443 lines
18 KiB
PHP
443 lines
18 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: lcc
|
|
* Date: 2022/2/15
|
|
* Time: 15:35
|
|
*/
|
|
class Business extends HD_Controller{
|
|
|
|
public function __construct(){
|
|
parent::__construct();
|
|
|
|
$this->load->model('auto/auto_brand_model');
|
|
$this->load->model('auto/auto_series_model');
|
|
$this->load->model('auto/auto_attr_model');
|
|
$this->load->model('auto/auto_cars_model');
|
|
$this->load->model('auto/auto_business_model');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$params = $this->input->get();
|
|
!isset($params['status']) && $params['status'] = 1;
|
|
!isset($params['if_effect']) && $params['if_effect'] = 1;
|
|
!isset($params['month']) && $params['month'] = '';
|
|
|
|
$where = array();
|
|
$where['brand_id in (select id from lc_auto_brand where status = 1)'] = null;
|
|
$where['s_id in (select id from lc_auto_series where status = 1)'] = null;
|
|
$where['v_id in (select id from lc_auto_attr where status = 1 and type = 1)'] = null;
|
|
if($params['brand_id']){
|
|
$where['brand_id'] = $params['brand_id'];
|
|
} else{
|
|
$params['brand_id'] = '';
|
|
}
|
|
|
|
if($params['s_id']){
|
|
$where['s_id'] = $params['s_id'];
|
|
} else{
|
|
$params['s_id'] = '';
|
|
}
|
|
if($params['v_id']){
|
|
$where['v_id'] = $params['v_id'];
|
|
} else{
|
|
$params['V_id'] = '';
|
|
}
|
|
if(strlen($params['status'])){
|
|
$where['status'] = $params['status'];
|
|
} else {
|
|
$params['status'] = '';
|
|
}
|
|
if(strlen($params['if_effect'])){
|
|
$where['if_effect'] = $params['if_effect'];
|
|
} else {
|
|
$params['if_effect'] = '';
|
|
}
|
|
if($params['city_id']){
|
|
$where['city_id'] = $params['city_id'];
|
|
} else{
|
|
$params['city_id'] = '';
|
|
}
|
|
if($params['year']){
|
|
$where['year'] = $params['year'];
|
|
}elseif(!isset($params['year'])){
|
|
$where['year'] = $params['year'] = date('Y');
|
|
}
|
|
if($params['month']){
|
|
$where['month'] = $params['month'];
|
|
}
|
|
$page = $params['page'];
|
|
$page = !$page ? 1 : $page;
|
|
$size = $params['size'];
|
|
$size = !$size ? 20 : $size;
|
|
|
|
//获取品牌map
|
|
$where_brand = array('status = 1' => null);
|
|
$map_brand = $this->auto_brand_model->map_brand($where_brand);
|
|
//状态
|
|
$statusAry = array('0' => '关闭', '1' => '开启');
|
|
|
|
$total = $this->auto_business_model->count($where);
|
|
$lists = array();
|
|
if($total){
|
|
$orderby = 'id desc';
|
|
$select = '*';
|
|
$rows = $this->auto_business_model->select($where, $orderby, $page, $size, $select);
|
|
if($rows){
|
|
$s_ids = array_unique(array_column($rows,'s_id'));
|
|
$attr_ids = array_unique(array_column($rows,'v_id'));
|
|
$city_ids = array_unique(array_column($rows,'city_id'));
|
|
//获取车系列表
|
|
$map_sery = array();
|
|
if($s_ids){
|
|
$str_ids = implode(',', $s_ids);
|
|
$where_sery = array("id in ({$str_ids})" => null);
|
|
$map_sery = $this->auto_series_model->map('id', 'name', $where_sery, 'id desc', 0, 0, 'id,name');
|
|
}
|
|
$map_attr = array();
|
|
if($attr_ids){
|
|
$str_ids = implode(',', $attr_ids);
|
|
$where_attr = array("id in ({$str_ids})" => null);
|
|
$map_attr = $this->auto_attr_model->map('id', 'title', $where_attr, 'id desc', 0 , 0, 'id, title, type');
|
|
}
|
|
if($city_ids){
|
|
$str_ids = implode(',', $city_ids);
|
|
$where_city = array("city_id in ({$str_ids})" => null);
|
|
$map_city = $this->sys_city_model->map('city_id', 'name', $where_city, 'id desc', 0 , 0, 'city_id, name');
|
|
}
|
|
//属性按'车型-车身颜色-内饰颜色'排序
|
|
foreach($rows as $v){
|
|
$title = "{$map_brand[$v['brand_id']]} {$map_sery[$v['s_id']]} {$map_attr[$v['v_id']]}";
|
|
$city_cn = $map_city[$v['city_id']];
|
|
$month = date('Y-m',strtotime("{$v['year']}-{$v['month']}"));
|
|
$lists[] = array(
|
|
'id' => $v['id'],
|
|
'title' => $title,
|
|
'status' => $v['status'],
|
|
'price_car' => $v['price_car'] > 0 ? $v['price_car'] : '0.00',
|
|
'price_floor' => $v['price_floor'] > 0 ? $v['price_floor'] : '0.00',
|
|
'price_coplus' => $v['price_coplus'] > 0 ? $v['price_coplus'] : '0.00',
|
|
'price_color' => $v['price_color'] > 0 ? $v['price_color'] : '0.00',
|
|
'profix_car' => $v['profix_car'],
|
|
'proxy_type' => $v['proxy_type'] == 0 ? '返佣' : '票折',
|
|
'proxy_profix_car' => $v['proxy_profix_car'],
|
|
'profix_insure' => $v['profix_insure'],
|
|
'profix_carno' => $v['profix_carno'],
|
|
'profix_loan' => $v['profix_loan'],
|
|
'city_cn'=> $city_cn,
|
|
'month' => $month,
|
|
's_effect_time' => $v['s_effect_time'] ? date('Y-m-d',$v['s_effect_time']) : '',
|
|
'effect_status' => $v['if_effect'] ? '生效中' : '未生效',
|
|
'if_effect' => $v['if_effect'],
|
|
'delivery_day' => $v['delivery_day']
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->data['params'] = $params;
|
|
$this->data['lists'] = $lists;
|
|
$this->data['statusAry'] = $statusAry;
|
|
$this->data['brandAry'] = $this->auto_brand_model->map_brand_list($map_brand);
|
|
$this->data['cityAry'] = $this->sys_city_model->select(['status'=>1],'id desc',0,0,'city_id,name');
|
|
$this->data['yearAry'] = $this->auto_business_model->year();
|
|
$this->data['monthAry'] = $this->auto_business_model->month();
|
|
$this->data['pager'] = array('count' => ceil($total / $size), 'curr' => $page, 'totle' => $total);
|
|
$this->data['_title'] = '商务政策管理';
|
|
$this->show_view('auto/business/lists',true);
|
|
}
|
|
|
|
public function lists()
|
|
{
|
|
// TODO: Implement lists() method.
|
|
}
|
|
|
|
public function get()
|
|
{
|
|
$id = $this->input->get('id');
|
|
#$map_brand = $this->auto_brand_model->map('id', 'name', ['status>'=>-1], 'id desc', 0 , 0, 'id, name');
|
|
$map_brand = $this->auto_brand_model->map_brand_list($this->auto_brand_model->map_brand(array('status = 1' => null)));
|
|
$city_rows = $this->sys_city_model->select(['status'=>1],'id desc',0,0,'city_id,name');
|
|
$row = $this->auto_business_model->get(['id'=>$id]);
|
|
if($id && $row){
|
|
$info = [
|
|
'id' => $row['id'],
|
|
'city_id' => $row['city_id'],
|
|
'brand_id' => ' '.$row['brand_id'],
|
|
's_id' => $row['s_id'],
|
|
'v_id' => $row['v_id'],
|
|
'price_car' => $row['price_car'],
|
|
'price_floor' => $row['price_floor'],
|
|
'price_color' => $row['price_color'],
|
|
'price_coplus' => $row['price_coplus'],
|
|
'proxy_type' => intval($row['proxy_type']),
|
|
'proxy_profix_car' => $row['proxy_profix_car'],
|
|
'profix_car' => $row['profix_car'],
|
|
'profix_carno' => $row['profix_carno'],
|
|
'profix_insure' => $row['profix_insure'],
|
|
'profix_loan' => $row['profix_loan'],
|
|
'delivery_day' => $row['delivery_day'],
|
|
'date' => date('Y-m',strtotime("{$row['year']}-{$row['month']}")),
|
|
'year' => $row['year'],
|
|
'month' => intval($row['month']),
|
|
'colors' => json_decode($row['colors'],true),
|
|
's_effect_time' => $row['s_effect_time'] ? date('Y-m-d',$row['s_effect_time']) : '',
|
|
'action' => 'auto/business/edit',
|
|
];
|
|
if($this->input->get('type')=='copy'){ //复制
|
|
$info['month'] = intval(date('m'));
|
|
$info['action'] = 'auto/business/add';
|
|
$info['s_effect_time'] = date('Y-m-d');
|
|
}
|
|
}else{
|
|
$info = [
|
|
'city_id' => '',
|
|
'brand_id' => '',
|
|
's_id' => '',
|
|
'v_id' => '',
|
|
'price_car' => 0.00,
|
|
'price_floor' => 0.00,
|
|
'price_color' => 0.00,
|
|
'price_coplus' => 0.00,
|
|
'proxy_type' => 0,
|
|
'proxy_profix_car' => 0.00,
|
|
'profix_car' => 0.00,
|
|
'profix_carno' => 0.00,
|
|
'profix_insure' => 0.00,
|
|
'profix_loan' => 0.00,
|
|
'delivery_day' => 0,
|
|
'action' => 'auto/business/add',
|
|
'year' => date('Y'),
|
|
'month' => intval(date('m')),
|
|
's_effect_time' => date('Y-m-d'),
|
|
'colors' => []
|
|
];
|
|
}
|
|
$this->data['info'] = $info;
|
|
$this->data['brandAry'] = $map_brand;
|
|
$this->data['city_rows'] = $city_rows;
|
|
$this->data['yearAry'] = $this->auto_business_model->year();
|
|
$this->data['monthAry'] = $this->auto_business_model->month();
|
|
$this->data['_title'] = '添加';
|
|
$this->show_view('auto/business/get');
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
$info = $this->input->post('info');
|
|
$res = $this->valid_data($info);
|
|
if(!$res['code']){
|
|
return $this->show_json(SYS_CODE_FAIL,$res['msg']);
|
|
}
|
|
$year = $info['year'];
|
|
$month = intval($info['month']);
|
|
$where = [
|
|
'brand_id' => $info['brand_id'],
|
|
's_id' => $info['s_id'],
|
|
'v_id' => $info['v_id'],
|
|
'city_id' => $info['city_id'],
|
|
'year' => $year,
|
|
'month' => $month,
|
|
'status'=>1
|
|
];
|
|
if($this->auto_business_model->get($where)){
|
|
return $this->show_json(SYS_CODE_FAIL, '数据已存在');
|
|
}
|
|
$data = [
|
|
'brand_id' => $info['brand_id'],
|
|
's_id' => $info['s_id'],
|
|
'v_id' => $info['v_id'],
|
|
'city_id' => $info['city_id'],
|
|
'year' => $year,
|
|
'month' => $month,
|
|
'status' => 1,
|
|
'c_time' => time()
|
|
];
|
|
$info['price_car'] && $data['price_car'] = $info['price_car'];
|
|
$info['price_floor'] && $data['price_floor'] = $info['price_floor'];
|
|
$info['price_coplus'] && $data['price_coplus'] = $info['price_coplus'];
|
|
$info['price_color'] && $data['price_color'] = $info['price_color'];
|
|
$data['proxy_type'] = $info['proxy_type'];
|
|
$info['proxy_profix_car'] && $data['proxy_profix_car'] = $info['proxy_profix_car'];
|
|
$info['profix_car'] && $data['profix_car'] = $info['profix_car'];
|
|
$info['profix_carno'] && $data['profix_carno'] = $info['profix_carno'];
|
|
$info['profix_insure'] && $data['profix_insure'] = $info['profix_insure'];
|
|
$info['profix_loan'] && $data['profix_loan'] = $info['profix_loan'];
|
|
$info['colors'] && $data['colors'] = json_encode($info['colors'],JSON_UNESCAPED_UNICODE);
|
|
$info['s_effect_time'] && $data['s_effect_time'] = strtotime($info['s_effect_time']);
|
|
$info['delivery_day'] && $data['delivery_day'] = $info['delivery_day'];
|
|
if(time()>$data['s_effect_time']){
|
|
$data['if_effect'] = 1;
|
|
}
|
|
$this->auto_business_model->add($data);
|
|
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
$info = $this->input->post('info');
|
|
if(!$this->auto_business_model->get(['id'=>$info['id']])){
|
|
return $this->show_json(SYS_CODE_FAIL,'参数错误');
|
|
}
|
|
$res = $this->valid_data($info);
|
|
if(!$res['code']){
|
|
return $this->show_json(SYS_CODE_FAIL,$res['msg']);
|
|
}
|
|
$year = $info['year'];
|
|
$month = intval($info['month']);
|
|
$where = [
|
|
'brand_id' => $info['brand_id'],
|
|
's_id' => $info['s_id'],
|
|
'v_id' => $info['v_id'],
|
|
'city_id' => $info['city_id'],
|
|
'year' => $year,
|
|
'month' => $month,
|
|
'status'=>1,
|
|
'id !=' => $info['id']
|
|
];
|
|
if($this->auto_business_model->get($where)){
|
|
return $this->show_json(SYS_CODE_FAIL, '数据已存在');
|
|
}
|
|
$data = [
|
|
'city_id' => $info['city_id'],
|
|
'brand_id' => $info['brand_id'],
|
|
's_id' => $info['s_id'],
|
|
'v_id' => $info['v_id'],
|
|
'year' => $year,
|
|
'month' => $month,
|
|
];
|
|
$data['price_car'] = $info['price_car'];
|
|
$data['price_floor'] = $info['price_floor'];
|
|
$data['price_coplus'] = $info['price_coplus'];
|
|
$data['price_color'] = $info['price_color'];
|
|
$data['proxy_type'] = $info['proxy_type'];
|
|
$data['proxy_profix_car'] = $info['proxy_profix_car'];
|
|
$data['profix_car'] = $info['profix_car'];
|
|
$data['profix_carno'] = $info['profix_carno'];
|
|
$data['profix_insure'] = $info['profix_insure'];
|
|
$data['profix_loan'] = $info['profix_loan'];
|
|
$info['colors'] && $data['colors'] = json_encode($info['colors'],JSON_UNESCAPED_UNICODE);
|
|
$info['s_effect_time'] && $data['s_effect_time'] = strtotime($info['s_effect_time']);
|
|
$info['delivery_day'] && $data['delivery_day'] = $info['delivery_day'];
|
|
if(time()>$data['s_effect_time']){
|
|
$data['if_effect'] = 1;
|
|
}
|
|
$this->auto_business_model->update($data,['id'=>$info['id']]);
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
// TODO: Implement del() method.
|
|
}
|
|
|
|
public function batch()
|
|
{
|
|
// TODO: Implement batch() method.
|
|
}
|
|
|
|
public function export()
|
|
{
|
|
// TODO: Implement export() method.
|
|
}
|
|
function edit_status(){
|
|
$id = $this->input->post('id');
|
|
$field = $this->input->post('field');
|
|
$value = $this->input->post('value');
|
|
$status = $this->input->post('status');
|
|
|
|
$upd = [];
|
|
if('status' == $field){
|
|
$status = $value;
|
|
$upd = array('status' => $status);
|
|
}
|
|
|
|
if($field == 'if_effect'){
|
|
$upd['if_effect'] = $value;
|
|
if($value){ //生效
|
|
$row = $this->auto_business_model->get(['id'=>$id]);
|
|
$where = [
|
|
'city_id' => $row['city_id'],
|
|
'brand_id' => $row['brand_id'],
|
|
's_id' => $row['s_id'],
|
|
'v_id' => $row['v_id'],
|
|
'status' => 1,
|
|
's_effect_time>' => $row['s_effect_time'],
|
|
];
|
|
if($this->auto_business_model->count($where)){
|
|
return $this->show_json(SYS_CODE_FAIL, '存在更新生效设置');
|
|
}
|
|
unset($where['s_effect_time']);
|
|
$this->auto_business_model->update(['if_effect'=>0],$where);
|
|
}
|
|
}
|
|
|
|
if(is_numeric($id)){
|
|
$where = array('id' => $id);
|
|
} else {
|
|
$where = array("id in ({$id})" => null);
|
|
}
|
|
|
|
$ret = $this->auto_business_model->update($upd, $where);
|
|
if(!$ret){
|
|
return $this->show_json(SYS_CODE_FAIL, '保存失败');
|
|
}
|
|
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
}
|
|
|
|
function add_copy(){
|
|
$id = $this->input->post('id');
|
|
$row = $this->auto_business_model->get(['id'=>$id]);
|
|
if(!$row){
|
|
return $this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
$year = date('Y');
|
|
$month = date('m');
|
|
$where = [
|
|
'brand_id' => $row['brand_id'],
|
|
's_id' => $row['s_id'],
|
|
'v_id' => $row['v_id'],
|
|
'city_id' => $row['city_id'],
|
|
'year' => $year,
|
|
'month' => $month,
|
|
'status>='=>0
|
|
];
|
|
if($this->auto_business_model->get($where)){
|
|
return $this->show_json(SYS_CODE_FAIL, '本月该数据已存在');
|
|
}
|
|
$data = [
|
|
'city_id' => $row['city_id'],
|
|
'brand_id' => $row['brand_id'],
|
|
's_id' => $row['s_id'],
|
|
'v_id' => $row['v_id'],
|
|
'year' => $year,
|
|
'month' => $month,
|
|
'status' => 1,
|
|
'c_time' => time()
|
|
];
|
|
$row['price_car'] && $data['price_car'] = $row['price_car'];
|
|
$row['price_floor'] && $data['price_floor'] = $row['price_floor'];
|
|
$row['price_coplus'] && $data['price_coplus'] = $row['price_coplus'];
|
|
$row['price_color'] && $data['price_color'] = $row['price_color'];
|
|
$this->auto_business_model->add($data);
|
|
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
|
|
}
|
|
private function valid_data($info){
|
|
if(!$info['brand_id']){
|
|
return ['code'=>0,'msg'=>'请选择品牌'];
|
|
}
|
|
if(!$info['s_id']){
|
|
return ['code'=>0,'msg'=>'请选择车系'];
|
|
}
|
|
if(!$info['v_id']){
|
|
return ['code'=>0,'msg'=>'请选择车型'];
|
|
}
|
|
if(!$info['city_id']){
|
|
return ['code'=>0,'msg'=>'请选择城市'];
|
|
}
|
|
return ['code'=>1,'msg'=>'验证成功'];
|
|
}
|
|
}
|