From 9ea191e6935de8497899a1ff7643165dc5ee8b94 Mon Sep 17 00:00:00 2001 From: lccsw <805383944@qq.com> Date: Wed, 24 Aug 2022 16:10:41 +0800 Subject: [PATCH] add-admin-re_settle --- admin/controllers/biz/Settle.php | 320 +++++++++++++++--- admin/views/biz/settle/lists.php | 5 + admin/views/biz/settle/lists_brand.php | 5 + admin/views/biz/settle/lists_static_brand.php | 10 +- api/controllers/plan/Biz.php | 2 +- common/libraries/receiver/Settle_entity.php | 160 +++++++++ 6 files changed, 442 insertions(+), 60 deletions(-) create mode 100644 common/libraries/receiver/Settle_entity.php diff --git a/admin/controllers/biz/Settle.php b/admin/controllers/biz/Settle.php index df55f6c0..595e1991 100644 --- a/admin/controllers/biz/Settle.php +++ b/admin/controllers/biz/Settle.php @@ -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, '更新完成!'); + } } diff --git a/admin/views/biz/settle/lists.php b/admin/views/biz/settle/lists.php index 02912452..462f0664 100644 --- a/admin/views/biz/settle/lists.php +++ b/admin/views/biz/settle/lists.php @@ -43,6 +43,11 @@
+ + 更新结算 +
diff --git a/admin/views/biz/settle/lists_brand.php b/admin/views/biz/settle/lists_brand.php index 3a89a942..e1e9d912 100644 --- a/admin/views/biz/settle/lists_brand.php +++ b/admin/views/biz/settle/lists_brand.php @@ -44,6 +44,11 @@ + + 更新结算 + diff --git a/admin/views/biz/settle/lists_static_brand.php b/admin/views/biz/settle/lists_static_brand.php index 791f7325..1fef2f01 100644 --- a/admin/views/biz/settle/lists_static_brand.php +++ b/admin/views/biz/settle/lists_static_brand.php @@ -58,7 +58,7 @@ {{v.profix_car_after}} {{v.price_all}} -