SellerChain.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. * DSO2O多用户商城
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 控制器
  12. */
  13. class SellerChain extends BaseSeller
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_chain.lang.php');
  19. }
  20. public function index()
  21. {
  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', '=', session('store_id'));
  56. $order = 'chain_addtime desc';
  57. $chain_list = $chain_model->getChainList($condition, 10, $order);
  58. View::assign('chain_list', $chain_list);
  59. View::assign('show_page', $chain_model->page_info->render());
  60. View::assign('search_field_name', trim($search_field_name));
  61. View::assign('search_field_value', trim($search_field_value));
  62. /* 设置卖家当前菜单 */
  63. $this->setSellerCurMenu('seller_chain');
  64. /* 设置卖家当前栏目 */
  65. $this->setSellerCurItem('chain_list');
  66. return View::fetch($this->template_dir . 'index');
  67. }
  68. public function add()
  69. {
  70. if (!request()->isPost()) {
  71. View::assign('baidu_ak', config('ds_config.baidu_ak'));
  72. $this->setSellerCurMenu('seller_chain');
  73. $this->setSellerCurItem('add');
  74. return View::fetch($this->template_dir . 'form');
  75. } else {
  76. $chain_model = model('chain');
  77. //不能添加超过20个
  78. if (Db::name('chain')->where(array(array('store_id', '=', session('store_id'))))->count() >= 20) {
  79. ds_json_encode(10001, lang('chain_count_error'));
  80. }
  81. $data = $this->post_data();
  82. $data['store_id'] = session('store_id');
  83. $data['chain_name'] = input('post.chain_name');
  84. $data['chain_addtime'] = TIMESTAMP;
  85. $chain_validate = ds_validate('chain');
  86. if (!$chain_validate->scene('chain_add')->check($data)) {
  87. ds_json_encode(10001, $chain_validate->getError());
  88. }
  89. $condition = array();
  90. $condition[] = array('chain_name', '=', $data['chain_name']);
  91. $result = $chain_model->getChainInfo($condition);
  92. if ($result) {
  93. ds_json_encode(10001, lang('chain_name_remote'));
  94. }
  95. $data['chain_passwd'] = md5($data['chain_passwd']);
  96. $result = $chain_model->addChain($data);
  97. if ($result) {
  98. $this->recordSellerlog(lang('ds_new') . lang('seller_chain') . '[' . $data['chain_name'] . ']', 1);
  99. ds_json_encode(10000, lang('ds_common_save_succ'));
  100. } else {
  101. ds_json_encode(10001, lang('ds_common_save_fail'));
  102. }
  103. }
  104. }
  105. public function edit()
  106. {
  107. $id = intval(input('param.id'));
  108. if (!$id) {
  109. $this->error(lang('param_error'));
  110. }
  111. $chain_model = model('chain');
  112. $chain_array = $chain_model->getChainInfo(array('chain_id' => $id, 'store_id' => session('store_id')));
  113. if (!$chain_array) {
  114. $this->error(lang('chain_empty'));
  115. }
  116. if (!request()->isPost()) {
  117. View::assign('baidu_ak', config('ds_config.baidu_ak'));
  118. View::assign('chain_array', $chain_array);
  119. $this->setSellerCurMenu('seller_chain');
  120. $this->setSellerCurItem('edit');
  121. return View::fetch($this->template_dir . 'form');
  122. } else {
  123. $data = $this->post_data();
  124. $chain_validate = ds_validate('chain');
  125. if (!$chain_validate->scene('chain_edit')->check($data)) {
  126. ds_json_encode(10001, $chain_validate->getError());
  127. }
  128. if (isset($data['chain_passwd'])) {
  129. $data['chain_passwd'] = md5($data['chain_passwd']);
  130. }
  131. $result = $chain_model->editChain($data, array('chain_id' => $id, 'store_id' => session('store_id')));
  132. if ($result) {
  133. $this->recordSellerlog(lang('ds_edit') . lang('seller_chain') . '[' . $chain_array['chain_name'] . ']', 1);
  134. ds_json_encode(10000, lang('ds_common_save_succ'));
  135. } else {
  136. ds_json_encode(10001, lang('ds_common_save_fail'));
  137. }
  138. }
  139. }
  140. public function del()
  141. {
  142. $id = intval(input('param.id'));
  143. if (!$id) {
  144. ds_json_encode(10001, lang('param_error'));
  145. }
  146. $chain_model = model('chain');
  147. $chain_array = $chain_model->getChainInfo(array('chain_id' => $id, 'store_id' => session('store_id')));
  148. if (!$chain_array) {
  149. ds_json_encode(10001, lang('chain_empty'));
  150. }
  151. //如果有正在配送的订单则不能删除
  152. $chain_order_model = model('chain_order');
  153. if ($chain_order_model->getChainOrderInfo(array(array('chain_id', '=', $id), array('chain_order_state', 'not in', [ORDER_STATE_CANCEL, ORDER_STATE_SUCCESS])))) {
  154. ds_json_encode(10001, lang('chain_drop_error'));
  155. }
  156. $result = $chain_model->delChain(array('chain_id' => $id, 'store_id' => session('store_id')), array($chain_array));
  157. if (!$result) {
  158. ds_json_encode(10001, lang('ds_common_del_fail'));
  159. } else {
  160. $this->recordSellerlog(lang('ds_del') . lang('seller_chain') . '[' . $chain_array['chain_name'] . ']', 1);
  161. ds_json_encode(10000, lang('ds_common_del_succ'));
  162. }
  163. }
  164. public function post_data()
  165. {
  166. $data = array(
  167. 'chain_truename' => input('post.chain_truename'),
  168. 'chain_mobile' => input('post.chain_mobile'),
  169. 'chain_addressname' => input('post.chain_addressname'),
  170. 'chain_telephony' => input('post.chain_telephony'),
  171. 'chain_area_2' => input('post.chain_area_2'),
  172. 'chain_area_3' => input('post.chain_area_3'),
  173. 'chain_area_info' => input('post.chain_area_info'),
  174. 'chain_state' => intval(input('post.chain_state')),
  175. 'chain_address' => input('post.chain_address'),
  176. 'chain_longitude' => input('post.chain_longitude'),
  177. 'chain_latitude' => input('post.chain_latitude'),
  178. 'chain_if_pickup' => input('post.chain_if_pickup'),
  179. 'chain_if_collect' => input('post.chain_if_collect'),
  180. );
  181. if (input('post.chain_passwd')) {
  182. $data['chain_passwd'] = input('post.chain_passwd');
  183. }
  184. return $data;
  185. }
  186. public function ajax()
  187. {
  188. $chain_model = model('chain');
  189. switch (input('param.branch')) {
  190. /**
  191. * 品牌名称
  192. */
  193. case 'chain_name':
  194. /**
  195. * 判断是否有重复
  196. */
  197. $condition = array();
  198. $condition[] = array('chain_name', '=', trim(input('param.value')));
  199. $condition[] = array('chain_id', '<>', intval(input('param.id')));
  200. $result = $chain_model->getChainInfo($condition);
  201. if (empty($result)) {
  202. echo 'true';
  203. exit;
  204. } else {
  205. echo 'false';
  206. exit;
  207. }
  208. break;
  209. }
  210. }
  211. /**
  212. * 栏目菜单
  213. */
  214. function getSellerItemList()
  215. {
  216. $menu_array[] = array(
  217. 'name' => 'chain_list',
  218. 'text' => lang('seller_chain_list'),
  219. 'url' => url('seller_chain/index'),
  220. );
  221. return $menu_array;
  222. }
  223. }