cost plan add recost with param bill_time

This commit is contained in:
qianhy
2023-03-02 16:18:49 +08:00
committed by lccsw
parent f8b2abe522
commit 0f5b5ada75
+223 -16
View File
@@ -313,6 +313,130 @@ class Order extends CI_Controller{
}
}
/**更新订单的二手车标志
*/
private function update_if_usedcar(){
$sql = 'update lc_receiver_orders_v2 set if_usedcar = 1 where if_usedcar = 0 and item_id in (select id from lc_items where vin in (
"LDP42A96XN9024652",
"LDP42A968N9024648",
"LDP42A967N9022809",
"LDP42A961N9024653",
"LDP42A965N9021917",
"LDP42A96XN9023405",
"LDP42A960N9018777",
"LDP42A963N9018840",
"LDP42A963N9030437",
"LDP42A966N9030299",
"LDP42A966N9030206",
"LDP42A969N9026604",
"LDP42A961N9029710",
"LDP42A960N9026443",
"LDP42A968N9025251",
"LDP42A962N9024676",
"LDP42A963N9022659",
"LDP42A964N9027059",
"LDP42A96XN9023484",
"LDP42A969N9027042",
"LDP42A96XN9025039",
"LDP42A960N9029696",
"LDP42A961N9018920",
"LDP42A966N9023417",
"LDP42A967N9029727",
"LDP42A960N9030055",
"LDP42A969N9030099",
"LDP42A968N9030420",
"LDP42A963N9030082",
"LDP42A963N9030390",
"LDP42A964N9020998",
"LDP42A967N9026830",
"LDP42A969N9026750",
"LDP42A967N9029663",
"LDP42A967N9018890",
"LDP42A968N9026836",
"LDP42A963N9030020",
"LDP42A96XN9030256",
"LDP42A960N9024868",
"LDP42A963N9029384",
"LDP42A967N9027850",
"LDP42A968N9030398",
"LDP42A96XN9030242",
"LDP42A967N9030229",
"LDP42A96XN9030239",
"LDP42A961N9030260",
"LDP42A961N9030047",
"LDP42A966N9030058",
"LDP42A96XN9030032",
"LDP42A965N9030102",
"LDP42A968N9030238",
"LDP42A964N9030253",
"LDP42A963N9029854",
"LDP42A963N9030051",
"LDP42A961N9030100",
"LDP42A962N9022670",
"LDP42A963N9030230",
"LDP42A967N9030215",
"LDP42A960N9030248",
"LDP42A963N9030079",
"LFZ63AL59ND051213",
"LFZ71AK58ND121148",
"LFZ71AK53ND121056",
"LFZ71AK50ND123072",
"LFZ71AK51ND123310",
"LFZ71AK55ND123312",
"LFZ71AK54ND123317",
"LFZ71AK56ND123318",
"LFZ71AK55ND123049",
"LFZ71AK55ND123116",
"LFZ71AK5XND123113",
"LFZ71AK57ND123117",
"LFZ71AK52ND123302",
"LFZ71AK51ND120729",
"LFZ71AK55ND120586",
"LFZ71AK50ND120589",
"LFZ71AK5XND102083",
"LFZ63AL52ND051263",
"LFZ63AL55ND051256",
"LFZ63AL59ND052846",
"LFZ63AL51ND052355",
"LFZ71AK58ND120775",
"LFZ63AL56ND050486",
"LFZ63AL52ND050484",
"LUZAGAAA5NA136091",
"LUZAGAAA6NA136018",
"LUZAGBGA8NA170829",
"LUZAGAGA0NA170446",
"LUZAGAGA9NA170476",
"LUZAGAGAXNA170440",
"LUZAGBGA9NA170869",
"LUZAGBGA7NA170885",
"LUZAGBGA6NA170845",
"LUZAGAGA1NA163358",
"LUZAGAGA2NA139845",
"LUZAGAGAXNA139852",
"LUZAGAGA2NA139831",
"LUZAGAGA9NA133279",
"LUZAGAGAXNA133260",
"LUZAGAGA3NA123699",
"LUZAGAGA0NA139830",
"LUZAGAGA4NA139846",
"LUZAGAGA0NA139875",
"LUZAGBGA6NA140681",
"LUZAGBGA6NA140678",
"LUZAGBGA9NA140724",
"LUZAGBGA3NA132473",
"LUZAGBGA8NA139581",
"LUZAGBGA2NA140774",
"LUZAGBGA9NA140738",
"LUZAGBGA8NA171253",
"LUZAGBGA6NA139403",
"LUZAGAAA1NA107154",
"LUZAGAAA9NA156327",
"LUZBGAFB6NA076697"
))';
$this->receiver_orders_v2_model->db->query($sql);
$res = $this->receiver_orders_v2_model->db->affected_rows();
echo "update_if_usedcar rows: {$res}<br><br>";
}
/**
* 添加成本数据
* @return void
@@ -328,10 +452,15 @@ class Order extends CI_Controller{
$this->load->model('items/items_cost_model');
//$this->load->model('sys/sys_finance_model');
$this->load->model('sys/sys_supplier_model');
# 更新订单的二手车标志
$this->update_if_usedcar();
$page = $this->input->get('page');
$size = $this->input->get('size');
$id = $this->input->get('id');
$debug = $this->input->get('debug');
$recost = $this->input->get('recost');
!$page && $page = 1;
!$size && $size = 5;
!$debug && $where = [
@@ -348,6 +477,16 @@ class Order extends CI_Controller{
$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 ($recost){
$bill_time = $this->input->get('bill_time');
$where = array(
'id in (select o_id from lc_items_cost)' => null,
);
$bill_time && $where["bill_time >= '{$bill_time}'"] = null;
$rows = $this->receiver_orders_v2_model->select($where,'',0,0);
echo "recost: <br>";
echo $this->receiver_orders_v2_model->db->last_query()."<br>";
}
if ($debug){
echo "debug mode start <br><br>get order_v2: {$id}<br>";
echo $this->receiver_orders_v2_model->db->last_query()."<br>";
@@ -367,11 +506,13 @@ class Order extends CI_Controller{
exit();*/
foreach ($rows as $item) {
$if_usedcar = $item['if_usedcar'];
$biz = $this->biz_model->get(['id'=>$item['biz_id']]);
if ($debug){
echo "finance_id: {$item['finance_id']}"."<br>";
echo "biz_id: {$item['biz_id']}"."<br>";
echo "status: {$item['status']}"."<br>";
echo "if_usedcar: {$if_usedcar}"."<br>";
echo "<br><br>";
echo "get biz: <br>";
@@ -394,6 +535,10 @@ class Order extends CI_Controller{
$bill_info['销货单位名称'] && $add_data['bill_name'] = $bill_info['销货单位名称'];
$bill_info['开票日期'] && $add_data['bill_time'] = $bill_info['开票日期'];
$bill_info['价税合计(小写)'] && $add_data['bill_price'] = str_replace('¥','',$bill_info['价税合计(小写)']);
if ($if_usedcar){
$add_data['bill_name'] = $bill_info['二手车市场'];
$add_data['bill_price'] = str_replace('¥','',$bill_info['车价合计(小写)']);
}
if ($debug){
echo "get bill_info: <br>";
echo $this->order_bills_model->db->last_query()."<br>";
@@ -611,18 +756,53 @@ class Order extends CI_Controller{
's_effect_time<=' => date('Y-m-t',strtotime($item['bill_time'])),
];
*/
$where = [
'biz_id' => $item['biz_id'],
'type' => 1,
'status' => 1,
's_effect_time<=' => date('Y-m-d',strtotime($item['bill_time'])),
];
$free_row = $this->biz_settle_srv_model->get($where);
if ($debug){
echo "get 挂牌配置 : <br>";
echo $this->biz_settle_srv_model->db->last_query()."<br>";
var_dump($free_row);
echo "<br><br>";
$free_row = array();
if ($if_usedcar){
$where = [
'biz_id' => $item['biz_id'],
'type' => 1,
'status' => 1,
'title like "%二手车%"' => null,
's_effect_time<=' => date('Y-m-d',strtotime($item['bill_time'])),
];
$free_row = $this->biz_settle_srv_model->get($where);
if ($debug){
echo "get 挂牌配置(if_usedcar) : <br>";
echo $this->biz_settle_srv_model->db->last_query()."<br>";
var_dump($free_row);
echo "<br><br>";
}
if(!$free_row){
$where = ['biz_id'=>$item['biz_id'],
'is_def'=>1,
'status'=>1,
'type'=>1,
'title like "%二手车%"' => null,
];
$free_row = $this->biz_settle_srv_model->get($where);
if ($debug){
echo "get 挂牌配置(if_usedcar)(默认) : <br>";
echo $this->biz_settle_srv_model->db->last_query()."<br>";
var_dump($free_row);
echo "<br><br>";
}
}
}
if(!$free_row){
$where = [
'biz_id' => $item['biz_id'],
'type' => 1,
'status' => 1,
's_effect_time<=' => date('Y-m-d',strtotime($item['bill_time'])),
];
$free_row = $this->biz_settle_srv_model->get($where);
if ($debug){
echo "get 挂牌配置 : <br>";
echo $this->biz_settle_srv_model->db->last_query()."<br>";
var_dump($free_row);
echo "<br><br>";
}
}
if(!$free_row){
$free_row = $this->biz_settle_srv_model->get(['biz_id'=>$item['biz_id'],'is_def'=>1,'status'=>1,'type'=>1]);
@@ -735,6 +915,14 @@ class Order extends CI_Controller{
$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);
$srv_json['if_pay'] = $pay_price>=$need_price ? 1 : 0;
if ($recost){
# 已标记为齐款的,不能设置为0
$cost = $this->items_cost_model->get(array('o_id'=>$item['id']));
$srv_json_ = json_decode($cost['srv_json'], true);
if ($srv_json_['if_pay']){
$srv_json['if_pay'] = 1;
}
}
$add_data['srv_json'] = json_encode($srv_json,JSON_UNESCAPED_UNICODE);
if ($debug){
echo "get add_data : <br>";
@@ -746,16 +934,35 @@ class Order extends CI_Controller{
var_dump($cost);
echo "<br>";
echo "c_time: ".date("Y-m-d H:i:s",$cost['c_time'])."<br>";
echo "srv_json:<br>";
var_dump(json_decode($cost['srv_json'], true));
}
echo "<br><br>debug mode end<br><br>";
exit();
}
$id = $this->items_cost_model->add($add_data);
if ($recost){
unset($add_data['c_time']);
$id = $this->items_cost_model->update($add_data, array('o_id' => $item['id']));
}
else{
$id = $this->items_cost_model->add($add_data);
}
if(is_numeric($id)){
$this->items_cost_model->update_total($id);
echo "添加成功订单id:{$item['id']}<br>";
if ($recost){
echo "更新成功订单id:{$item['id']}<br>";
}
else{
echo "添加成功订单id:{$item['id']}<br>";
}
}else{
echo "添加失败订单id:{$item['id']}<br>";
if ($recost){
echo "忽略更新订单id:{$item['id']}<br>";
}
else{
echo "添加失败订单id:{$item['id']}<br>";
}
}
}
}else{
@@ -767,7 +974,7 @@ class Order extends CI_Controller{
* 修复成本数据的非品牌店的水平业务
* @return void
*/
public function cost_repair_spyw(){
private function cost_repair_spyw(){
$this->load->model("biz/biz_model");
$this->load->model('auto/auto_business_model');
$this->load->model('items/items_cost_model');