SellerChain.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  11. * 网站地址: https://www.valimart.net/
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class SellerChain extends BaseSeller {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_chain.lang.php');
  21. }
  22. public function index() {
  23. $chain_model = model('chain');
  24. $condition = array();
  25. $search_field_value = input('search_field_value');
  26. $search_field_name = input('search_field_name');
  27. if ($search_field_value != '') {
  28. switch ($search_field_name) {
  29. case 'chain_name':
  30. $condition[] = array('chain_name','like', '%' . trim($search_field_value) . '%');
  31. break;
  32. case 'chain_truename':
  33. $condition[] = array('chain_truename','like', '%' . trim($search_field_value) . '%');
  34. break;
  35. case 'chain_mobile':
  36. $condition[] = array('chain_mobile','like', '%' . trim($search_field_value) . '%');
  37. break;
  38. case 'chain_addressname':
  39. $condition[] = array('chain_addressname','like', '%' . trim($search_field_value) . '%');
  40. break;
  41. }
  42. }
  43. $search_state = input('search_state');
  44. switch ($search_state) {
  45. case '1':
  46. $condition[] = array('chain_state','=','1');
  47. break;
  48. case '0':
  49. $condition[] = array('chain_state','=','0');
  50. break;
  51. }
  52. $filtered = 0;
  53. if ($condition) {
  54. $filtered = 1;
  55. }
  56. $condition[] = array('store_id','=',session('store_id'));
  57. $order='chain_addtime desc';
  58. $chain_list = $chain_model->getChainList($condition, 10, $order);
  59. View::assign('chain_list', $chain_list);
  60. View::assign('show_page', $chain_model->page_info->render());
  61. View::assign('search_field_name', trim($search_field_name));
  62. View::assign('search_field_value', trim($search_field_value));
  63. /* 设置卖家当前菜单 */
  64. $this->setSellerCurMenu('seller_chain');
  65. /* 设置卖家当前栏目 */
  66. $this->setSellerCurItem('chain_list');
  67. return View::fetch($this->template_dir . 'index');
  68. }
  69. public function add() {
  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. $id = intval(input('param.id'));
  107. if (!$id) {
  108. $this->error(lang('param_error'));
  109. }
  110. $chain_model = model('chain');
  111. $chain_array = $chain_model->getChainInfo(array('chain_id' => $id, 'store_id' => session('store_id')));
  112. if (!$chain_array) {
  113. $this->error(lang('chain_empty'));
  114. }
  115. if (!request()->isPost()) {
  116. View::assign('baidu_ak', config('ds_config.baidu_ak'));
  117. View::assign('chain_array', $chain_array);
  118. $this->setSellerCurMenu('seller_chain');
  119. $this->setSellerCurItem('edit');
  120. return View::fetch($this->template_dir . 'form');
  121. } else {
  122. $data = $this->post_data();
  123. $chain_validate = ds_validate('chain');
  124. if (!$chain_validate->scene('chain_edit')->check($data)) {
  125. ds_json_encode(10001, $chain_validate->getError());
  126. }
  127. if (isset($data['chain_passwd'])) {
  128. $data['chain_passwd'] = md5($data['chain_passwd']);
  129. }
  130. $result = $chain_model->editChain($data, array('chain_id' => $id, 'store_id' => session('store_id')));
  131. if ($result) {
  132. $this->recordSellerlog(lang('ds_edit') . lang('seller_chain') . '[' . $chain_array['chain_name'] . ']', 1);
  133. ds_json_encode(10000, lang('ds_common_save_succ'));
  134. } else {
  135. ds_json_encode(10001, lang('ds_common_save_fail'));
  136. }
  137. }
  138. }
  139. public function del() {
  140. $id = intval(input('param.id'));
  141. if (!$id) {
  142. ds_json_encode(10001, lang('param_error'));
  143. }
  144. $chain_model = model('chain');
  145. $chain_array = $chain_model->getChainInfo(array('chain_id' => $id, 'store_id' => session('store_id')));
  146. if (!$chain_array) {
  147. ds_json_encode(10001, lang('chain_empty'));
  148. }
  149. //如果有正在配送的订单则不能删除
  150. $chain_order_model=model('chain_order');
  151. if($chain_order_model->getChainOrderInfo(array(array('chain_id','=',$id),array('chain_order_state','not in',[ORDER_STATE_CANCEL,ORDER_STATE_SUCCESS])))){
  152. ds_json_encode(10001, lang('chain_drop_error'));
  153. }
  154. $result = $chain_model->delChain(array('chain_id' => $id, 'store_id' => session('store_id')), array($chain_array));
  155. if (!$result) {
  156. ds_json_encode(10001, lang('ds_common_del_fail'));
  157. } else {
  158. $this->recordSellerlog(lang('ds_del') . lang('seller_chain') . '[' . $chain_array['chain_name'] . ']', 1);
  159. ds_json_encode(10000, lang('ds_common_del_succ'));
  160. }
  161. }
  162. public function post_data() {
  163. $data = array(
  164. 'chain_truename' => input('post.chain_truename'),
  165. 'chain_mobile' => input('post.chain_mobile'),
  166. 'chain_addressname' => input('post.chain_addressname'),
  167. 'chain_telephony' => input('post.chain_telephony'),
  168. 'chain_area_2' => input('post.chain_area_2'),
  169. 'chain_area_3' => input('post.chain_area_3'),
  170. 'chain_area_info' => input('post.chain_area_info'),
  171. 'chain_state' => intval(input('post.chain_state')),
  172. 'chain_address' => input('post.chain_address'),
  173. 'chain_longitude' => input('post.chain_longitude'),
  174. 'chain_latitude' => input('post.chain_latitude'),
  175. 'chain_if_pickup' => input('post.chain_if_pickup'),
  176. 'chain_if_collect' => input('post.chain_if_collect'),
  177. );
  178. if (input('post.chain_passwd')) {
  179. $data['chain_passwd'] = input('post.chain_passwd');
  180. }
  181. return $data;
  182. }
  183. public function ajax() {
  184. $chain_model = model('chain');
  185. switch (input('param.branch')) {
  186. /**
  187. * 品牌名称
  188. */
  189. case 'chain_name':
  190. /**
  191. * 判断是否有重复
  192. */
  193. $condition = array();
  194. $condition[] = array('chain_name','=',trim(input('param.value')));
  195. $condition[] = array('chain_id','<>',intval(input('param.id')));
  196. $result = $chain_model->getChainInfo($condition);
  197. if (empty($result)) {
  198. echo 'true';
  199. exit;
  200. } else {
  201. echo 'false';
  202. exit;
  203. }
  204. break;
  205. }
  206. }
  207. /**
  208. * 栏目菜单
  209. */
  210. function getSellerItemList() {
  211. $menu_array[] = array(
  212. 'name' => 'chain_list',
  213. 'text' => lang('seller_chain_list'),
  214. 'url' => url('seller_chain/index'),
  215. );
  216. return $menu_array;
  217. }
  218. }