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