SellerChain.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. use think\facade\Db;
  5. /**
  6. * ============================================================================
  7. * DSO2O多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class SellerChain extends MobileSeller {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_chain.lang.php');
  21. }
  22. public function index() {
  23. $chain_model = model('chain');
  24. $condition = array();
  25. $search_field_value = input('search_field_value');
  26. $search_field_name = input('search_field_name');
  27. if ($search_field_value != '') {
  28. switch ($search_field_name) {
  29. case 'chain_name':
  30. $condition[] = array('chain_name', 'like', '%' . trim($search_field_value) . '%');
  31. break;
  32. case 'chain_truename':
  33. $condition[] = array('chain_truename', 'like', '%' . trim($search_field_value) . '%');
  34. break;
  35. case 'chain_mobile':
  36. $condition[] = array('chain_mobile', 'like', '%' . trim($search_field_value) . '%');
  37. break;
  38. case 'chain_addressname':
  39. $condition[] = array('chain_addressname', 'like', '%' . trim($search_field_value) . '%');
  40. break;
  41. }
  42. }
  43. $search_state = input('search_state');
  44. switch ($search_state) {
  45. case '1':
  46. $condition[] = array('chain_state', '=', '1');
  47. break;
  48. case '0':
  49. $condition[] = array('chain_state', '=', '0');
  50. break;
  51. }
  52. $filtered = 0;
  53. if ($condition) {
  54. $filtered = 1;
  55. }
  56. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  57. $order = 'chain_addtime desc';
  58. $chain_list = $chain_model->getChainList($condition, 10, $order);
  59. $result = array_merge(array('chain_list' => $chain_list), mobile_page($chain_model->page_info));
  60. ds_json_encode(10000, '', $result);
  61. }
  62. public function add() {
  63. $chain_model = model('chain');
  64. //不能添加超过20个
  65. if (Db::name('chain')->where(array(array('store_id', '=', $this->store_info['store_id'])))->count() >= 20) {
  66. ds_json_encode(10001, lang('chain_count_error'));
  67. }
  68. $data = $this->post_data();
  69. $data['store_id'] = $this->store_info['store_id'];
  70. $data['chain_name'] = input('post.chain_name');
  71. $data['chain_addtime'] = TIMESTAMP;
  72. $chain_validate = ds_validate('chain');
  73. if (!$chain_validate->scene('chain_add')->check($data)) {
  74. ds_json_encode(10001, $chain_validate->getError());
  75. }
  76. $condition = array();
  77. $condition[] = array('chain_name', '=', $data['chain_name']);
  78. $result = $chain_model->getChainInfo($condition);
  79. if ($result) {
  80. ds_json_encode(10001, lang('chain_name_remote'));
  81. }
  82. $data['chain_passwd'] = md5($data['chain_passwd']);
  83. $result = $chain_model->addChain($data);
  84. if ($result) {
  85. ds_json_encode(10000, lang('ds_common_op_succ'));
  86. } else {
  87. ds_json_encode(10001, lang('ds_common_op_fail'));
  88. }
  89. }
  90. public function info() {
  91. $id = intval(input('param.chain_id'));
  92. if (!$id) {
  93. ds_json_encode(10001, lang('param_error'));
  94. }
  95. $chain_model = model('chain');
  96. $chain_array = $chain_model->getChainInfo(array('chain_id' => $id, 'store_id' => $this->store_info['store_id']));
  97. if (!$chain_array) {
  98. ds_json_encode(10001, lang('chain_empty'));
  99. }
  100. ds_json_encode(10000, '', array('chain_info' => $chain_array));
  101. }
  102. public function edit() {
  103. $id = intval(input('param.chain_id'));
  104. if (!$id) {
  105. ds_json_encode(10001, lang('param_error'));
  106. }
  107. $chain_model = model('chain');
  108. $data = $this->post_data();
  109. $chain_validate = ds_validate('chain');
  110. if (!$chain_validate->scene('chain_edit')->check($data)) {
  111. ds_json_encode(10001, $chain_validate->getError());
  112. }
  113. if (isset($data['chain_passwd'])) {
  114. $data['chain_passwd'] = md5($data['chain_passwd']);
  115. }
  116. $result = $chain_model->editChain($data, array('chain_id' => $id, 'store_id' => $this->store_info['store_id']));
  117. if ($result) {
  118. ds_json_encode(10000, lang('ds_common_op_succ'));
  119. } else {
  120. ds_json_encode(10001, lang('ds_common_op_fail'));
  121. }
  122. }
  123. public function del() {
  124. $id = intval(input('param.chain_id'));
  125. if (!$id) {
  126. ds_json_encode(10001, lang('param_error'));
  127. }
  128. $chain_model = model('chain');
  129. $chain_array = $chain_model->getChainInfo(array('chain_id' => $id, 'store_id' => $this->store_info['store_id']));
  130. if (!$chain_array) {
  131. ds_json_encode(10001, lang('chain_empty'));
  132. }
  133. //如果有正在配送的订单则不能删除
  134. $chain_order_model = model('chain_order');
  135. if ($chain_order_model->getChainOrderInfo(array(array('chain_id', '=', $id), array('chain_order_state', 'not in', [ORDER_STATE_CANCEL, ORDER_STATE_SUCCESS])))) {
  136. ds_json_encode(10001, lang('chain_drop_error'));
  137. }
  138. $result = $chain_model->delChain(array('chain_id' => $id, 'store_id' => $this->store_info['store_id']), array($chain_array));
  139. if (!$result) {
  140. ds_json_encode(10001, lang('ds_common_del_fail'));
  141. } else {
  142. ds_json_encode(10000, lang('ds_common_del_succ'));
  143. }
  144. }
  145. public function post_data() {
  146. $data = array(
  147. 'chain_truename' => input('post.chain_truename'),
  148. 'chain_mobile' => input('post.chain_mobile'),
  149. 'chain_addressname' => input('post.chain_addressname'),
  150. 'chain_telephony' => input('post.chain_telephony'),
  151. 'chain_area_2' => input('post.chain_area_2'),
  152. 'chain_area_3' => input('post.chain_area_3'),
  153. 'chain_area_info' => input('post.chain_area_info'),
  154. 'chain_state' => intval(input('post.chain_state')),
  155. 'chain_address' => input('post.chain_address'),
  156. 'chain_longitude' => input('post.chain_longitude'),
  157. 'chain_latitude' => input('post.chain_latitude'),
  158. 'chain_if_pickup' => input('post.chain_if_pickup'),
  159. 'chain_if_collect' => input('post.chain_if_collect'),
  160. );
  161. if (input('post.chain_passwd')) {
  162. $data['chain_passwd'] = input('post.chain_passwd');
  163. }
  164. return $data;
  165. }
  166. }