123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
- namespace app\home\controller;
- use think\facade\View;
- use think\facade\Lang;
- use think\facade\Db;
- /**
-
- * DSO2O多用户商城
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class SellerChain extends BaseSeller
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_chain.lang.php');
- }
- public function index()
- {
- $chain_model = model('chain');
- $condition = array();
- $search_field_value = input('search_field_value');
- $search_field_name = input('search_field_name');
- if ($search_field_value != '') {
- switch ($search_field_name) {
- case 'chain_name':
- $condition[] = array('chain_name', 'like', '%' . trim($search_field_value) . '%');
- break;
- case 'chain_truename':
- $condition[] = array('chain_truename', 'like', '%' . trim($search_field_value) . '%');
- break;
- case 'chain_mobile':
- $condition[] = array('chain_mobile', 'like', '%' . trim($search_field_value) . '%');
- break;
- case 'chain_addressname':
- $condition[] = array('chain_addressname', 'like', '%' . trim($search_field_value) . '%');
- break;
- }
- }
- $search_state = input('search_state');
- switch ($search_state) {
- case '1':
- $condition[] = array('chain_state', '=', '1');
- break;
- case '0':
- $condition[] = array('chain_state', '=', '0');
- break;
- }
- $filtered = 0;
- if ($condition) {
- $filtered = 1;
- }
- $condition[] = array('store_id', '=', session('store_id'));
- $order = 'chain_addtime desc';
- $chain_list = $chain_model->getChainList($condition, 10, $order);
- View::assign('chain_list', $chain_list);
- View::assign('show_page', $chain_model->page_info->render());
- View::assign('search_field_name', trim($search_field_name));
- View::assign('search_field_value', trim($search_field_value));
- /* 设置卖家当前菜单 */
- $this->setSellerCurMenu('seller_chain');
- /* 设置卖家当前栏目 */
- $this->setSellerCurItem('chain_list');
- return View::fetch($this->template_dir . 'index');
- }
- public function add()
- {
- if (!request()->isPost()) {
- View::assign('baidu_ak', config('ds_config.baidu_ak'));
- $this->setSellerCurMenu('seller_chain');
- $this->setSellerCurItem('add');
- return View::fetch($this->template_dir . 'form');
- } else {
- $chain_model = model('chain');
- //不能添加超过20个
- if (Db::name('chain')->where(array(array('store_id', '=', session('store_id'))))->count() >= 20) {
- ds_json_encode(10001, lang('chain_count_error'));
- }
- $data = $this->post_data();
- $data['store_id'] = session('store_id');
- $data['chain_name'] = input('post.chain_name');
- $data['chain_addtime'] = TIMESTAMP;
- $chain_validate = ds_validate('chain');
- if (!$chain_validate->scene('chain_add')->check($data)) {
- ds_json_encode(10001, $chain_validate->getError());
- }
- $condition = array();
- $condition[] = array('chain_name', '=', $data['chain_name']);
- $result = $chain_model->getChainInfo($condition);
- if ($result) {
- ds_json_encode(10001, lang('chain_name_remote'));
- }
- $data['chain_passwd'] = md5($data['chain_passwd']);
- $result = $chain_model->addChain($data);
- if ($result) {
- $this->recordSellerlog(lang('ds_new') . lang('seller_chain') . '[' . $data['chain_name'] . ']', 1);
- ds_json_encode(10000, lang('ds_common_save_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_save_fail'));
- }
- }
- }
- public function edit()
- {
- $id = intval(input('param.id'));
- if (!$id) {
- $this->error(lang('param_error'));
- }
- $chain_model = model('chain');
- $chain_array = $chain_model->getChainInfo(array('chain_id' => $id, 'store_id' => session('store_id')));
- if (!$chain_array) {
- $this->error(lang('chain_empty'));
- }
- if (!request()->isPost()) {
- View::assign('baidu_ak', config('ds_config.baidu_ak'));
- View::assign('chain_array', $chain_array);
- $this->setSellerCurMenu('seller_chain');
- $this->setSellerCurItem('edit');
- return View::fetch($this->template_dir . 'form');
- } else {
- $data = $this->post_data();
- $chain_validate = ds_validate('chain');
- if (!$chain_validate->scene('chain_edit')->check($data)) {
- ds_json_encode(10001, $chain_validate->getError());
- }
- if (isset($data['chain_passwd'])) {
- $data['chain_passwd'] = md5($data['chain_passwd']);
- }
- $result = $chain_model->editChain($data, array('chain_id' => $id, 'store_id' => session('store_id')));
- if ($result) {
- $this->recordSellerlog(lang('ds_edit') . lang('seller_chain') . '[' . $chain_array['chain_name'] . ']', 1);
- ds_json_encode(10000, lang('ds_common_save_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_save_fail'));
- }
- }
- }
- public function del()
- {
- $id = intval(input('param.id'));
- if (!$id) {
- ds_json_encode(10001, lang('param_error'));
- }
- $chain_model = model('chain');
- $chain_array = $chain_model->getChainInfo(array('chain_id' => $id, 'store_id' => session('store_id')));
- if (!$chain_array) {
- ds_json_encode(10001, lang('chain_empty'));
- }
- //如果有正在配送的订单则不能删除
- $chain_order_model = model('chain_order');
- if ($chain_order_model->getChainOrderInfo(array(array('chain_id', '=', $id), array('chain_order_state', 'not in', [ORDER_STATE_CANCEL, ORDER_STATE_SUCCESS])))) {
- ds_json_encode(10001, lang('chain_drop_error'));
- }
- $result = $chain_model->delChain(array('chain_id' => $id, 'store_id' => session('store_id')), array($chain_array));
- if (!$result) {
- ds_json_encode(10001, lang('ds_common_del_fail'));
- } else {
- $this->recordSellerlog(lang('ds_del') . lang('seller_chain') . '[' . $chain_array['chain_name'] . ']', 1);
- ds_json_encode(10000, lang('ds_common_del_succ'));
- }
- }
- public function post_data()
- {
- $data = array(
- 'chain_truename' => input('post.chain_truename'),
- 'chain_mobile' => input('post.chain_mobile'),
- 'chain_addressname' => input('post.chain_addressname'),
- 'chain_telephony' => input('post.chain_telephony'),
- 'chain_area_2' => input('post.chain_area_2'),
- 'chain_area_3' => input('post.chain_area_3'),
- 'chain_area_info' => input('post.chain_area_info'),
- 'chain_state' => intval(input('post.chain_state')),
- 'chain_address' => input('post.chain_address'),
- 'chain_longitude' => input('post.chain_longitude'),
- 'chain_latitude' => input('post.chain_latitude'),
- 'chain_if_pickup' => input('post.chain_if_pickup'),
- 'chain_if_collect' => input('post.chain_if_collect'),
- );
- if (input('post.chain_passwd')) {
- $data['chain_passwd'] = input('post.chain_passwd');
- }
- return $data;
- }
- public function ajax()
- {
- $chain_model = model('chain');
- switch (input('param.branch')) {
- /**
- * 品牌名称
- */
- case 'chain_name':
- /**
- * 判断是否有重复
- */
- $condition = array();
- $condition[] = array('chain_name', '=', trim(input('param.value')));
- $condition[] = array('chain_id', '<>', intval(input('param.id')));
- $result = $chain_model->getChainInfo($condition);
- if (empty($result)) {
- echo 'true';
- exit;
- } else {
- echo 'false';
- exit;
- }
- break;
- }
- }
- /**
- * 栏目菜单
- */
- function getSellerItemList()
- {
- $menu_array[] = array(
- 'name' => 'chain_list',
- 'text' => lang('seller_chain_list'),
- 'url' => url('seller_chain/index'),
- );
- return $menu_array;
- }
- }
|