SellerChain.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. * 网站地址: http://www.csdeshang.com
  12. * ----------------------------------------------------------------------------
  13. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  14. * 不允许对程序代码以任何形式任何目的的再发布。
  15. * ============================================================================
  16. * 控制器
  17. */
  18. class SellerChain extends BaseSeller {
  19. public function initialize() {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_chain.lang.php');
  22. }
  23. public function index() {
  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','=',session('store_id'));
  58. $order='chain_addtime desc';
  59. $chain_list = $chain_model->getChainList($condition, 10, $order);
  60. View::assign('chain_list', $chain_list);
  61. View::assign('show_page', $chain_model->page_info->render());
  62. View::assign('search_field_name', trim($search_field_name));
  63. View::assign('search_field_value', trim($search_field_value));
  64. /* 设置卖家当前菜单 */
  65. $this->setSellerCurMenu('seller_chain');
  66. /* 设置卖家当前栏目 */
  67. $this->setSellerCurItem('chain_list');
  68. return View::fetch($this->template_dir . 'index');
  69. }
  70. public function add() {
  71. if (!request()->isPost()) {
  72. View::assign('baidu_ak', config('ds_config.baidu_ak'));
  73. $this->setSellerCurMenu('seller_chain');
  74. $this->setSellerCurItem('add');
  75. return View::fetch($this->template_dir . 'form');
  76. } else {
  77. $chain_model = model('chain');
  78. //不能添加超过20个
  79. if(Db::name('chain')->where(array(array('store_id','=',session('store_id'))))->count()>=20){
  80. ds_json_encode(10001, lang('chain_count_error'));
  81. }
  82. $data = $this->post_data();
  83. $data['store_id'] = session('store_id');
  84. $data['chain_name'] = input('post.chain_name');
  85. $data['chain_addtime'] = TIMESTAMP;
  86. $chain_validate = ds_validate('chain');
  87. if (!$chain_validate->scene('chain_add')->check($data)) {
  88. ds_json_encode(10001, $chain_validate->getError());
  89. }
  90. $condition = array();
  91. $condition[] = array('chain_name','=',$data['chain_name']);
  92. $result = $chain_model->getChainInfo($condition);
  93. if ($result) {
  94. ds_json_encode(10001, lang('chain_name_remote'));
  95. }
  96. $data['chain_passwd'] = md5($data['chain_passwd']);
  97. $result = $chain_model->addChain($data);
  98. if ($result) {
  99. $this->recordSellerlog(lang('ds_new') . lang('seller_chain') . '[' . $data['chain_name'] . ']', 1);
  100. ds_json_encode(10000, lang('ds_common_save_succ'));
  101. } else {
  102. ds_json_encode(10001, lang('ds_common_save_fail'));
  103. }
  104. }
  105. }
  106. public function edit() {
  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. $id = intval(input('param.id'));
  142. if (!$id) {
  143. ds_json_encode(10001, lang('param_error'));
  144. }
  145. $chain_model = model('chain');
  146. $chain_array = $chain_model->getChainInfo(array('chain_id' => $id, 'store_id' => session('store_id')));
  147. if (!$chain_array) {
  148. ds_json_encode(10001, lang('chain_empty'));
  149. }
  150. //如果有正在配送的订单则不能删除
  151. $chain_order_model=model('chain_order');
  152. if($chain_order_model->getChainOrderInfo(array(array('chain_id','=',$id),array('chain_order_state','not in',[ORDER_STATE_CANCEL,ORDER_STATE_SUCCESS])))){
  153. ds_json_encode(10001, lang('chain_drop_error'));
  154. }
  155. $result = $chain_model->delChain(array('chain_id' => $id, 'store_id' => session('store_id')), array($chain_array));
  156. if (!$result) {
  157. ds_json_encode(10001, lang('ds_common_del_fail'));
  158. } else {
  159. $this->recordSellerlog(lang('ds_del') . lang('seller_chain') . '[' . $chain_array['chain_name'] . ']', 1);
  160. ds_json_encode(10000, lang('ds_common_del_succ'));
  161. }
  162. }
  163. public function post_data() {
  164. $data = array(
  165. 'chain_truename' => input('post.chain_truename'),
  166. 'chain_mobile' => input('post.chain_mobile'),
  167. 'chain_addressname' => input('post.chain_addressname'),
  168. 'chain_telephony' => input('post.chain_telephony'),
  169. 'chain_area_2' => input('post.chain_area_2'),
  170. 'chain_area_3' => input('post.chain_area_3'),
  171. 'chain_area_info' => input('post.chain_area_info'),
  172. 'chain_state' => intval(input('post.chain_state')),
  173. 'chain_address' => input('post.chain_address'),
  174. 'chain_longitude' => input('post.chain_longitude'),
  175. 'chain_latitude' => input('post.chain_latitude'),
  176. 'chain_if_pickup' => input('post.chain_if_pickup'),
  177. 'chain_if_collect' => input('post.chain_if_collect'),
  178. );
  179. if (input('post.chain_passwd')) {
  180. $data['chain_passwd'] = input('post.chain_passwd');
  181. }
  182. return $data;
  183. }
  184. public function ajax() {
  185. $chain_model = model('chain');
  186. switch (input('param.branch')) {
  187. /**
  188. * 品牌名称
  189. */
  190. case 'chain_name':
  191. /**
  192. * 判断是否有重复
  193. */
  194. $condition = array();
  195. $condition[] = array('chain_name','=',trim(input('param.value')));
  196. $condition[] = array('chain_id','<>',intval(input('param.id')));
  197. $result = $chain_model->getChainInfo($condition);
  198. if (empty($result)) {
  199. echo 'true';
  200. exit;
  201. } else {
  202. echo 'false';
  203. exit;
  204. }
  205. break;
  206. }
  207. }
  208. /**
  209. * 栏目菜单
  210. */
  211. function getSellerItemList() {
  212. $menu_array[] = array(
  213. 'name' => 'chain_list',
  214. 'text' => lang('seller_chain_list'),
  215. 'url' => url('seller_chain/index'),
  216. );
  217. return $menu_array;
  218. }
  219. }