Files
liche/admin/controllers/biz/Settle.php
T
2022-09-15 16:05:51 +08:00

713 lines
32 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once COMMPATH.'third_party/PHPExcel.php';
class Settle 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_business_model');
$this->load->model('items/items_model');
$this->load->model('receiver/order/receiver_orders_v2_model');
$this->load->model('receiver/order/receiver_order_datas_model');
$this->load->model('receiver/order/receiver_order_loans_model','order_loans_model');
$this->load->model('receiver/receiver_fine_model');
$this->load->model('biz/biz_model');
$this->load->model('biz/biz_settle_model');
$this->load->model('biz/biz_settle_srv_model');
$this->load->model('biz/biz_settle_static_model');
$this->load->model('biz/biz_info_model');
$this->load->model('biz/biz_trucking_model');
$this->load->library('receiver/orders_v2_entity');
$this->load->library('receiver/settle_entity');
}
public function index()
{
$this->lists();
}
public function lists()
{
$params = $this->input->get();
$where = array();
$t1 = 'lc_biz_settle';
$t2 = 'lc_receiver_orders_v2';
if($params['biz_id']){
$where["$t1.biz_id"] = $params['biz_id'];
} else{
$params['biz_id'] = '';
}
if($params['brand_id']){
$where["$t2.brand_id"] = $params['brand_id'];
} else{
$params['brand_id'] = '';
}
if($params['s_id']){
$where["$t2.s_id"] = $params['s_id'];
} else{
$params['s_id'] = '';
}
if($params['v_id']){
$where["$t2.v_id"] = $params['v_id'];
} else{
$params['v_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'];
}elseif(!isset($params['month'])){
$where['month'] = $params['month'] = intval(date('m'));
}
$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('id', 'name', $where_brand, 'id desc', 0 , 0, 'id, name');
$total = $this->biz_settle_model->selectOrders($where, '', '', '',1);
$lists = array();
if($total){
$orderby = "$t1.id desc";
$select = "$t1.*,$t2.sid,$t2.name,$t2.mobile,$t2.s_id,$t2.v_id,$t2.brand_id,$t2.cor_id,$t2.item_id,$t2.money_json as o_money_json,$t2.srv_ids";
$rows = $this->biz_settle_model->selectOrders($where, $orderby, $page, $size,0, $select);
if($rows){
$s_ids = array_unique(array_filter(array_column($rows,'s_id')));
$cor_ids = array_unique(array_filter(array_column($rows,'cor_id')));
$v_ids = array_unique(array_filter(array_column($rows,'v_id')));
$attr_ids = array_merge($cor_ids,$v_ids);
$item_ids = array_unique(array_filter(array_column($rows,'item_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');
}
$biz_ids = array_unique(array_column($rows,'biz_id'));
$map_biz = [];
if($biz_ids){
$biz_ids = implode(',',array_filter($biz_ids));
$where_biz = ["id in ({$biz_ids})" => null];
$map_biz = $this->biz_model->map('id', 'biz_name', $where_biz, '', 0, 0, 'id,biz_name');
}
$map_item = [];
if($item_ids){
$str_item_ids = implode(',',$item_ids);
$where_item = ["id in ({$str_item_ids})" => null];
$map_item = $this->items_model->map('id', 'vin', $where_item, '', 0, 0, 'id,vin');
}
foreach($rows as $v){
$title = "{$map_brand[$v['brand_id']]} {$map_sery[$v['s_id']]} {$map_attr[$v['v_id']]} {$map_attr[$v['cor_id']]}";
$month = date('Y-m',strtotime("{$v['year']}-{$v['month']}"));
$money_json = json_decode($v['money_json'],true);
$o_money_json = json_decode($v['o_money_json'],true);
$sum_srv = $v['profix_insure']+$v['profix_carno']+$v['profix_loan']+$v['profix_fine'];
$srv_json = json_decode($v['srv_ids'],true);
$srv_loan = 0;
if($v['profix_loan']>0 && $srv_json){
foreach ($srv_json as $v2) {
if($v2['key']=='price_finance'){
$srv_loan = $v2['price'];
break;
}
}
}
$lists[] = array(
'id' => $v['id'],
'o_id' => $v['o_id'],
'title' => $title,
'biz_name' => $map_biz[$v['biz_id']],
'profix_car' => $v['profix_car'],
'profix_car_after' => sprintf("%.2f",$v['profix_car']/1.13),
'profix_insure' => $v['profix_insure'],
'profix_carno' => $v['profix_carno'],
'profix_loan' => $v['profix_loan'],
'srv_json' => $srv_loan,
'profix_fine' => $v['profix_fine'],
'sum_srv' => $sum_srv,
'sum_srv_after' => $params['_biz_type']==1 ? sprintf("%.2f",$sum_srv/1.13) : sprintf("%.2f",$sum_srv/1.06),
'price_trucking' => $v['price_trucking'],
'name' => $v['name'],
'mobile' => $v['mobile'],
'sid' => $v['sid'],
'month' => $month,
'vin' => $map_item[$v['item_id']],
'money_json' => is_array($money_json) ? $money_json : [],
'o_money_json' => $o_money_json
);
}
}
}
$this->data['params'] = $params;
$this->data['lists'] = $lists;
$this->data['brandAry'] = $map_brand;
$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'] = '商家结算管理';
$view = $params['_biz_type']==1 ? 'biz/settle/lists_brand' : 'biz/settle/lists';
$this->show_view($view,true);
}
public function get(){
}
public function add(){
}
public function edit()
{
}
public function del()
{
}
public function batch()
{
}
public function export()
{
$biz_id = $this->input->get('id');
$month = $this->input->get('month');
$year = date('Y');
!$month && $month = intval(date('m',strtotime("-1 month")));;
$where = [
'biz_id' => $biz_id,
'year' => $year,
'month' => $month
];
$type_arr = $this->biz_settle_static_model->other_price_type();
$biz = $this->biz_model->get(['id'=>$biz_id],'biz_name');
$row = $this->biz_settle_static_model->get($where);
$sheet_data = [];
if($row){
$sheet_data[] = [
'门店','单车总毛利','税后单车总毛利','水平业务总毛利',
'店面租金','水电费','店长工资','店员工资',
'抽成','拖车费','其它费用','总利润',
'狸车分润','合伙人分润','时间'];
$row['month_str'] = date('Y-m',strtotime("{$row['year']}-{$row['month']}"));
$row['total_need'] = $row['rent'] + $row['wat_ele'] + $row['manager_wage'] + $row['employee_wage'] + $row['commission'] + $row['price_trucking'];
$row['price_ml'] = $row['price_total'] - $row['total_need'];
$other_price = '';
$other_json = json_decode($row['price_other'],true);
if($other_json){
foreach($other_json as $key=>$val){
$type_cn = $type_arr[$val['type']];
$other_price .= $val['name'].$val['money']."({$type_cn})\n";
}
}
$sheet_data[] = [
$biz['biz_name'],
$row['profix_car'],
$row['profix_car_after'],
$row['price_all'],
$row['rent'],
$row['wat_ele'],
$row['manager_wage'],
$row['employee_wage'],
$row['commission'],
$row['price_trucking'],
$other_price,
$row['price_ml'],
$row['profix_liche'],
$row['profix_partner']+$row['profix_partner_oflow'],
$row['month_str']
];
}
$t1 = 'lc_biz_settle';
$t2 = 'lc_receiver_orders_v2';
$where = [
"{$t1}.biz_id" => $biz_id,
"{$t1}.year" => $year,
"{$t1}.month" => $month
];
$orderby = "$t1.id desc";
$select = "$t1.*,$t2.sid,$t2.name,$t2.mobile,$t2.s_id,$t2.v_id,$t2.brand_id,$t2.cor_id,$t2.item_id";
$all_rows = $this->biz_settle_model->selectOrders($where, $orderby, 0, 0,0, $select);
$sheet_data2 = [];
if($all_rows){
$sheet_data2[] = ['门店','订单信息','品牌车型','车架号','单车利润','保险利润','贷款利润','挂牌利润','水平业务合计','拖车费','时间'];
$s_ids = array_unique(array_filter(array_column($all_rows,'s_id')));
$cor_ids = array_unique(array_filter(array_column($all_rows,'cor_id')));
$v_ids = array_unique(array_filter(array_column($all_rows,'v_id')));
$attr_ids = array_merge($cor_ids,$v_ids);
$item_ids = array_unique(array_filter(array_column($all_rows,'item_id')));
//获取品牌map
$where_brand = array('status > -1' => null);
$map_brand = $this->auto_brand_model->map('id', 'name', $where_brand, 'id desc', 0 , 0, 'id, name');
//获取车系列表
$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');
}
$map_item = [];
if($item_ids){
$str_item_ids = implode(',',$item_ids);
$where_item = ["id in ({$str_item_ids})" => null];
$map_item = $this->items_model->map('id', 'vin', $where_item, '', 0, 0, 'id,vin');
}
foreach($all_rows as $v){
$title = "{$map_brand[$v['brand_id']]} {$map_sery[$v['s_id']]} {$map_attr[$v['v_id']]} {$map_attr[$v['cor_id']]}";
$vin = $map_item[$v['item_id']];
$month_str = date('Y-m',strtotime("{$v['year']}-{$v['month']}"));
$sheet_data2[] = array(
$biz['biz_name'],
"{$v['name']} {$v['mobile']}",
$title,
$vin,
$v['profix_car'],
$v['profix_insure'],
$v['profix_loan'],
$v['profix_carno'],
$v['profix_insure']+$v['profix_loan']+$v['profix_carno'],
$v['price_trucking'],
$month_str,
);
}
}
$cells = array('A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$obpe = new PHPExcel();
if($sheet_data){
$obpe->setactivesheetindex(0);
foreach($sheet_data as $key=>$val){
foreach($val as $k2=>$v2){
$cell = $cells[$k2];
$k = $key+1;
$obpe->getactivesheet()->setcellvalue("{$cell}{$k}", $v2);
}
}
}
if($sheet_data2){
//创建一个新的工作空间(sheet)
$obpe->createSheet();
$obpe->setactivesheetindex(1);
foreach($sheet_data2 as $key=>$val){
foreach($val as $k2=>$v2){
$cell = $cells[$k2];
$k = $key+1;
$obpe->getactivesheet()->setcellvalue("{$cell}{$k}", $v2);
}
}
}
$filename = $biz['biz_name']."_{$year}{$month}月_结算表";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header('Content-Disposition:attachment;filename='. $filename .'.xlsx');
header("Content-Transfer-Encoding:binary");
$writer = PHPExcel_IOFactory::createWriter($obpe, 'Excel2007');
$writer->save('php://output');
}
//统计合计
public function lists_static(){
$params = $this->input->get();
$where = [];
if($params['year']){
$where['year'] = $params['year'];
}elseif(!isset($params['year'])){
$where['year'] = $params['year'] = date('Y');
}
if($params['month']){
$where['month'] = $params['month'];
}elseif(!isset($params['month'])){
$where['month'] = $params['month'] = intval(date('m',strtotime("-1 month")));
}
if($params['id']){
$where['biz_id'] = $params['id'];
}
$page = $params['page'];
$page = !$page ? 1 : $page;
$size = $params['size'];
$size = !$size ? 20 : $size;
$total = $this->biz_settle_static_model->count($where);
$lists = array();
if($total){
$orderby = 'id desc';
$select = '*';
$rows = $this->biz_settle_static_model->select($where, $orderby, $page, $size, $select);
if($rows){
$biz_ids = array_unique(array_column($rows,'biz_id'));
$map_biz = [];
if($biz_ids){
$biz_ids = implode(',',$biz_ids);
$where_biz = ["id in ({$biz_ids})" => null];
$map_biz = $this->biz_model->map('id', 'biz_name', $where_biz, '', 0, 0, 'id,biz_name');
}
//属性按'车型-车身颜色-内饰颜色'排序
foreach($rows as $v){
$temp = $v;
$temp['biz_name'] = $map_biz[$v['biz_id']];
$temp['month_str'] = date('Y-m',strtotime("{$v['year']}-{$v['month']}"));
$temp['price_other'] = $v['price_other'] ? json_decode($v['price_other']) : [];
$temp['total_need'] = $v['rent'] + $v['wat_ele'] + $v['manager_wage'] + $v['employee_wage'] + $v['commission'] + $v['price_trucking'];
$temp['price_ml'] = $v['price_total'] - $temp['total_need'];
$temp['profix_partner'] = $v['profix_partner'] + $v['profix_partner_oflow'];
$temp['money_json'] = json_decode($v['money_json'],true);
$temp['price_all_after'] = sprintf("%.2f",$v['price_all']/1.13);
$lists[] = $temp;
}
}
}
$this->data['params'] = $params;
$this->data['lists'] = $lists;
$this->data['yearAry'] = $this->auto_business_model->year();
$this->data['monthAry'] = $this->auto_business_model->month();
$this->data['type_arr'] = $this->biz_settle_static_model->other_price_type();
$this->data['pager'] = array('count' => ceil($total / $size), 'curr' => $page,'totle'=>$total);
$this->data['_title'] = '商家结算管理';
$view = $params['_biz_type']==1 ? 'biz/settle/lists_static_brand' : 'biz/settle/lists_static';
$this->show_view($view,true);
}
//重新统计
public function edit_static(){
$id = $this->input->post('id');
$type = $this->input->post('type');
$row = $this->biz_settle_static_model->get(['id'=>$id]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
if($type){ //品牌
$res = $this->settle_entity->brand_static($row['id']);
if($res['code']){
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
}else{
return $this->show_json(SYS_CODE_FAIL, '操作失败');
}
}else{ //合伙人
$res = $this->settle_entity->re_static($row['id']);
if($res['code']){
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
}else{
return $this->show_json(SYS_CODE_FAIL, '操作失败');
}
}
}
public function add_price(){
$id = $this->input->get_post('id');
$row = $this->biz_settle_static_model->get(['id'=>$id]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
if($this->input->method()=='post'){
$lists = $this->input->post('lists');
if(!is_array($lists)){
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$price_other = [];
foreach($lists as $key=>$val){
if($val['money']){
$price_other[] = [
'name' => $val['name'],
'money' => $val['money'],
'type' => $val['type'] ? $val['type'] : 0
];
}
}
$up_data['price_other'] = json_encode($price_other,JSON_UNESCAPED_UNICODE);
$this->biz_settle_static_model->update($up_data,['id'=>$id]);
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
}
$lists = $row['price_other'] ? json_decode($row['price_other']) : [];
$this->data['id'] = $id;
$this->data['lists'] = $lists;
$this->data['type_arr'] = $this->biz_settle_static_model->other_price_type();
$this->show_view('biz/settle/add');
}
//更新品牌结算
public function edit_js(){
$params = $this->input->post();
$where = [
'biz_id' => $params['biz_id'],
'year' => $params['year'],
'month' => $params['month']
];
$rows = $this->biz_settle_model->select($where,'id desc');
if($rows){
$order_ids = implode(',',array_column($rows,'o_id'));
$order_rows = [];
if($order_ids){
$o_where = [
"id in ({$order_ids})" => null
];
$order_rows = $this->receiver_orders_v2_model->map('id','',$o_where,'','','');
}
foreach ($rows as $key => $val) {
$order = $order_rows[$val['o_id']][0];
if(!$order){
continue;
}
$info_json = json_decode($order['info_json'],true);
$money_json = json_decode($order['money_json'],true);
$bill_time_month = date('Y-m-d',strtotime($order['bill_time']));
$settle_money_json = [];
$settle_money_json['in'] = [ //收入
'profix_car' => 0, //整车
'srv_price' => $this->orders_v2_entity->order_srv_money($order['id']), //服务费
'commission' => 0, //佣金
];
$settle_money_json['out'] = [ //成本
'apply_price' => 0, //申请成本
'fine_price' => 0, //赠送精品成本
];
//获取创建订单时商务政策
$where = [
'id' => $info_json['business_id'],
];
$b_row_one = $this->auto_business_model->get($where);
$settle_money_json['in']['profix_car'] = $b_row_one['profix_car'] ? $b_row_one['profix_car']-$money_json['price_discount'] : 0;
//挂牌利润 = 实收 - 成本
$profix_carno = 0;
if($money_json['fee_carno']>0){
$where = [
'biz_id' => $order['biz_id'],
'type' => 1,
'status' => 1,
's_effect_time>=' => date('Y-m-01',strtotime($order['bill_time'])),
's_effect_time<=' => date('Y-m-t',strtotime($order['bill_time'])),
];
$free_row = $this->biz_settle_srv_model->get($where);
if(!$free_row){
$free_row = $this->biz_settle_srv_model->get(['biz_id'=>$order['biz_id'],'is_def'=>1,'status'=>1,'type'=>1]);
}
$free_jsondata = json_decode($free_row['jsondata'],true);
$cb_fee_carno = $free_jsondata['price'] ? $free_jsondata['price'] : 0;
$profix_carno = $money_json['fee_carno'] - $cb_fee_carno;
}
//保险利润 = 金额(是否含税) * 返点百分比(保险类型):保险生效日
$data_row = $this->receiver_order_datas_model->get(['o_id'=>$order['id']]);
$insurance_img = json_decode($data_row['insurance_img'],true);
$business_img = json_decode($data_row['business_img'],true);
$profix_insuer_ins = 0;
if($insurance_img){
//强险
$time = strtotime($insurance_img['date']);
$where = [
'biz_id' => $order['biz_id'],
'title' => $insurance_img['product'],
'type' => 2,
"json_extract(jsondata, '$.type') = '2'" => null,
"json_extract(jsondata, '$.s_time') >= '{$time}'" => null,
"json_extract(jsondata, '$.e_time') <= '{$time}'" => null
];
$fd_row = $this->biz_settle_srv_model->get($where);
if(!$fd_row){
$where = [
'biz_id' => $order['biz_id'],
'title' => $insurance_img['product'],
'type' => 2,
'is_def' => 1,
"json_extract(jsondata, '$.type') = '2'" => null,
];
$fd_row = $this->biz_settle_srv_model->get($where);
}
$fd_jsondata = json_decode($fd_row['jsondata'],true);
$qx_fd = $fd_jsondata['rebate']/100;
$profix_insuer_ins = floatval($insurance_img['price']) * $qx_fd;
}
$profix_insuer_bis = 0;
if($business_img){
//商业险
$time = strtotime($business_img['date']);
$where = [
'biz_id' => $order['biz_id'],
'title' => $business_img['product'],
'type' => 2,
"json_extract(jsondata, '$.type') = '1'" => null,
"json_extract(jsondata, '$.s_time') >= '{$time}'" => null,
"json_extract(jsondata, '$.e_time') <= '{$time}'" => null
];
$bis_fd_row = $this->biz_settle_srv_model->get($where);
if(!$bis_fd_row){
$where = [
'biz_id' => $order['biz_id'],
'title' => $business_img['product'],
'type' => 2,
'is_def' => 1,
"json_extract(jsondata, '$.type') = '1'" => null,
];
$bis_fd_row = $this->biz_settle_srv_model->get($where);
}
$bis_fd_jsondata = json_decode($bis_fd_row['jsondata'],true);
$bis_fd = $bis_fd_jsondata['rebate']/100;
$profix_insuer_bis = floatval($business_img['price'])*$bis_fd;
}
$profix_insuer = $profix_insuer_ins + $profix_insuer_bis;
//贷款利润 = 手续费 + 贷款金额 * 返点(对应产品)
// $profix_loan = floatval($money_json['price_finance']);
//贷款佣金 = 贷款金额 * 返点(对应产品)
$profix_loan = 0;
if($money_json['price_loan']>=0){
$loan_row = $this->order_loans_model->get(['o_id'=>$order['id']]);
$finance_id = $order['finance_id'];
$finance_num = $loan_row['num'] ? $loan_row['num'] : 0;
$where = [
'biz_id' => $order['biz_id'],
'type' => 3,
's_effect_time' => $bill_time_month,
"json_extract(jsondata, '$.finance_id') = '{$finance_id}'" => null,
"json_extract(jsondata, '$.finance_num') = '{$finance_num}'" => null,
];
$fd_row = $this->biz_settle_srv_model->get($where);
if(!$fd_row){
$fd_row = $this->biz_settle_srv_model->get(['biz_id'=>$order['biz_id'],'is_def'=>1,'status'=>1,'type'=>3]);
}
$fd_jsondata = json_decode($fd_row['jsondata'],true);
$loan_fd = $fd_jsondata['rebate'] ? $fd_jsondata['rebate']/100:0;
$profix_loan = $money_json['price_loan']*$loan_fd;
//获取贷款手续费
$srv_loan = 0;
$srv_json = json_decode($order['srv_ids'],true);
if($srv_json){
foreach ($srv_json as $v2) {
if($v2['key']=='price_finance'){
$srv_loan = $v2['price'];
break;
}
}
}
$profix_loan += $srv_loan;
}
$settle_money_json['profix_insuer_ins'] = $profix_insuer_ins;
$settle_money_json['profix_insuer_bis'] = $profix_insuer_bis;
$settle_money_json['in']['commission'] = $profix_loan+$profix_insuer;
//精品成本(赠送的也要算)
$profix_fine = 0;
$fines = json_decode($order['fines'],true);
$fines_ids = array_column($fines,'id');
if($fines){
$fines_ids = implode(',',$fines_ids);
$where = [
"id in ({$fines_ids})" => null
];
$fines_ids && $cb_sum = $this->receiver_fine_model->sum('price',$where);
$cb = $cb_sum['price'] ? $cb_sum['price'] : 0; //成本
$profix_fine = $cb;
}
$settle_money_json['out']['biz_price'] = $profix_fine;
$add_data = [
'profix_car' => $settle_money_json['in']['profix_car'],
'profix_insure' => $profix_insuer,
'profix_loan' => $profix_loan,
'profix_carno' => $profix_carno,
'profix_fine' => $money_json['price_fine_select'] - $profix_fine,
'money_json' => json_encode($settle_money_json,JSON_UNESCAPED_UNICODE),
];
if($money_json['price_car']>$b_row_one['price_floor']){
$add_data['oflow_profix_car'] = $money_json['price_car'] - $b_row_one['price_floor'];
}
$this->biz_settle_model->update($add_data,['id'=>$val['id']]);
}
$this->settle_entity->brand_static('',$params['biz_id'],$params['year'],$params['month']);
}
return $this->show_json(SYS_CODE_SUCCESS, '更新完成!');
}
//更新合伙结算列表
public function edit_settle(){
$params = $this->input->post();
$where = [
'biz_id' => $params['biz_id'],
'year' => $params['year'],
'month' => $params['month']
];
$rows = $this->biz_settle_model->select($where,'id desc');
if($rows){
$order_ids = implode(',',array_column($rows,'o_id'));
$order_rows = [];
if($order_ids){
$o_where = [
"id in ({$order_ids})" => null
];
$order_rows = $this->receiver_orders_v2_model->map('id','',$o_where,'','','');
}
foreach ($rows as $key => $val) {
$order = $order_rows[$val['o_id']][0];
if(!$order){
continue;
}
$info_json = json_decode($order['info_json'],true);
$money_json = json_decode($order['money_json'],true);
//获取创建订单时商务政策
$where = [
'id' => $info_json['business_id'],
];
$b_row_one = $this->auto_business_model->get($where);
//获取开票日期商务政策
$b_where = [
'city_id' => $order['city_id'],
'brand_id' => $order['brand_id'],
's_id' => $order['s_id'],
'v_id' => $order['v_id'],
'if_effect' => 1,
];
$b_row_two = $this->auto_business_model->select($b_where,'id desc',1,1);
$b_row_two = $b_row_two[0];
$truck_row = $this->biz_trucking_model->get(['auto_b_id'=>$order['brand_id'],'biz_id'=>$order['biz_id'],'status'=>1]);
$price_trucking = $truck_row['money'] ? $truck_row['money'] : 0;
$add_data = [
'profix_car' => $b_row_one['profix_car'] ? $b_row_one['profix_car'] : 0,
'profix_insure' => $b_row_two['profix_insure'] ? $b_row_two['profix_insure'] : 0,
'profix_loan' => $b_row_two['profix_loan'] ? $b_row_two['profix_loan'] : 0,
'profix_carno' => $b_row_two['profix_carno'] ? $b_row_two['profix_carno'] : 0,
'price_trucking' => $price_trucking,
];
if($money_json['price_car']>$b_row_one['price_floor']){
$add_data['oflow_profix_car'] = $money_json['price_car'] - $b_row_one['price_floor'];
}
$this->biz_settle_model->update($add_data,['id'=>$val['id']]);
}
$this->settle_entity->re_static('',$params['biz_id'],$params['year'],$params['month']);
}
return $this->show_json(SYS_CODE_SUCCESS, '更新完成!');
}
}