add-auto-biz

This commit is contained in:
lccsw
2023-01-30 14:40:29 +08:00
parent 5c341c997d
commit f6f17c4e21
5 changed files with 441 additions and 2 deletions
+151 -1
View File
@@ -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).'<br>';
}else{
echo "门店id:{$val['id']},无授权品牌<br>";
}
}
}else{
echo '执行完毕';
}
}
}
+250
View File
@@ -0,0 +1,250 @@
<style type="text/css">
.seaction-hand-area {
padding: 20px 30px
}
.seaction-hand-area .sec-lf {
min-width: 100px;
padding: 30px 0 0;
float: left;
margin-right: 50px;
position: relative;
border: 1px solid #e6e6e6
}
.seaction-hand-area .sec-lf .caption {
position: absolute;
left: 0;
top: 0;
right: 0;
height: 30px;
line-height: 30px;
background: #f2f2f2;
text-align: center
}
.seaction-hand-area .sec-lf .list {
max-height: 438px;
overflow: auto
}
.seaction-hand-area .sec-lf .list li {
border-bottom: 1px solid #e6e6e6
}
.seaction-hand-area .sec-lf .list li.active a {
color: #fff;
background: #3bb4f2
}
.seaction-hand-area .sec-lf .list li a {
display: block;
height: 40px;
line-height: 40px;
padding: 0 20px;
text-align: center;
color: #333
}
.seaction-hand-area .sec-lf .list li a:hover {
color: #fff;
background: #3bb4f2
}
.seaction-hand-area .sec-mid, .seaction-hand-area .sec-rt {
padding: 30px 0 40px;
margin-right: 50px;
float: left;
position: relative;
border: 1px solid #e6e6e6;
min-width: 250px
}
.seaction-hand-area .sec-mid .caption, .seaction-hand-area .sec-rt .caption {
position: absolute;
left: 0;
top: 0;
right: 0;
height: 30px;
line-height: 30px;
background: #f2f2f2;
text-align: center
}
.check-hand-box {
padding: 10px 0;
min-height: 200px;
max-height: 400px;
overflow: auto
}
.check-hand-box .item-cell {
color: #333;
padding: 3px 15px
}
.check-hand-box .item-cell label {
font-weight: 400
}
.check-hand-btns {
background: #f2f2f2;
position: absolute;
right: 0;
bottom: 0;
left: 0;
padding: 5px 15px
}
.check-hand-btns .check-all {
font-size: 14px;
font-weight: 400
}
.check-hand-btns .check-all input {
display: inline-block;
vertical-align: middle;
margin-top: -2px
}
</style>
<!-- table 表格样式************************************* -->
<div id="vue-app">
<div class="seaction-hand-area clearfix">
<div class="sec-lf">
<p class="caption">门店类型</p>
<ul class="list">
<li :class="params.cate_id > 0 ? '': 'active'" @click="get_biz(0)">
<a href="javascript:;">所有门店</a>
</li>
<li :class="params.cate_id == i ? 'active': ''" v-for="(v,i) in cate_lists" @click="get_biz(i)">
<a href="javascript:;">{{v}}</a>
</li>
</ul>
</div>
<div class="sec-mid clearfix">
<p class="caption">未授权门店</p>
<div class="check-hand-box" id="biz_lists">
<div class="item-cell" v-for="(v,i) in biz_lists">
<label><input type="checkbox" :value="i" class="biz-ids">{{v}}</label>
</div>
</div>
<div class="check-hand-btns clearfix">
<label class="check-all fl">
<input type="checkbox" data-check-target=".biz-ids">全选
</label>
<button class="am-btn am-btn-primary am-btn-xs fr" id="add_biz" @click="add_biz">选择</button>
</div>
</div>
<div class="sec-rt">
<p class="caption">已授权门店</p>
<div class="check-hand-box" id="hz_biz_lists">
<div class="item-cell" v-for="(v,i) in brand_biz">
<label><input type="checkbox" :value="i" data-type="remove" class="hz_biz_lists">{{v}}</label>
</div>
</div>
<div class="check-hand-btns clearfix">
<label class="check-all fl">
<input type="checkbox" data-check-target=".hz_biz_lists">全选
</label>
<button class="am-btn am-btn-danger am-btn-xs fr" id="remove_biz" @click="remove_biz">移除</button>
</div>
</div>
</div>
<form class="am-form am-form-horizontal ptb20 pr20" action="" data-auto="true" method="post">
<div class="am-form-group" style="margin-bottom: 2rem">
<div class="add_input">
</div>
<div class="remove_input">
</div>
<div class="am-para-input">
<a href="javascript:;" class="am-btn am-btn-secondary" type="button" id="edit-btn" @click="save">保存</a>
</div>
</div>
</form>
</div>
<script>
vue_obj = new Vue({
el: '#vue-app',
data: {
params:[],
cate_lists:[],
biz_lists:new Object(),
brand_biz:new Object(),
},
mounted:function() {
this.params = <?=json_encode($params,JSON_UNESCAPED_UNICODE)?>;
this.cate_lists = <?=json_encode($cate_lists,JSON_UNESCAPED_UNICODE)?>;
this.get_biz(this.params.cate_id)
},
methods:{
get_biz(cate_id=0){
var that = this
this.params.cate_id=cate_id
this.biz_lists = new Object()
this.brand_biz = new Object()
var params = {
'id' : this.params.id,
'type' : this.params.cate_id
}
$.get('/auto/brand/ajax_biz',params,function (res){
if(res.data.biz_lists && res.data.biz_lists.length!=0){
that.biz_lists = res.data.biz_lists
}
if(res.data.brand_biz && res.data.brand_biz.length!=0){
that.brand_biz = res.data.brand_biz
}
},'json')
},
add_biz(){
var that = this
$(".biz-ids").each(function(){
var check = $(this).is(':checked');
var biz_name = $(this).parent().text();
var biz_id = $(this).val();
if(check){
$(this).prop("checked",false);
delete that.biz_lists[biz_id]
that.brand_biz[biz_id] = biz_name
}
});
this.$forceUpdate()
},
remove_biz(){
var that = this
$(".hz_biz_lists").each(function(){
var check = $(this).is(':checked');
var biz_name = $(this).parent().text();
var biz_id = $(this).val();
if(check){
$(this).prop("checked",false);
delete that.brand_biz[biz_id]
that.biz_lists[biz_id] = biz_name
}
});
this.$forceUpdate()
},
save(){
var params = {
'id' : this.params.id,
'brand_biz' : this.brand_biz,
'type' : this.params.cate_id
}
$.post('/auto/brand/edit_biz',params,function (result){
if(result.code){
layer.msg(result.msg, {time: 2000,icon:1 }, function () {
// $.form.reload();
});
}else{
layer.msg(result.msg,{icon:2});
}
},'json')
}
},
watch:{
}
});
</script>
+5 -1
View File
@@ -25,6 +25,7 @@
<th width="10%"><span>ID</span></th>
<th width="20%"><span>品牌名称</span></th>
<th width="10%"><span>状态</span></th>
<th width="10%"><span>授权门店数</span></th>
<th width="15%"><span>创建时间</span></th>
<th width="35%"><span>操作</span></th>
</tr>
@@ -35,6 +36,7 @@
<td><?= $v['id'] ?></td>
<td><?= $v['name'] ?></td>
<td><?= $v['status_name'] ?></td>
<td><?= $v['t_biz'] ?></td>
<td><?= $v['c_time'] ?></td>
<td>
<a href="javascript:void (0);" data-title="编辑品牌" data-modal="/auto/brand/get?id=<?= $v['id'] ?>"
@@ -46,7 +48,9 @@
<a style="color: red" href="javascript:void (0);" data-ajax="post"
data-action="/auto/brand/del"
data-params-id="<?= $v['id'] ?>" data-params-status="1">恢复</a>
<?php } ?>
<?php } ?>|
<a href="javascript:void (0);" data-open="/auto/brand/get_biz?id=<?= $v['id'] ?>"
class="am-text-primary">授权门店</a>
</td>
</tr>
<?php } ?>
@@ -0,0 +1,19 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Created by Vim.
* User: lcc
* Date: 2021/06/23
* Time: 16:24
*/
class Auto_brand_biz_model extends HD_Model
{
private $table_name = 'lc_auto_brand_biz';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
}
+16
View File
@@ -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='品牌授权门店'