SellerChain.php 7.1 KB

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