Files
liche/api/controllers/plan/Biz.php
T
2022-03-24 22:29:48 +08:00

160 lines
6.8 KiB
PHP

<?php
class Biz 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();
$this->load->model('receiver/order/receiver_orders_v2_model','orders_model');
$this->load->model('auto/auto_business_model');
$this->load->model('biz/biz_model');
$this->load->model('biz/biz_info_model');
$this->load->model('biz/biz_settle_model');
$this->load->model('biz/biz_settle_static_model');
$this->load->model('biz/biz_trucking_model');
}
public function settle(){
$size = $this->input->get('size');
!$size && $size = 5;
$t1 = 'lc_receiver_order_status';
$t2 = 'lc_receiver_orders_v2';
$t3 = 'lc_biz_settle';
$t4 = 'lc_biz';
$fields = "$t2.*,$t4.city_id";
$where = [
"$t1.pid_status" => 5,
"$t1.status" => 1,
"$t2.status>=" => 0,
"$t3.id is null" => null,
"$t4.type" => 2
];
$this->db->from("$t1");
$this->db->join("$t2", "$t2.id=$t1.o_id",'left');
$this->db->join("$t3", "$t3.o_id=$t1.o_id",'left');
$this->db->join("$t4", "$t4.id=$t2.biz_id",'left');
$this->db->select($fields);
$this->db->where($where);
$this->db->order_by("$t2.id ASC");
$this->db->limit($size);
$rows = $this->db->get()->result_array();
if($rows){
foreach($rows as $key=>$val){
//获取创建订单当月商务政策
$b_where = [
'city_id ' => $val['city_id'],
'brand_id' => $val['brand_id'],
's_id' => $val['s_id'],
'v_id' => $val['v_id'],
'status' => 1
];
$b_where['year'] = date('Y',$val['c_time']);
$b_where['month'] = intval(date('m',$val['c_time']));
$b_row_one = $this->auto_business_model->get($b_where);
//获取开票日期商务政策
$b_row_two = $b_row_one;
if(date('Y-m',strtotime($val['bill_time']))!=date('Y-m',$val['c_time'])) {
$b_where['year'] = date('Y',strtotime($val['bill_time']));
$b_where['month'] = intval(date('m',strtotime($val['bill_time'])));
$b_row_two = $this->auto_business_model->get($b_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;
$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_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,
'year' => date('Y'),
'month' => intval(date('m')),
'c_time' => time()
];
$this->biz_settle_model->add($add_data);
}
}else{
echo 'finish';
}
}
//统计前一个月利润
public function merage(){
$size = $this->input->get('size');
!$size && $size = 5;
$t1 = 'lc_biz_settle';
$t2 = 'lc_biz_settle_static';
$fields = "$t1.*";
$where = [
"$t1.year" => date('Y',strtotime("last month")),
//"$t1.month" => date('m',strtotime('last month')),
"$t1.month" => date('m'),
"$t2.id is null" => null
];
$this->db->from("$t1");
$this->db->join("$t2", "$t2.biz_id=$t1.biz_id",'left');
$this->db->select($fields);
$this->db->where($where);
$this->db->group_by("$t1.biz_id");
$this->db->limit($size);
$rows = $this->db->get()->result_array();
if($rows){
foreach($rows as $key=>$val){
$where = [
'biz_id' => $val['biz_id'],
'year' => $val['year'],
'month' => $val['month']
];
if(!$this->biz_settle_static_model->get($where)){
$biz = $this->biz_model->get(['id'=>$val['biz_id']]);
$biz_info = $this->biz_info_model->get(['biz_id'=>$val['biz_id']]);
$total_car = $this->biz_settle_model->count($where);
$sum_car = $this->biz_settle_model->sum('profix_car',$where);
$sum_insure = $this->biz_settle_model->sum('profix_insure',$where);
$sum_loan = $this->biz_settle_model->sum('profix_loan',$where);
$sum_carno = $this->biz_settle_model->sum('profix_carno',$where);
$price_all = $sum_insn['profix_insure']+$sum_loan['profix_loan']+$sum_carno['profix_carno'];
$sum_trucking = $this->biz_settle_model->sum('price_trucking',$where);
$data = [
'biz_id' => $val['biz_id'],
'profix_car' => $sum_car['profix_car'],
'profix_car_after' => sprintf("%.2f",$sum_car['profix_car']/1.13),
'price_all' => $price_all,
'price_trucking' => $sum_trucking['price_trucking'],
'rent' => $biz_info['rent'],
'wat_ele' => $biz_info['wat_ele'],
'employee_wage' => $biz_info['employee_wage'],
'manager_wage' => $biz_info['manager_wage'],
'commission' => $biz_info['commission'] * $total_car,
'year' => $val['year'],
'month' => $val['month'],
'c_time' => time()
];
$data['price_total'] = $data['price_all']+$data['profix_car_after'];
$type_config = $this->biz_type[$biz_info['type']];
$price_need = $data['price_total'] - $data['rent'] - $data['wat_ele'] - $data['employee_wage'] - $data['manager_wage'] - $data['commission'] - $data['price_trucking'];
$data['profix_liche'] = $price_need*$type_config['liche'];
$data['profix_partner'] = $price_need*$type_config['partner'];
$this->biz_settle_static_model->add($data);
}
}
}else{
echo 'finish';
}
}
}