add-admin-re_settle
This commit is contained in:
@@ -15,12 +15,18 @@ class Settle extends HD_Controller
|
||||
|
||||
$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()
|
||||
@@ -402,65 +408,26 @@ class Settle extends HD_Controller
|
||||
//重新统计
|
||||
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, '参数错误!');
|
||||
}
|
||||
$all_other = 0; //共同承担其它费用
|
||||
$liche_other = 0; //狸车承担其它费用
|
||||
$partner_other = 0; //合伙人承担其它费用
|
||||
$price_other = json_decode($row['price_other'],true);
|
||||
if($price_other){
|
||||
foreach($price_other as $item){
|
||||
if($item['type']==2){
|
||||
$partner_other += $item['money'];
|
||||
}elseif($item['type']==1){
|
||||
$liche_other += $item['money'];
|
||||
}else{
|
||||
$all_other += $item['money'];
|
||||
}
|
||||
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, '操作失败');
|
||||
}
|
||||
}
|
||||
$car_total = $this->biz_settle_model->count(['stic_id'=>$row['id']]);
|
||||
$biz_info = $this->biz_info_model->get(['biz_id'=>$row['biz_id']]);
|
||||
$partner_rate = $biz_info['rate']/100;
|
||||
$liche_rate = (100-$biz_info['rate'])/100;
|
||||
$update = [
|
||||
'rent' => $biz_info['rent'],
|
||||
'wat_ele' => $biz_info['wat_ele'],
|
||||
'manager_wage' => $biz_info['manager_wage'],
|
||||
'commission' => $biz_info['commission']*$car_total,
|
||||
];
|
||||
$employee_wage = $biz_info['num'] ? ceil($car_total/$biz_info['num']) : 0;
|
||||
$update['employee_wage'] = $employee_wage*$biz_info['employee_wage'];
|
||||
|
||||
$settle_rows = $this->biz_settle_model->select(['stic_id'=>$row['id']],'id asc',0,0,'id,o_id');
|
||||
if(is_array($settle_rows)){
|
||||
$o_id_str = implode(',',array_column($settle_rows,'o_id'));
|
||||
$order_rows = [];
|
||||
if($o_id_str){
|
||||
$where = [
|
||||
"id in ($o_id_str)" => null
|
||||
];
|
||||
$order_rows = $this->receiver_orders_v2_model->map('id','brand_id',$where,0,0,'id,brand_id');
|
||||
}
|
||||
foreach($settle_rows as $val){
|
||||
$auto_b_id = $order_rows[$val['o_id']] ? $order_rows[$val['o_id']] : 0;
|
||||
$truck_row = $this->biz_trucking_model->get(['biz_id'=>$row['biz_id'],'auto_b_id'=>$auto_b_id,'status'=>1]);
|
||||
$price = $truck_row ? $truck_row['money'] : 0;
|
||||
$this->biz_settle_model->update(['price_trucking'=>$price],['id'=>$val['id']]);
|
||||
}
|
||||
}
|
||||
$truck_sum = $this->biz_settle_model->sum('price_trucking',['stic_id' => $row['id']]);
|
||||
$update['price_trucking'] = $truck_sum['price_trucking'];
|
||||
|
||||
$price_need = $update['rent'] + $update['wat_ele'] + $update['employee_wage'] + $update['manager_wage'] + $update['commission'] + $update['price_trucking'];
|
||||
$price_ml = $row['price_total'] - $price_need - $all_other;
|
||||
$update['profix_liche'] = $price_ml*$liche_rate-$liche_other;
|
||||
$update['profix_partner'] = $price_ml*$partner_rate-$partner_other;
|
||||
$this->biz_settle_static_model->update($update,['id'=>$row['id']]);
|
||||
|
||||
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
|
||||
}
|
||||
|
||||
public function add_price(){
|
||||
@@ -494,4 +461,251 @@ class Settle extends HD_Controller
|
||||
$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, '更新完成!');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,11 @@
|
||||
<div class="am-form-group fl ml20">
|
||||
<input type="hidden" value="<?=$params['biz_id']?>" name="biz_id">
|
||||
<button type="submit" class="am-btn am-btn-sm am-btn-success w100">搜索</button>
|
||||
<a href="javascript:;" class="am-btn am-btn-sm am-btn-success w100" data-ajax="post"
|
||||
:data-action="'/biz/settle/edit_brand?biz_id='+params.biz_id" :data-params-year="params.year" :data-params-month="params.month"
|
||||
:data-params-biz_id="params.biz_id" >
|
||||
更新结算
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -44,6 +44,11 @@
|
||||
<input type="hidden" value="<?=$params['biz_id']?>" name="biz_id">
|
||||
<input type="hidden" value="<?=$params['_biz_type']?>" name="_biz_type">
|
||||
<button type="submit" class="am-btn am-btn-sm am-btn-success w100">搜索</button>
|
||||
<a href="javascript:;" class="am-btn am-btn-sm am-btn-success w100" data-ajax="post"
|
||||
:data-action="'/biz/settle/edit_js?biz_id='+params.biz_id" :data-params-year="params.year" :data-params-month="params.month"
|
||||
:data-params-biz_id="params.biz_id" >
|
||||
更新结算
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
<td>{{v.profix_car_after}}</td>
|
||||
<td>{{v.price_all}}</td>
|
||||
<td>
|
||||
<template v-if="v.money_json.biz_price">
|
||||
<template v-if="v.money_json && v.money_json.biz_price">
|
||||
<template v-for="(v2,i2) in v.money_json.biz_price_list">
|
||||
{{i2}}:{{v2}}<br>
|
||||
</template>
|
||||
@@ -79,11 +79,9 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="10" class="align-r">
|
||||
<a class="am-btn am-btn-primary am-btn-xs" :data-open="'biz/settle?_biz_type=1&biz_id='+v.biz_id+'&month='+v.month" href="javascript:;">查看明细</a>
|
||||
<a class="am-btn am-btn-primary am-btn-xs" :data-modal="'biz/settle/add_price?id='+v.id" data-title="新增费用" href="javascript:;">新增费用</a>
|
||||
<!--
|
||||
<a class="am-btn am-btn-primary am-btn-xs" data-ajax="post" data-action="biz/settle/edit_static" :data-params-id="v.id" href="javascript:;">重新结算</a>
|
||||
-->
|
||||
<a class="am-btn am-btn-primary am-btn-xs" :data-open="'/biz/settle?_biz_type=1&biz_id='+v.biz_id+'&month='+v.month" href="javascript:;">查看明细</a>
|
||||
<a class="am-btn am-btn-primary am-btn-xs" :data-modal="'/biz/settle/add_price?id='+v.id" data-title="新增费用" href="javascript:;">新增费用</a>
|
||||
<a class="am-btn am-btn-primary am-btn-xs" data-ajax="post" data-action="biz/settle/edit_static" :data-params-id="v.id" data-params-type="1" href="javascript:;">重新结算</a>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
|
||||
@@ -473,7 +473,7 @@ class Biz extends HD_Controller
|
||||
];
|
||||
$data['price_total'] = $val['price_all']+$data['profix_car_after'];
|
||||
$biz_info = $this->biz_info_model->get(['biz_id'=>$val['biz_id']]);
|
||||
$price_need = $data['price_total'] = $money_json['biz_price'];
|
||||
$price_need = $data['price_total'] + $money_json['biz_price'];
|
||||
$partner_rate = $biz_info['rate']/100;
|
||||
$liche_rate = (100-$biz_info['rate'])/100;
|
||||
$data['profix_liche'] = $price_need*$liche_rate;
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
class Settle_entity{
|
||||
private $ci;
|
||||
public function __construct(){
|
||||
$this->ci = & get_instance();
|
||||
$this->ci->load->model('biz/biz_settle_model');
|
||||
$this->ci->load->model('biz/biz_settle_static_model');
|
||||
$this->ci->load->model('biz/biz_settle_price_model');
|
||||
$this->ci->load->model('biz/biz_info_model');
|
||||
$this->ci->load->model('biz/biz_trucking_model');
|
||||
$this->ci->load->model('receiver/order/receiver_orders_v2_model');
|
||||
}
|
||||
|
||||
//品牌更新统计
|
||||
public function brand_static($static_id,$biz_id,$year,$month){
|
||||
if($static_id){
|
||||
$static_row = $this->ci->biz_settle_static_model->get(['id'=>$static_id]);
|
||||
}else{
|
||||
$where = [
|
||||
'biz_id' => $biz_id,
|
||||
'year' => $year,
|
||||
'month' => $month
|
||||
];
|
||||
$static_row = $this->ci->biz_settle_static_model->get($where);
|
||||
}
|
||||
if(!$static_row){
|
||||
return ['code'=>0,'msg'=>'统计数据不存在'];
|
||||
}
|
||||
$all_other = 0; //共同承担其它费用
|
||||
$liche_other = 0; //狸车承担其它费用
|
||||
$partner_other = 0; //品牌承担其它费用
|
||||
$price_other = json_decode($static_row['price_other'],true);
|
||||
if($price_other){
|
||||
foreach($price_other as $item){
|
||||
if($item['type']==2){
|
||||
$partner_other += $item['money'];
|
||||
}elseif($item['type']==1){
|
||||
$liche_other += $item['money'];
|
||||
}else{
|
||||
$all_other += $item['money'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$biz_price = 0;//门店成本
|
||||
$biz_price_list = [];
|
||||
$p_where = [
|
||||
'biz_id' => $biz_id,
|
||||
'status' => 1,
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
];
|
||||
$price_row = $this->ci->biz_settle_price_model->get($p_where);
|
||||
if($price_row){
|
||||
$biz_price = $this->ci->biz_settle_price_model->sum_jsondata($price_row['money_json']);
|
||||
$biz_price_list = $this->ci->biz_settle_price_model->get_jsondata($price_row['money_json']);
|
||||
}
|
||||
$add_money_json = [ //成本
|
||||
'biz_price' => $biz_price, //门店成本
|
||||
'biz_price_list' => $biz_price_list
|
||||
];
|
||||
$data['money_json'] = json_encode($add_money_json,JSON_UNESCAPED_UNICODE);
|
||||
$sum_profix_car = $this->ci->biz_settle_model->sum('profix_car',['stic_id'=>$static_row['id']]);
|
||||
$sum_profix_insure = $this->ci->biz_settle_model->sum('profix_insure',['stic_id'=>$static_row['id']]);
|
||||
$sum_profix_loan = $this->ci->biz_settle_model->sum('profix_loan',['stic_id'=>$static_row['id']]);
|
||||
$sum_profix_carno = $this->ci->biz_settle_model->sum('profix_carno',['stic_id'=>$static_row['id']]);
|
||||
$sum_profix_fine = $this->ci->biz_settle_model->sum('profix_fine',['stic_id'=>$static_row['id']]);
|
||||
$data['profix_car'] = $sum_profix_car['profix_car'];
|
||||
$data['price_all'] = $sum_profix_insure['profix_insure']+$sum_profix_loan['profix_loan']+$sum_profix_carno['profix_carno']+$sum_profix_fine['profix_fine'];
|
||||
$data['profix_car_after'] = sprintf("%.2f",$data['profix_car']/1.13);
|
||||
$data['price_total'] = $data['price_all']+$data['profix_car_after'];
|
||||
//计算分润
|
||||
$biz_info = $this->ci->biz_info_model->get(['biz_id'=>$static_row['biz_id']]);
|
||||
$price_need = $data['price_total'] + $biz_price - $all_other;
|
||||
$partner_rate = $biz_info['rate']/100;
|
||||
$liche_rate = (100-$biz_info['rate'])/100;
|
||||
$data['profix_liche'] = $price_need*$liche_rate-$liche_other;
|
||||
$data['profix_partner'] = $price_need*$partner_rate-$partner_other;
|
||||
$res = $this->ci->biz_settle_static_model->update($data,['id'=>$static_row['id']]);
|
||||
if($res){
|
||||
return ['code'=>1,'msg'=>'更新成功'];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'更新失败'];
|
||||
}
|
||||
}
|
||||
//合伙人更新统计
|
||||
public function re_static($static_id,$biz_id,$year,$month){
|
||||
if($static_id){
|
||||
$row = $this->ci->biz_settle_static_model->get(['id'=>$static_id]);
|
||||
}else{
|
||||
$where = [
|
||||
'biz_id' => $biz_id,
|
||||
'year' => $year,
|
||||
'month' => $month
|
||||
];
|
||||
$row = $this->ci->biz_settle_static_model->get($where);
|
||||
}
|
||||
if(!$row){
|
||||
return ['code'=>0,'msg'=>'统计数据不存在'];
|
||||
}
|
||||
$all_other = 0; //共同承担其它费用
|
||||
$liche_other = 0; //狸车承担其它费用
|
||||
$partner_other = 0; //合伙人承担其它费用
|
||||
$price_other = json_decode($row['price_other'],true);
|
||||
if($price_other){
|
||||
foreach($price_other as $item){
|
||||
if($item['type']==2){
|
||||
$partner_other += $item['money'];
|
||||
}elseif($item['type']==1){
|
||||
$liche_other += $item['money'];
|
||||
}else{
|
||||
$all_other += $item['money'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$car_total = $this->ci->biz_settle_model->count(['stic_id'=>$row['id']]);
|
||||
$biz_info = $this->ci->biz_info_model->get(['biz_id'=>$row['biz_id']]);
|
||||
$partner_rate = $biz_info['rate']/100;
|
||||
$liche_rate = (100-$biz_info['rate'])/100;
|
||||
$update = [
|
||||
'rent' => $biz_info['rent'],
|
||||
'wat_ele' => $biz_info['wat_ele'],
|
||||
'manager_wage' => $biz_info['manager_wage'],
|
||||
'commission' => $biz_info['commission']*$car_total,
|
||||
];
|
||||
$employee_wage = $biz_info['num'] ? ceil($car_total/$biz_info['num']) : 0;
|
||||
$update['employee_wage'] = $employee_wage*$biz_info['employee_wage'];
|
||||
|
||||
$settle_rows = $this->ci->biz_settle_model->select(['stic_id'=>$row['id']],'id asc',0,0,'id,o_id');
|
||||
if(is_array($settle_rows)){
|
||||
$o_id_str = implode(',',array_column($settle_rows,'o_id'));
|
||||
$order_rows = [];
|
||||
if($o_id_str){
|
||||
$where = [
|
||||
"id in ($o_id_str)" => null
|
||||
];
|
||||
$order_rows = $this->ci->receiver_orders_v2_model->map('id','brand_id',$where,0,0,'id,brand_id');
|
||||
}
|
||||
foreach($settle_rows as $val){
|
||||
$auto_b_id = $order_rows[$val['o_id']] ? $order_rows[$val['o_id']] : 0;
|
||||
$truck_row = $this->ci->biz_trucking_model->get(['biz_id'=>$row['biz_id'],'auto_b_id'=>$auto_b_id,'status'=>1]);
|
||||
$price = $truck_row ? $truck_row['money'] : 0;
|
||||
$this->ci->biz_settle_model->update(['price_trucking'=>$price],['id'=>$val['id']]);
|
||||
}
|
||||
}
|
||||
$truck_sum = $this->ci->biz_settle_model->sum('price_trucking',['stic_id' => $row['id']]);
|
||||
$update['price_trucking'] = $truck_sum['price_trucking'];
|
||||
|
||||
$price_need = $update['rent'] + $update['wat_ele'] + $update['employee_wage'] + $update['manager_wage'] + $update['commission'] + $update['price_trucking'];
|
||||
$price_ml = $row['price_total'] - $price_need - $all_other;
|
||||
$update['profix_liche'] = $price_ml*$liche_rate-$liche_other;
|
||||
$update['profix_partner'] = $price_ml*$partner_rate-$partner_other;
|
||||
$res = $this->ci->biz_settle_static_model->update($update,['id'=>$row['id']]);
|
||||
if($res){
|
||||
return ['code'=>1,'msg'=>'更新成功'];
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'更新失败'];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user