From cbe9ff63bf5d13697bb9f08a7ea37418b8399359 Mon Sep 17 00:00:00 2001 From: lccsw <805383944@qq.com> Date: Fri, 29 Jul 2022 15:02:39 +0800 Subject: [PATCH] edit-order-settle_brand --- admin/controllers/biz/Seprice.php | 174 ++++++++++++++++ admin/controllers/biz/Settle.php | 11 +- admin/views/biz/seprice/get.php | 140 +++++++++++++ admin/views/biz/seprice/lists.php | 111 ++++++++++ admin/views/biz/settle/lists_static_brand.php | 133 ++++++++++++ admin/views/biz/store/get_info.php | 8 +- admin/views/biz/store/lists.php | 8 +- api/controllers/plan/Biz.php | 193 +++++++++++++++--- common/models/biz/Biz_settle_price_model.php | 55 +++++ 9 files changed, 794 insertions(+), 39 deletions(-) create mode 100644 admin/controllers/biz/Seprice.php create mode 100644 admin/views/biz/seprice/get.php create mode 100755 admin/views/biz/seprice/lists.php create mode 100644 admin/views/biz/settle/lists_static_brand.php create mode 100644 common/models/biz/Biz_settle_price_model.php diff --git a/admin/controllers/biz/Seprice.php b/admin/controllers/biz/Seprice.php new file mode 100644 index 00000000..42325f35 --- /dev/null +++ b/admin/controllers/biz/Seprice.php @@ -0,0 +1,174 @@ +load->model('biz/biz_model'); + $this->load->model('biz/biz_settle_price_model'); + $this->load->model('auto/auto_business_model'); + } + + public function index() + { + $this->lists(); + } + + public function lists() + { + $params = $this->input->get(); + $page = $params['page'] ? $params['page'] : 1; + $size = $params['size'] ? $params['size'] : 50; + !strlen($params['status']) && $params['status'] = ''; + !strlen($params['year']) && $params['year'] = date('Y'); + !strlen($params['month']) && $params['month'] = ''; + $biz_row = $this->biz_model->get(['id'=>$params['biz_id']]); + if(!$biz_row){ + return $this->show_json(SYS_CODE_FAIL,'参数错误'); + } + + $where = [ + 'biz_id' => $biz_row['id'], + 'status>=' => 0, + 'year' => date('Y') + ]; + strlen($params['status']) && $where['status'] = $params['status']; + strlen($params['year']) && $where['year'] = $params['year']; + strlen($params['month']) && $where['month'] = $params['month']; + $lists = []; + $total = $this->biz_settle_price_model->count($where); + if($total){ + $rows = $this->biz_settle_price_model->select($where,'id desc',$page,$size); + foreach ($rows as $item) { + $temp = [ + 'id' => $item['id'], + 'money_json' => $this->biz_settle_price_model->get_jsondata($item['money_json']), + 'show_time' => "{$item['year']}-{$item['month']}", + 'status' => $item['status'], + 'status_cn' => $item['status'] ? '正常' : '禁用', + 'c_time' => date('Y-m-d H:i',$item['c_time']) + ]; + $lists[] = $temp; + } + } + $this->data['yearAry'] = $this->auto_business_model->year(); + $this->data['monthAry'] = $this->auto_business_model->month(); + $this->data['params'] = $params; + $this->data['lists'] = $lists; + $this->data['pager'] = array('count' => ceil($total / $size), 'curr' => $page,'totle'=>$total); + $this->data['_title'] = "{$biz_row['biz_name']}-费用管理"; + $this->show_view('biz/seprice/lists',true); + } + + public function get(){ + $params = $this->input->get(); + $row = $this->biz_settle_price_model->get(['id'=>$params['id']]); + $info = []; + if($row){ + $info['id'] = $row['id']; + $info['money_json'] = json_decode($row['money_json'],true); + $info['year'] = $row['year']; + $info['month'] = $row['month']; + $info['action'] = '/biz/seprice/edit'; + $biz_id = $params['biz_id']; + }else{ + $biz_row = $this->biz_model->get(['id'=>$params['biz_id']]); + if(!$biz_row){ + return $this->show_json(SYS_CODE_FAIL,'参数错误'); + } + $biz_id = $biz_row['id']; + $info['money_json'] = [ + 'rent' => '', + 'base_manager' => '', + 'base_employees' => '', + 'wat_ele' => '', + 'media' => '', + 'marketing' => '', + 'drive' => '', + 'commission' => '', + 'trucking' => '' + ]; + $info['year'] = date('Y'); + $info['month'] = intval(date('m')); + $info['action'] = '/biz/seprice/add'; + } + $info['biz_id'] = $biz_id; + $this->data['info'] = $info; + $this->data['yearAry'] = $this->auto_business_model->year(); + $this->data['monthAry'] = $this->auto_business_model->month(); + $this->show_view('biz/seprice/get'); + } + + public function add(){ + $info = $this->input->post('info'); + $biz_row = $this->biz_model->get(['id'=>$info['biz_id']]); + if(!$biz_row){ + return $this->show_json(SYS_CODE_FAIL,'参数错误'); + } + $data = [ + 'money_json' => json_encode($info['money_json'],JSON_UNESCAPED_UNICODE), + 'biz_id' => $info['biz_id'], + 'year' => $info['year'], + 'month' => $info['month'], + 'c_time' => time() + ]; + $res = $this->biz_settle_price_model->add($data); + if($res){ + return $this->show_json(SYS_CODE_SUCCESS,'保存成功'); + }else{ + return $this->show_json(SYS_CODE_FAIL,'保存失败'); + } + } + + public function edit(){ + $info = $this->input->post('info'); + $row = $this->biz_settle_price_model->get(['id'=>$info['id']]); + if(!$row){ + return $this->show_json(SYS_CODE_FAIL,'参数错误'); + } + $data = [ + 'money_json' => json_encode($info['money_json'],JSON_UNESCAPED_UNICODE), + 'year' => $info['year'], + 'month' => $info['month'], + ]; + $res = $this->biz_settle_price_model->update($data,['id'=>$info['id']]); + if($res){ + return $this->show_json(SYS_CODE_SUCCESS,'保存成功'); + }else{ + return $this->show_json(SYS_CODE_FAIL,'保存失败'); + } + } + + public function edit_status(){ + $id = $this->input->post('id'); + $value = $this->input->post('value'); + $row = $this->biz_settle_price_model->get(['id'=>$id]); + if(!$row){ + return $this->show_json(SYS_CODE_FAIL,'参数错误'); + } + $update = [ + 'status' => $value ? 0 : 1 + ]; + $res = $this->biz_settle_price_model->update($update,['id'=>$id]); + if($res){ + return $this->show_json(SYS_CODE_SUCCESS,'保存成功'); + }else{ + return $this->show_json(SYS_CODE_FAIL,'保存失败'); + } + } + public function del() + { + } + + public function batch() + { + + } + public function export(){ + + } + +} diff --git a/admin/controllers/biz/Settle.php b/admin/controllers/biz/Settle.php index bf48229d..76840cc9 100644 --- a/admin/controllers/biz/Settle.php +++ b/admin/controllers/biz/Settle.php @@ -5,11 +5,6 @@ require_once COMMPATH.'third_party/PHPExcel.php'; class Settle extends HD_Controller { - private $biz_type = [ - 1 => ['liche' => 0.25 , 'partner' => 0.75], - 2 => ['liche' => 0.35 , 'partner' => 0.65], - ]; - public function __construct() { parent::__construct(); @@ -26,6 +21,8 @@ class Settle extends HD_Controller $this->load->model('biz/biz_settle_static_model'); $this->load->model('biz/biz_info_model'); $this->load->model('biz/biz_trucking_model'); + $_biz_type = $this->input->get('_biz_type'); + $_SESSION['is_brand'] = $_biz_type==1 ? $_biz_type : ''; } public function index() @@ -370,6 +367,7 @@ class Settle extends HD_Controller $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); $lists[] = $temp; } } @@ -381,7 +379,8 @@ class Settle extends HD_Controller $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'] = '商家结算管理'; - $this->show_view('biz/settle/lists_static',true); + $view = $_SESSION['is_brand'] ? 'biz/settle/lists_static_brand' : 'biz/settle/lists_static'; + $this->show_view($view,true); } diff --git a/admin/views/biz/seprice/get.php b/admin/views/biz/seprice/get.php new file mode 100644 index 00000000..364cbe7a --- /dev/null +++ b/admin/views/biz/seprice/get.php @@ -0,0 +1,140 @@ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + +
+
+ +
+ +
+
+
+
+ diff --git a/admin/views/biz/seprice/lists.php b/admin/views/biz/seprice/lists.php new file mode 100755 index 00000000..92be62be --- /dev/null +++ b/admin/views/biz/seprice/lists.php @@ -0,0 +1,111 @@ +
+ +
+
共有条数据
+ + + + + + + + + + + + + + + + + + + + + +
ID费用明细有效月份状态创建时间操作
{{item.id}} + + {{item.show_time}}{{item.status_cn}}{{item.c_time}} + 编辑 + + +
+
+
+
+ +
+
+
+ diff --git a/admin/views/biz/settle/lists_static_brand.php b/admin/views/biz/settle/lists_static_brand.php new file mode 100644 index 00000000..c8d89b33 --- /dev/null +++ b/admin/views/biz/settle/lists_static_brand.php @@ -0,0 +1,133 @@ +
+
+
+
+ + + + + + + + + + + + + + + + + + + +
+ ID + 门店单车总毛利服务费佣金门店费用精品其它费用总利润分润时间
+
+
+
+ +
+
+
+ + diff --git a/admin/views/biz/store/get_info.php b/admin/views/biz/store/get_info.php index 3f0a9859..51402d20 100644 --- a/admin/views/biz/store/get_info.php +++ b/admin/views/biz/store/get_info.php @@ -1,5 +1,6 @@
+
- 合伙人:%     + + + :%     狸车:{{100-info.rate}}% (说明:有效值0~100,输入数值的百分比)
+
diff --git a/admin/views/biz/store/lists.php b/admin/views/biz/store/lists.php index 6d04eb5b..2d986da3 100755 --- a/admin/views/biz/store/lists.php +++ b/admin/views/biz/store/lists.php @@ -159,15 +159,19 @@ 精品配置 + 费用管理 + 水平业务配置 + class="am-btn am-btn-primary am-btn-xs">水平业务配置 + 基本信息 - 结算统计 load->model('biz/biz_settle_static_model'); $this->load->model('biz/biz_settle_srv_model'); $this->load->model('biz/biz_trucking_model'); + $this->load->model('biz/biz_settle_price_model'); $this->load->model('sys/sys_finance_model'); $this->load->library('receiver/orders_v2_entity'); @@ -182,6 +183,7 @@ class Biz extends HD_Controller //品牌店统计 public function settle_brand(){ + $id = $this->input->get('id'); $size = $this->input->get('size'); !$size && $size = 5; @@ -196,6 +198,7 @@ class Biz extends HD_Controller "$t2.id is null" => null, "$t3.type" => 1, ]; + $id && $where["{$t1}.id"] = $id; $this->db->from("$t1"); $this->db->join("$t2", "$t2.o_id=$t1.id",'left'); $this->db->join("$t3", "$t3.id=$t1.biz_id",'left'); @@ -209,31 +212,41 @@ class Biz extends HD_Controller foreach($rows as $key=>$val){ $info_json = json_decode($val['info_json'],true); $money_json = json_decode($val['money_json'],true); + $settle_money_json = []; + $settle_money_json['in'] = [ //收入 + 'profix_car' => 0, //整车 + 'srv_price' => $this->orders_v2_entity->order_srv_money($val['id']), //服务费 + 'commission' => 0, //佣金 + ]; + $settle_money_json['out'] = [ //成本 +// 'biz_price' => 0', //门店成本 + 'apply_price' => 0, //申请成本 + 'fine_price' => 0, //赠送精品成本 + ]; //获取创建订单时商务政策 $where = [ 'id' => $info_json['business_id'], ]; $b_row_one = $this->auto_business_model->get($where); - $truck_row = $this->biz_trucking_model->get(['auto_b_id'=>$val['brand_id'],'biz_id'=>$val['biz_id'],'status'=>1]); - $price_trucking = $truck_row['money'] ? $truck_row['money'] : 0; + $settle_money_json['in']['profix_car'] = $b_row_one['profix_car'] ? $b_row_one['profix_car'] : 0; //挂牌利润 = 实收 - 成本 - $profix_carno = 0; - if($money_json['fee_carno']>0){ - $where = [ - 'biz_id' => $val['biz_id'], - 'type' => 1, - 'status' => 1, - 's_effect_time>=' => date('Y-m-01',$val['c_time']), - 's_effect_time<=' => date('Y-m-t',$val['c_time']), - ]; - $free_row = $this->biz_settle_srv_model->get($where); - if(!$free_row){ - $free_row = $this->biz_settle_srv_model->get(['biz_id'=>$val['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; - } +// $profix_carno = 0; +// if($money_json['fee_carno']>0){ +// $where = [ +// 'biz_id' => $val['biz_id'], +// 'type' => 1, +// 'status' => 1, +// 's_effect_time>=' => date('Y-m-01',$val['c_time']), +// 's_effect_time<=' => date('Y-m-t',$val['c_time']), +// ]; +// $free_row = $this->biz_settle_srv_model->get($where); +// if(!$free_row){ +// $free_row = $this->biz_settle_srv_model->get(['biz_id'=>$val['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; +// } //保险利润 = 金额(是否含税) * 返点百分比(保险类型):保险生效日 $agent_row = $this->order_agents_model->get(['o_id'=>$val['id']]); $agent_json = json_decode($agent_row['jsondata'],true); @@ -259,7 +272,9 @@ class Biz extends HD_Controller $profix_insuer_bis = floatval($money_json['business_risk'])*$bis_fd; $profix_insuer = $profix_insuer_ins + $profix_insuer_bis; //贷款利润 = 手续费 + 贷款金额 * 返点(对应产品) - $profix_loan = floatval($money_json['price_finance']); +// $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'=>$val['id']]); $finance_id = $val['finance_id']; @@ -276,8 +291,9 @@ class Biz extends HD_Controller } $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; + $profix_loan = $money_json['price_loan']*$loan_fd; } + $settle_money_json['in']['commission'] = $profix_loan+$profix_insuer; //实收 - 成本(赠送的也要算) $profix_fine = 0; $fines = json_decode($val['fines'],true); @@ -289,21 +305,32 @@ class Biz extends HD_Controller ]; $fines_ids && $cb_sum = $this->receiver_fine_model->sum('price',$where); $cb = $cb_sum['price'] ? $cb_sum['price'] : 0; //成本 - $sh = 0; //实收 - foreach ($fines as $f_val) { - $sh += floatval($f_val['price']); - } - $profix_fine = $sh-$cb; +// $sh = 0; //实收 +// foreach ($fines as $f_val) { +// $sh += floatval($f_val['price']); +// } + $profix_fine = $cb; } + $settle_money_json['out']['biz_price'] = $profix_fine; +// $biz_price = 0;//门店成本 +// $p_where = [ +// 'biz_id' => $val['biz_id'], +// 'status' => 1, +// 'year' => date('Y',$val['c_time']), +// 'month' => date('m',$val['c_time']), +// ]; +// $price_row = $this->biz_settle_price_model->get($p_where); +// $price_row && $biz_price = $this->biz_settle_price_model->sum_jsondata($price_row['jsondata']); +// $settle_money_json['out']['biz_price'] = $biz_price; $add_data = [ 'biz_id' => $val['biz_id'], 'o_id' => $val['id'], - 'profix_car' => $b_row_one['profix_car'] ? $b_row_one['profix_car'] : 0, + 'profix_car' => $settle_money_json['in']['profix_car'], 'profix_insure' => $profix_insuer, 'profix_loan' => $profix_loan, - 'profix_carno' => $profix_carno, - 'price_trucking' => $price_trucking, - 'profix_fine' => $profix_fine, +// 'profix_carno' => $profix_carno, +// 'profix_fine' => $profix_fine, + 'money_json' => json_encode($settle_money_json,JSON_UNESCAPED_UNICODE), 'year' => date('Y'), 'month' => intval(date('m')), 'c_time' => time() @@ -318,4 +345,110 @@ class Biz extends HD_Controller } } + //统计前一个月利润 + public function merge_brand(){ + $size = $this->input->get('size'); + $page = 1; + !$size && $size = 5; + + $where = [ + "year" => date('Y',strtotime("last month")), + "month" => intval(date('m',strtotime('last day of - 1 months'))), + "stic_id" => 0 + ]; + $rows = $this->biz_settle_model->select($where,'id asc',$page,$size); + if($rows){ + foreach($rows as $key=>$val){ + $settle_money_json = json_decode($val['money_json'],true); + $where = [ + 'biz_id' => $val['biz_id'], + 'year' => $val['year'], + 'month' => $val['month'] + ]; + $static_row = $this->biz_settle_static_model->get($where); + $price_all = $val['profix_insure']+$val['profix_loan']+$val['profix_carno']; + if(!$static_row){ + $data = [ + 'biz_id' => $val['biz_id'], + 'profix_car' => $val['profix_car'], + 'year' => $val['year'], + 'month' => $val['month'], + 'c_time' => time() + ]; + $add_money_json['in'] = [ //收入 + 'profix_car' => $val['profix_car'], //整车 + 'srv_price' => $settle_money_json['srv_price'], //服务费 + 'commission' => $settle_money_json['commission'], //佣金 + ]; + $biz_price = 0;//门店成本 + $p_where = [ + 'biz_id' => $val['biz_id'], + 'status' => 1, + 'year' => date('Y',$val['year']), + 'month' => date('m',$val['month']), + ]; + $price_row = $this->biz_settle_price_model->get($p_where); + $price_row && $biz_price = $this->biz_settle_price_model->sum_jsondata($price_row['jsondata']); + $add_money_json['out'] = [ //成本 + 'biz_price' => $biz_price, //门店成本 + 'apply_price' => $settle_money_json['apply_price'], //申请成本 + 'fine_price' => $settle_money_json['fine_price'], //赠送精品成本 + ]; + $data['money_json'] = json_encode($add_money_json,JSON_UNESCAPED_UNICODE); + $stic_id = $this->biz_settle_static_model->add($data); + if($stic_id){ + $this->biz_settle_model->update(['stic_id'=>$stic_id],['id'=>$val['id']]); + } + }else{ + $static_money_json = json_decode($static_row['money_json'],true); + $data = [ + 'profix_car' => $static_row['profix_car'] + $val['profix_car'], + ]; + $out = $static_money_json['out']; + $in = $static_money_json['in']; + $add_money_json['in'] = [ //收入 + 'profix_car' => $val['profix_car'] + $in['profix_car'], //整车 + 'srv_price' => $settle_money_json['srv_price'] + $in['profix_car'], //服务费 + 'commission' => $settle_money_json['commission'] + $in['commission'], //佣金 + ]; + $add_money_json['out'] = [ //成本 + 'biz_price' => $out['biz_price'], //门店成本 + 'apply_price' => $settle_money_json['apply_price']+$out['apply_price'], //申请成本 + 'fine_price' => $settle_money_json['fine_price'] + $out['fine_price'], //赠送精品成本 + ]; + $data['money_json'] = json_encode($add_money_json,JSON_UNESCAPED_UNICODE); + $res = $this->biz_settle_static_model->update($data,['id'=>$static_row['id']]); + if($res){ + $this->biz_settle_model->update(['stic_id'=>$static_row['id']],['id'=>$val['id']]); + } + } + } + }else{ + //计算分润 + $where = [ + 'price_total' => 0.00 + ]; + $rows = $this->biz_settle_static_model->select($where,'id asc',$page,$size); + if($rows){ + foreach($rows as $val){ + $money_json = json_decode($val['money_json'],true); + $biz_info = $this->biz_info_model->get(['biz_id'=>$val['biz_id']]); + $in = $money_json['in']; + $out = $money_json['out']; + $in_price = $in['profix_car']+$in['srv_price']+$in['commission']; + $out_price = $out['biz_price']+$out['apply_price']+$out['fine_price']; + $price_need = $in_price-$out_price; + $partner_rate = $biz_info['rate']/100; + $liche_rate = (100-$biz_info['rate'])/100; + $data['profix_liche'] = $price_need*$liche_rate; + $data['profix_partner'] = $price_need*$partner_rate; + $data['price_total'] = $in_price-$out_price; + + $this->biz_settle_static_model->update($data,['id'=>$val['id']]); + } + }else{ + echo 'finish'; + } + } + } } diff --git a/common/models/biz/Biz_settle_price_model.php b/common/models/biz/Biz_settle_price_model.php new file mode 100644 index 00000000..84f4500d --- /dev/null +++ b/common/models/biz/Biz_settle_price_model.php @@ -0,0 +1,55 @@ +table_name, 'default'); + } + + /** + * @param $jsondata + * @return array + */ + public function get_jsondata($jsondata){ + $jsondata = json_decode($jsondata,true); + $jsondata_cn = [ + 'rent' => '房租', + 'base_manager' => '店长底薪', + 'base_employees' => '销售底薪', + 'wat_ele' => '水电物业', + 'media' => '垂直媒体', + 'marketing' => '市场营销费', + 'drive' => '试驾车租金', + 'commission' => '销售提成', + 'trucking' => '拖车费', + ]; + $res = []; + if($jsondata){ + foreach ($jsondata as $key=>$val) { + $key_cn = $jsondata_cn[$key] ? $jsondata_cn[$key] : $key; + $res[$key_cn] = $val; + } + } + + return $res; + } + + /** + * @param $jsondata + * @return int|mixed + */ + public function sum_jsondata($jsondata=[]){ + $jsondata = json_decode($jsondata,true); + $res = 0; + if($jsondata){ + foreach ($jsondata as $key=>$val) { + $res += $val; + } + } + return $res; + } +}