From f6f17c4e21babaf20cb6491656f53a1d12fc624c Mon Sep 17 00:00:00 2001
From: lccsw <805383944@qq.com>
Date: Mon, 30 Jan 2023 14:40:29 +0800
Subject: [PATCH] add-auto-biz
---
admin/controllers/auto/Brand.php | 152 +++++++++++-
admin/views/auto/brand/edit_biz.php | 250 ++++++++++++++++++++
admin/views/auto/brand/lists.php | 6 +-
common/models/auto/Auto_brand_biz_model.php | 19 ++
sql/auto.sql | 16 ++
5 files changed, 441 insertions(+), 2 deletions(-)
create mode 100755 admin/views/auto/brand/edit_biz.php
create mode 100644 common/models/auto/Auto_brand_biz_model.php
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 @@
+
+
+