SellerChain.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class SellerChain extends MobileSeller {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_chain.lang.php');
  20. }
  21. public function index() {
  22. $chain_model = model('chain');
  23. $condition = array();
  24. $search_field_value = input('search_field_value');
  25. $search_field_name = input('search_field_name');
  26. if ($search_field_value != '') {
  27. switch ($search_field_name) {
  28. case 'chain_name':
  29. $condition[] = array('chain_name', 'like', '%' . trim($search_field_value) . '%');
  30. break;
  31. case 'chain_truename':
  32. $condition[] = array('chain_truename', 'like', '%' . trim($search_field_value) . '%');
  33. break;
  34. case 'chain_mobile':
  35. $condition[] = array('chain_mobile', 'like', '%' . trim($search_field_value) . '%');
  36. break;
  37. case 'chain_addressname':
  38. $condition[] = array('chain_addressname', 'like', '%' . trim($search_field_value) . '%');
  39. break;
  40. }
  41. }
  42. $search_state = input('search_state');
  43. switch ($search_state) {
  44. case '1':
  45. $condition[] = array('chain_state', '=', '1');
  46. break;
  47. case '0':
  48. $condition[] = array('chain_state', '=', '0');
  49. break;
  50. }
  51. $filtered = 0;
  52. if ($condition) {
  53. $filtered = 1;
  54. }
  55. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  56. $order = 'chain_addtime desc';
  57. $chain_list = $chain_model->getChainList($condition, 10, $order);
  58. $result = array_merge(array('chain_list' => $chain_list), mobile_page($chain_model->page_info));
  59. ds_json_encode(10000, '', $result);
  60. }
  61. public function add() {
  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. $id = intval(input('param.chain_id'));
  91. if (!$id) {
  92. ds_json_encode(10001, lang('param_error'));
  93. }
  94. $chain_model = model('chain');
  95. $chain_array = $chain_model->getChainInfo(array('chain_id' => $id, 'store_id' => $this->store_info['store_id']));
  96. if (!$chain_array) {
  97. ds_json_encode(10001, lang('chain_empty'));
  98. }
  99. ds_json_encode(10000, '', array('chain_info' => $chain_array));
  100. }
  101. public function edit() {
  102. $id = intval(input('param.chain_id'));
  103. if (!$id) {
  104. ds_json_encode(10001, lang('param_error'));
  105. }
  106. $chain_model = model('chain');
  107. $data = $this->post_data();
  108. $chain_validate = ds_validate('chain');
  109. if (!$chain_validate->scene('chain_edit')->check($data)) {
  110. ds_json_encode(10001, $chain_validate->getError());
  111. }
  112. if (isset($data['chain_passwd'])) {
  113. $data['chain_passwd'] = md5($data['chain_passwd']);
  114. }
  115. $result = $chain_model->editChain($data, array('chain_id' => $id, 'store_id' => $this->store_info['store_id']));
  116. if ($result) {
  117. ds_json_encode(10000, lang('ds_common_op_succ'));
  118. } else {
  119. ds_json_encode(10001, lang('ds_common_op_fail'));
  120. }
  121. }
  122. public function del() {
  123. $id = intval(input('param.chain_id'));
  124. if (!$id) {
  125. ds_json_encode(10001, lang('param_error'));
  126. }
  127. $chain_model = model('chain');
  128. $chain_array = $chain_model->getChainInfo(array('chain_id' => $id, 'store_id' => $this->store_info['store_id']));
  129. if (!$chain_array) {
  130. ds_json_encode(10001, lang('chain_empty'));
  131. }
  132. //如果有正在配送的订单则不能删除
  133. $chain_order_model = model('chain_order');
  134. if ($chain_order_model->getChainOrderInfo(array(array('chain_id', '=', $id), array('chain_order_state', 'not in', [ORDER_STATE_CANCEL, ORDER_STATE_SUCCESS])))) {
  135. ds_json_encode(10001, lang('chain_drop_error'));
  136. }
  137. $result = $chain_model->delChain(array('chain_id' => $id, 'store_id' => $this->store_info['store_id']), array($chain_array));
  138. if (!$result) {
  139. ds_json_encode(10001, lang('ds_common_del_fail'));
  140. } else {
  141. ds_json_encode(10000, lang('ds_common_del_succ'));
  142. }
  143. }
  144. public function post_data() {
  145. $data = array(
  146. 'chain_truename' => input('post.chain_truename'),
  147. 'chain_mobile' => input('post.chain_mobile'),
  148. 'chain_addressname' => input('post.chain_addressname'),
  149. 'chain_telephony' => input('post.chain_telephony'),
  150. 'chain_area_2' => input('post.chain_area_2'),
  151. 'chain_area_3' => input('post.chain_area_3'),
  152. 'chain_area_info' => input('post.chain_area_info'),
  153. 'chain_state' => intval(input('post.chain_state')),
  154. 'chain_address' => input('post.chain_address'),
  155. 'chain_longitude' => input('post.chain_longitude'),
  156. 'chain_latitude' => input('post.chain_latitude'),
  157. 'chain_if_pickup' => input('post.chain_if_pickup'),
  158. 'chain_if_collect' => input('post.chain_if_collect'),
  159. );
  160. if (input('post.chain_passwd')) {
  161. $data['chain_passwd'] = input('post.chain_passwd');
  162. }
  163. return $data;
  164. }
  165. }