diff --git a/api/controllers/plan/Order.php b/api/controllers/plan/Order.php index 68c71050..51cab0b1 100644 --- a/api/controllers/plan/Order.php +++ b/api/controllers/plan/Order.php @@ -341,15 +341,18 @@ class Order extends CI_Controller{ 'id>=' => Orders_v2_entity::V2_START_ID ]; $id && $where['id'] = $id; - if ($debug && !$id){ - exit('debug下,只支持单个id参数'); + if ($debug){ + if (!$id){ + exit('debug下,只支持单个id参数'); + } + $where['(status = 1 or ( status = 0 and id in (select o_id from `lc_receiver_order_status` where (pid_status = 4 and `status` in (1,2)) or (pid_status = 3 and `status` = 1) group by o_id having count(distinct pid_status) = 2 )) or ( status = 0 and id in (select id from lc_receiver_orders_v2 where if_usedcar = 1 and bill_time > 0 )) )'] = null; } $rows = $this->receiver_orders_v2_model->select($where,'',$page,$size); if ($debug){ - echo "debug mode
get order_v2: {$id}
"; + echo "debug mode start

get order_v2: {$id}
"; echo $this->receiver_orders_v2_model->db->last_query()."
"; var_dump($rows); - echo "

"; + echo "
"; } if($rows){ $supplier2 = $this->sys_supplier_model->select(['status' => 1, 'type' => 2], '', 0, 0, 'id,title,short'); @@ -366,6 +369,11 @@ class Order extends CI_Controller{ foreach ($rows as $item) { $biz = $this->biz_model->get(['id'=>$item['biz_id']]); if ($debug){ + echo "finance_id: {$item['finance_id']}"."
"; + echo "biz_id: {$item['biz_id']}"."
"; + echo "status: {$item['status']}"."
"; + echo "

"; + echo "get biz:
"; echo $this->biz_model->db->last_query()."
"; var_dump($biz); @@ -396,34 +404,17 @@ class Order extends CI_Controller{ echo "bill_price: {$add_data['bill_price']}"."
"; echo "

"; } + $srv_json = []; //精品 $srv_json['price_fine_select'] = $money_json['price_fine_select'] ? $money_json['price_fine_select'] : 0; - //保险 - $img_data = $this->receiver_order_datas_model->get(['o_id'=>$item['id'],'status>='=>0]); - $insurance_img = json_decode($img_data['insurance_img'],true); - $business_img = json_decode($img_data['business_img'],true); - $srv_json['insurance_price'] = $insurance_img['price'] ? $insurance_img['price'] : ''; - $srv_json['insurance_product'] = $insurance_img['product'] ? $insurance_img['product'] : ''; - $srv_json['business_price'] = $business_img['price'] ? $business_img['price'] : ''; - $srv_json['business_product'] = $business_img['product'] ? $business_img['product'] : ''; - if ($debug){ - echo "get order_datas - 保险 img_data:
"; - echo $this->receiver_order_datas_model->db->last_query()."
"; - var_dump($img_data); - echo "
"; - echo "insurance_price: {$srv_json['insurance_price']}"."
"; - echo "insurance_product: {$srv_json['insurance_product']}"."
"; - echo "business_price: {$srv_json['business_price']}"."
"; - echo "business_product: {$srv_json['business_product']}"."
"; - echo "

"; - } + //获取创建订单时商务政策 $where = [ 'id' => $info_json['business_id'], ]; $b_row_one = $this->auto_business_model->get($where); - $srv_json['ori_price'] = $b_row_one['price_car'] ? $b_row_one['price_car'] : ''; + $srv_json['ori_price'] = $b_row_one['price_car'] ? $b_row_one['price_car'] : 0; $srv_json['price_floor'] = $b_row_one['price_floor'] ? $b_row_one['price_floor'] : 0; $srv_json['profix_car'] = $biz['type']==2 ? $b_row_one['proxy_profix_car'] : $b_row_one['profix_car']; if ($debug){ @@ -437,7 +428,6 @@ class Order extends CI_Controller{ echo "

"; } - $srv_json['insurance_ins_price'] = $srv_json['insurance_fd'] = 0; /* 水平 品牌店按现有逻辑 (1) @@ -448,6 +438,13 @@ class Order extends CI_Controller{ $add_data['insurance_price'] = $b_row_one['profix_insure'] ? $b_row_one['profix_insure'] : 0.00; $add_data['fee_carno_price'] = $b_row_one['profix_carno'] ? $b_row_one['profix_carno'] : 0.00; $add_data['loan_price'] = $b_row_one['profix_loan'] ? $b_row_one['profix_loan'] : 0.00; + if ($debug){ + echo "biz_type==2 (biz_type==3时均为0): "."
"; + echo "insurance_price: {$add_data['insurance_price']}"."
"; + echo "fee_carno_price: {$add_data['fee_carno_price']}"."
"; + echo "loan_price: {$add_data['loan_price']}"."
"; + echo "

"; + } } elseif ($biz['type']==3){ $add_data['insurance_price'] = 0.00; @@ -455,7 +452,34 @@ class Order extends CI_Controller{ $add_data['loan_price'] = 0.00; } - if($insurance_img && $insurance_img['product']){//强险 + //保险 + $srv_json['insurance_price'] = $srv_json['business_price'] = 0; + $srv_json['insurance_product'] = $srv_json['business_product'] = ''; + $img_data = $this->receiver_order_datas_model->get(['o_id'=>$item['id'],'status>='=>0]); + $insurance_img = json_decode($img_data['insurance_img'],true); + $business_img = json_decode($img_data['business_img'],true); + if ($biz['type']==1){ + $srv_json['insurance_price'] = $insurance_img['price'] ? $insurance_img['price'] : 0; + $srv_json['insurance_product'] = $insurance_img['product'] ? $insurance_img['product'] : ''; + $srv_json['business_price'] = $business_img['price'] ? $business_img['price'] : 0; + $srv_json['business_product'] = $business_img['product'] ? $business_img['product'] : ''; + if ($debug){ + echo "get order_datas - 保险 img_data:
"; + echo $this->receiver_order_datas_model->db->last_query()."
"; + var_dump($img_data); + echo "
"; + echo "insurance_price: {$srv_json['insurance_price']}"."
"; + echo "insurance_product: {$srv_json['insurance_product']}"."
"; + echo "business_price: {$srv_json['business_price']}"."
"; + echo "business_product: {$srv_json['business_product']}"."
"; + echo "

"; + } + } + + + //强险 + $srv_json['insurance_ins_price'] = $srv_json['insurance_fd'] = 0; + if($biz['type']==1 && $insurance_img && $insurance_img['product']){ $time = strtotime($insurance_img['date']); /*$where = [ 'biz_id' => $item['biz_id'], @@ -478,6 +502,9 @@ class Order extends CI_Controller{ $fd_row = $this->biz_settle_srv_model->get($where); if ($debug){ echo "get 强险配置 :
"; + if ($insure_product != $insurance_img['product']){ + echo "{$insurance_img['product']} -> {$insure_product}"."
"; + } echo $this->biz_settle_srv_model->db->last_query()."
"; var_dump($fd_row); echo "

"; @@ -510,8 +537,10 @@ class Order extends CI_Controller{ echo "

"; } } + + //商业险 $srv_json['business_ins_price'] = $srv_json['business_fd'] = 0; - if($business_img && $business_img['product']){//商业险 + if($biz['type']==1 && $business_img && $business_img['product']){ $time = strtotime($business_img['date']); /*$where = [ 'biz_id' => $item['biz_id'], @@ -534,6 +563,9 @@ class Order extends CI_Controller{ $bis_fd_row = $this->biz_settle_srv_model->get($where); if ($debug){ echo "get 商业险配置 :
"; + if ($insure_product != $business_img['product']){ + echo "{$business_img['product']} -> {$insure_product}"."
"; + } echo $this->biz_settle_srv_model->db->last_query()."
"; var_dump($bis_fd_row); echo "

"; @@ -566,10 +598,11 @@ class Order extends CI_Controller{ echo "

"; } } + //挂牌 $srv_json['fee_carno'] = $money_json['fee_carno'] ? $money_json['fee_carno'] : 0; $srv_json['cb_fee_carno'] = 0; - if($money_json['fee_carno']>0){ + if($biz['type']==1 && $money_json['fee_carno']>0){ /*$where = [ 'biz_id' => $item['biz_id'], 'type' => 1, @@ -603,11 +636,11 @@ class Order extends CI_Controller{ $free_jsondata = json_decode($free_row['jsondata'],true); $srv_json['cb_fee_carno'] = $free_jsondata['price'] ? $free_jsondata['price'] : 0; if ($debug){ - echo "get 挂牌返点:
"; - echo "cb_fee_carno: {$srv_json['cb_fee_carno']}"."
"; + echo "挂牌返点 cb_fee_carno: {$srv_json['cb_fee_carno']}"."
"; echo "

"; } } + //贷款信息 $srv_json['loan_product'] = ''; $srv_json['loan_srv_price'] = $srv_json['loan_num'] = $srv_json['loan_price'] = 0; @@ -622,59 +655,80 @@ class Order extends CI_Controller{ $srv_json['loan_product'] = $finance_row ? $finance_row['title'] : ''; } $srv_json['loan_num'] = $finance_num = $loan_row['num'] ? $loan_row['num'] : 36; - /*$where = [ - 'biz_id' => $item['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, - ];*/ - $where = [ - 'biz_id' => $item['biz_id'], - 'type' => 3, - 'status' => 1, - 's_effect_time<=' => date('Y-m-d',strtotime($item['bill_time'])), - "json_extract(jsondata, '$.supplier_id') = '{$finance_id}'" => null, - "json_extract(jsondata, '$.finance_num') = '{$finance_num}'" => null, - ]; - $fd_row = $this->biz_settle_srv_model->get($where); if ($debug){ - echo "get 贷款配置 :
"; - echo $this->biz_settle_srv_model->db->last_query()."
"; - var_dump($fd_row); + echo "get 贷款信息:
"; + echo $this->order_loans_model->db->last_query()."
"; + var_dump($loan_row); + echo "
"; + if ($finance_id){ + echo $this->sys_supplier_model->db->last_query()."
"; + var_dump($finance_row); + echo "
"; + } + echo "loan_price (money_json['price_loan']): {$srv_json['loan_price']}"."
"; + echo "loan_product: {$srv_json['loan_product']}"."
"; + echo "loan_num: {$srv_json['loan_num']}"."
"; echo "

"; } - if(!$fd_row){ - $fd_row = $this->biz_settle_srv_model->get(['biz_id'=>$item['biz_id'],'is_def'=>1,'status'=>1,'type'=>3, - "json_extract(jsondata, '$.supplier_id') = '{$finance_id}'" => null, "json_extract(jsondata, '$.finance_num') = '{$finance_num}'" => null]); + + if ($biz['type']==1){ + /*$where = [ + 'biz_id' => $item['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, + ];*/ + $where = [ + 'biz_id' => $item['biz_id'], + 'type' => 3, + 'status' => 1, + 's_effect_time<=' => date('Y-m-d',strtotime($item['bill_time'])), + "json_extract(jsondata, '$.supplier_id') = '{$finance_id}'" => null, + "json_extract(jsondata, '$.finance_num') = '{$finance_num}'" => null, + ]; + $fd_row = $this->biz_settle_srv_model->get($where); if ($debug){ - echo "get 贷款配置(默认) :
"; + echo "get 贷款配置 :
"; echo $this->biz_settle_srv_model->db->last_query()."
"; var_dump($fd_row); echo "

"; } - } - $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; - $s_json = json_decode($item['srv_ids'],true); - if($s_json){ - foreach ($s_json as $v2) { - if($v2['key']=='price_finance'){ - $srv_loan = $v2['price']; - break; + if(!$fd_row){ + $fd_row = $this->biz_settle_srv_model->get(['biz_id'=>$item['biz_id'],'is_def'=>1,'status'=>1,'type'=>3, + "json_extract(jsondata, '$.supplier_id') = '{$finance_id}'" => null, "json_extract(jsondata, '$.finance_num') = '{$finance_num}'" => null]); + if ($debug){ + echo "get 贷款配置(默认) :
"; + echo $this->biz_settle_srv_model->db->last_query()."
"; + var_dump($fd_row); + echo "

"; } } - } - $srv_json['loan_srv_price'] = $profix_loan + $srv_loan; - if ($debug){ - echo "get 贷款返点:
"; - echo "loan_srv_price: {$srv_json['loan_srv_price']}"."
"; - echo "

"; + $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; + $s_json = json_decode($item['srv_ids'],true); + if($s_json){ + foreach ($s_json as $v2) { + if($v2['key']=='price_finance'){ + $srv_loan = $v2['price']; + break; + } + } + } + $srv_json['loan_srv_price'] = $profix_loan + $srv_loan; + if ($debug){ + echo "贷款返点: loan_fd: {$loan_fd}"."
"; + echo "贷款返点金额: profix_loan: {$profix_loan}"."
"; + echo "贷款手续费: srv_loan: {$srv_loan}"."
"; + echo "按揭综合服务费: loan_srv_price: {$srv_json['loan_srv_price']}"."
"; + echo "

"; + } } } + $sum = $this->app_liche_orders_model->sum('total_price', ['o_id'=>$item['id'],'status'=>1,'pay_price <>'=>0]); $pay_price = $sum['total_price'] ? $sum['total_price'] : 0; $need_price = $this->orders_v2_entity->recevable_price($item['id'],$srv_price=true,$price_loan=false); @@ -683,6 +737,15 @@ class Order extends CI_Controller{ if ($debug){ echo "get add_data :
"; var_dump($add_data); + + if ($cost = $this->items_cost_model->get(array('o_id'=>$item['id']))){ + echo "

"; + echo $this->items_cost_model->db->last_query()."
"; + var_dump($cost); + echo "
"; + echo "c_time: ".date("Y-m-d H:i:s",$cost['c_time'])."
"; + } + echo "

debug mode end

"; exit(); } $id = $this->items_cost_model->add($add_data);