SellerChain.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. use think\facade\Db;
  5. /**
  6. * DSO2O多用户商城
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class SellerChain extends MobileSeller
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_chain.lang.php');
  18. }
  19. public function index()
  20. {
  21. $chain_model = model('chain');
  22. $condition = array();
  23. $search_field_value = input('search_field_value');
  24. $search_field_name = input('search_field_name');
  25. if ($search_field_value != '') {
  26. switch ($search_field_name) {
  27. case 'chain_name':
  28. $condition[] = array('chain_name', 'like', '%' . trim($search_field_value) . '%');
  29. break;
  30. case 'chain_truename':
  31. $condition[] = array('chain_truename', 'like', '%' . trim($search_field_value) . '%');
  32. break;
  33. case 'chain_mobile':
  34. $condition[] = array('chain_mobile', 'like', '%' . trim($search_field_value) . '%');
  35. break;
  36. case 'chain_addressname':
  37. $condition[] = array('chain_addressname', 'like', '%' . trim($search_field_value) . '%');
  38. break;
  39. }
  40. }
  41. $search_state = input('search_state');
  42. switch ($search_state) {
  43. case '1':
  44. $condition[] = array('chain_state', '=', '1');
  45. break;
  46. case '0':
  47. $condition[] = array('chain_state', '=', '0');
  48. break;
  49. }
  50. $filtered = 0;
  51. if ($condition) {
  52. $filtered = 1;
  53. }
  54. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  55. $order = 'chain_addtime desc';
  56. $chain_list = $chain_model->getChainList($condition, 10, $order);
  57. $result = array_merge(array('chain_list' => $chain_list), mobile_page($chain_model->page_info));
  58. ds_json_encode(10000, '', $result);
  59. }
  60. public function add()
  61. {
  62. $chain_model = model('chain');
  63. //不能添加超过20个
  64. if (Db::name('chain')->where(array(array('store_id', '=', $this->store_info['store_id'])))->count() >= 20) {
  65. ds_json_encode(10001, lang('chain_count_error'));
  66. }
  67. $data = $this->post_data();
  68. $data['store_id'] = $this->store_info['store_id'];
  69. $data['chain_name'] = input('post.chain_name');
  70. $data['chain_addtime'] = TIMESTAMP;
  71. $chain_validate = ds_validate('chain');
  72. if (!$chain_validate->scene('chain_add')->check($data)) {
  73. ds_json_encode(10001, $chain_validate->getError());
  74. }
  75. $condition = array();
  76. $condition[] = array('chain_name', '=', $data['chain_name']);
  77. $result = $chain_model->getChainInfo($condition);
  78. if ($result) {
  79. ds_json_encode(10001, lang('chain_name_remote'));
  80. }
  81. $data['chain_passwd'] = md5($data['chain_passwd']);
  82. $result = $chain_model->addChain($data);
  83. if ($result) {
  84. ds_json_encode(10000, lang('ds_common_op_succ'));
  85. } else {
  86. ds_json_encode(10001, lang('ds_common_op_fail'));
  87. }
  88. }
  89. public function info()
  90. {
  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. {
  104. $id = intval(input('param.chain_id'));
  105. if (!$id) {
  106. ds_json_encode(10001, lang('param_error'));
  107. }
  108. $chain_model = model('chain');
  109. $data = $this->post_data();
  110. $chain_validate = ds_validate('chain');
  111. if (!$chain_validate->scene('chain_edit')->check($data)) {
  112. ds_json_encode(10001, $chain_validate->getError());
  113. }
  114. if (isset($data['chain_passwd'])) {
  115. $data['chain_passwd'] = md5($data['chain_passwd']);
  116. }
  117. $result = $chain_model->editChain($data, array('chain_id' => $id, 'store_id' => $this->store_info['store_id']));
  118. if ($result) {
  119. ds_json_encode(10000, lang('ds_common_op_succ'));
  120. } else {
  121. ds_json_encode(10001, lang('ds_common_op_fail'));
  122. }
  123. }
  124. public function del()
  125. {
  126. $id = intval(input('param.chain_id'));
  127. if (!$id) {
  128. ds_json_encode(10001, lang('param_error'));
  129. }
  130. $chain_model = model('chain');
  131. $chain_array = $chain_model->getChainInfo(array('chain_id' => $id, 'store_id' => $this->store_info['store_id']));
  132. if (!$chain_array) {
  133. ds_json_encode(10001, lang('chain_empty'));
  134. }
  135. //如果有正在配送的订单则不能删除
  136. $chain_order_model = model('chain_order');
  137. if ($chain_order_model->getChainOrderInfo(array(array('chain_id', '=', $id), array('chain_order_state', 'not in', [ORDER_STATE_CANCEL, ORDER_STATE_SUCCESS])))) {
  138. ds_json_encode(10001, lang('chain_drop_error'));
  139. }
  140. $result = $chain_model->delChain(array('chain_id' => $id, 'store_id' => $this->store_info['store_id']), array($chain_array));
  141. if (!$result) {
  142. ds_json_encode(10001, lang('ds_common_del_fail'));
  143. } else {
  144. ds_json_encode(10000, lang('ds_common_del_succ'));
  145. }
  146. }
  147. public function post_data()
  148. {
  149. $data = array(
  150. 'chain_truename' => input('post.chain_truename'),
  151. 'chain_mobile' => input('post.chain_mobile'),
  152. 'chain_addressname' => input('post.chain_addressname'),
  153. 'chain_telephony' => input('post.chain_telephony'),
  154. 'chain_area_2' => input('post.chain_area_2'),
  155. 'chain_area_3' => input('post.chain_area_3'),
  156. 'chain_area_info' => input('post.chain_area_info'),
  157. 'chain_state' => intval(input('post.chain_state')),
  158. 'chain_address' => input('post.chain_address'),
  159. 'chain_longitude' => input('post.chain_longitude'),
  160. 'chain_latitude' => input('post.chain_latitude'),
  161. 'chain_if_pickup' => input('post.chain_if_pickup'),
  162. 'chain_if_collect' => input('post.chain_if_collect'),
  163. );
  164. if (input('post.chain_passwd')) {
  165. $data['chain_passwd'] = input('post.chain_passwd');
  166. }
  167. return $data;
  168. }
  169. }