diff --git a/admin/controllers/auto/Brand.php b/admin/controllers/auto/Brand.php index 50b192a8..c3e1399c 100644 --- a/admin/controllers/auto/Brand.php +++ b/admin/controllers/auto/Brand.php @@ -12,6 +12,8 @@ class Brand extends HD_Controller{ public function __construct(){ parent::__construct(); $this->load->model('auto/auto_brand_model'); + $this->load->model('auto/auto_brand_biz_model'); + $this->load->model('biz/biz_model'); } public function index(){ @@ -35,6 +37,7 @@ class Brand extends HD_Controller{ 'id' => $val['id'], 'name' => $val['name'], 'status' => $val['status'], + 't_biz' => $this->auto_brand_biz_model->count(['brand_id'=>$val['id']]), 'status_name' => $status_arr[$val['status']], 'c_time' => date('Y-m-d H:i:s',$val['c_time']) ]; @@ -156,7 +159,7 @@ class Brand extends HD_Controller{ if(strlen($status) > 0){ $where['status'] = $status; } else { - $whre['status > -1'] = null; + $where['status > -1'] = null; } $total = $this->auto_brand_model->count($where); @@ -178,5 +181,152 @@ class Brand extends HD_Controller{ $this->data = array('total' => $total, 'list' => $lists); return $this->show_json(SYS_CODE_SUCCESS); } + //授权门店 + public function get_biz(){ + $id = $this->input->get('id'); + $info = $this->auto_brand_model->get(array('id' => $id)); + if (!$info) { + return $this->show_json(SYS_CODE_FAIL, '数据不存在!'); + } + $cate_lists = $this->biz_model->type_ary(); + $params = [ + 'id' => $id, + 'cate_id' => 1 + ]; + $this->data['params'] = $params; + $this->data['cate_lists'] = $cate_lists; + $this->data['info'] = $info; + $this->data['_title'] = '授权品牌'; + return $this->show_view('auto/brand/edit_biz',true); + } + //授权门店 + public function edit_biz(){ + $brand_id = $this->input->post('id'); + $type = intval($this->input->post('type')); + $brand_biz = $this->input->post('brand_biz'); + + $info = $this->auto_brand_model->get(array('id' => $brand_id)); + if (!$info) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $biz_ids = ''; + $brand_biz && $biz_ids = implode(',',array_unique(array_keys($brand_biz))); + if($brand_biz && $biz_ids){ + $where = [ + "biz_id not in ({$biz_ids})" => null, + 'brand_id' => $brand_id + ]; + $type && $where['type'] = $type; + if($this->auto_brand_biz_model->count($where)){ + $this->auto_brand_biz_model->delete($where); + } + $add_datas = []; + foreach ($brand_biz as $key => $val) { + $where = [ + 'biz_id' => $key, + 'brand_id' => $brand_id + ]; + $type && $where['type'] = $type; + if(!$this->auto_brand_biz_model->count($where)){ + if(!$type){ + $biz_row = $this->biz_model->get(['id'=>$key],'type'); + $type = $biz_row['type']; + } + $add_datas[] = [ + 'biz_id' => $key, + 'type' => $type, + 'brand_id' => $brand_id, + 'c_time' => time() + ]; + } + } + $add_datas && $this->auto_brand_biz_model->add_batch($add_datas); + }else{ + $where = [ + 'brand_id' => $brand_id, + ]; + $type && $where['type'] = $type; + if($this->auto_brand_biz_model->count($where)){ + $this->auto_brand_biz_model->delete($where); + } + } + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + + public function ajax_biz(){ + $type = intval($this->input->get('type')); + $brand_id = intval($this->input->get('id')); + if($type){ + $where = [ + 'status' => 1, + 'type' => $type, + "id not in (select biz_id from lc_auto_brand_biz where brand_id={$brand_id} and type={$type})" => null + ]; + }else{ + $where = [ + 'status' => 1, + "id not in (select biz_id from lc_auto_brand_biz where brand_id={$brand_id})" => null + ]; + } + $biz_lists = $this->biz_model->map('id','biz_name',$where,'',0,0,'id,biz_name'); + if($type){ + $where = [ + 'status' => 1, + 'type' => $type, + "id in (select biz_id from lc_auto_brand_biz where brand_id={$brand_id} and type={$type})" => null + ]; + }else{ + $where = [ + 'status' => 1, + "id in (select biz_id from lc_auto_brand_biz where brand_id={$brand_id})" => null + ]; + } + $brand_biz = $this->biz_model->map('id','biz_name',$where,'',0,0,'id,biz_name'); + $this->data['biz_lists'] = $biz_lists; + $this->data['brand_biz'] = $brand_biz; + return $this->show_json(SYS_CODE_SUCCESS); + } + + //旧门店授权品牌脚本 + public function change(){ + $page = $this->input->get('page'); + $size = $this->input->get('size'); + !$page && $page = 1; + !$size && $size = 20; + $where = [ + 'status' => 1 + ]; + $rows = $this->biz_model->select($where,'id asc',$page,$size,'id,type,jsondata'); + if($rows){ + foreach ($rows as $key=>$val) { + $jsondata = json_decode($val['jsondata'],true); + $add_datas = []; + if($jsondata['auto_brands'] && is_array($jsondata['auto_brands'])){ + foreach ($jsondata['auto_brands'] as $v) { + $where = [ + 'biz_id'=>$val['id'], + 'type'=>$val['type'], + 'brand_id'=>$v + ]; + if(!$this->auto_brand_biz_model->count($where)){ + $add_datas[] = [ + 'biz_id' => $val['id'], + 'type' => $val['type'], + 'brand_id' => $v, + 'c_time' => time() + ]; + } + + } + $add_datas && $this->auto_brand_biz_model->add_batch($add_datas); + echo "门店id:{$val['id']},添加数据:".json_encode($add_datas,JSON_UNESCAPED_UNICODE).'
'; + }else{ + echo "门店id:{$val['id']},无授权品牌
"; + } + } + }else{ + echo '执行完毕'; + } + } } diff --git a/admin/views/auto/brand/edit_biz.php b/admin/views/auto/brand/edit_biz.php new file mode 100755 index 00000000..c041d37d --- /dev/null +++ b/admin/views/auto/brand/edit_biz.php @@ -0,0 +1,250 @@ + + +
+
+
+

门店类型

+ +
+
+

未授权门店

+
+
+ +
+
+
+ + +
+
+
+

已授权门店

+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+
+ +
+
+ 保存 +
+
+
+
+ + diff --git a/admin/views/auto/brand/lists.php b/admin/views/auto/brand/lists.php index 40493b12..c3ec2606 100755 --- a/admin/views/auto/brand/lists.php +++ b/admin/views/auto/brand/lists.php @@ -25,6 +25,7 @@ ID 品牌名称 状态 + 授权门店数 创建时间 操作 @@ -35,6 +36,7 @@ + 恢复 - + | + 授权门店 diff --git a/common/models/auto/Auto_brand_biz_model.php b/common/models/auto/Auto_brand_biz_model.php new file mode 100644 index 00000000..d87f056b --- /dev/null +++ b/common/models/auto/Auto_brand_biz_model.php @@ -0,0 +1,19 @@ +table_name, 'default'); + } + +} diff --git a/sql/auto.sql b/sql/auto.sql index b72d66ad..fe5dedda 100644 --- a/sql/auto.sql +++ b/sql/auto.sql @@ -122,3 +122,19 @@ create table lc_auto_car_finance ( u_time timestamp not null default current_timestamp on update current_timestamp comment '更新时间', primary key (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车型金融信息' + +-- ---------------------------- +-- Title:车型金融信息 +-- Author:lcc +-- Table:lc_auto_car_finance +-- --------------------------- +drop table if exists lc_auto_brand_biz; +create table lc_auto_brand_biz ( + id int(10) not null auto_increment, + biz_id int(10) not null comment '门店id', + brand_id int(10) not null comment '车型品牌id', + type tinyint(3) not null comment '门店类型', + c_time int(10) not null default '0' COMMENT '创建时间', + u_time timestamp not null default current_timestamp on update current_timestamp comment '更新时间', + primary key (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='品牌授权门店'