|
@@ -244,6 +244,7 @@ class Sale extends Base
|
|
|
$paytime==""?"": $data['paytime'] = $paytime;
|
|
|
$datainfo = Db::name('sale')->insert($data,true);
|
|
|
if($datainfo>0){
|
|
|
+
|
|
|
//修改状态,添加待办
|
|
|
ActionLog::logAdd($this->post['token'], [
|
|
|
"order_code" => $orderCode,//销售单code
|
|
@@ -272,15 +273,22 @@ class Sale extends Base
|
|
|
}
|
|
|
}
|
|
|
$outstatus=0;
|
|
|
+ $standing_book_da = ['customer_code' => $customer_code, 'skuCode' => $skuCode, 'updatetime' => date('Y-m-d H:i:s')];
|
|
|
if($is_stock==0){
|
|
|
- $bol=$this->createCgd($cgd);
|
|
|
+ $bol=$this->createCgd($cgd,$standing_book_da);
|
|
|
if($bol==false){
|
|
|
Db::rollback();
|
|
|
return error_show(1002,"订单创建失败");
|
|
|
}
|
|
|
}else{
|
|
|
$outstatus=1;
|
|
|
- $bol =$this->RelaCgd(['orderCode'=>$orderCode,"good_num"=>$good_num,"spuCode"=>$spuCode,"companyNo"=>$supplierNo,"cost_fee"=>isset($good['cost_fee'])?$good['cost_fee']:0]);
|
|
|
+ $bol =$this->RelaCgd([
|
|
|
+ 'orderCode'=>$orderCode,
|
|
|
+ "good_num"=>$good_num,
|
|
|
+ "spuCode"=>$spuCode,
|
|
|
+ "companyNo"=>$supplierNo,
|
|
|
+ "cost_fee"=>isset($good['cost_fee'])?$good['cost_fee']:0
|
|
|
+ ],$standing_book_da);
|
|
|
if($bol==false){
|
|
|
Db::rollback();
|
|
|
return error_show(1002,"库存商品关联采购单失败");
|
|
@@ -365,6 +373,7 @@ class Sale extends Base
|
|
|
Db::rollback();
|
|
|
return error_show(1002, "发货地址添加创建失败");
|
|
|
}
|
|
|
+
|
|
|
$cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
|
|
|
if ($cgdinfo == false) {
|
|
|
Db::rollback();
|
|
@@ -408,6 +417,8 @@ class Sale extends Base
|
|
|
"order_id" => Db::name("order_out")->getLastInsID(),
|
|
|
"order_status" => $out['status'],"before_status"=> $out['status']
|
|
|
]);
|
|
|
+
|
|
|
+ $standing_book_da['outCode'] = $outCode;
|
|
|
}
|
|
|
// }
|
|
|
}else{
|
|
@@ -416,6 +427,14 @@ class Sale extends Base
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //处理台账
|
|
|
+ if (isset($standing_book_da['bk_code'])) {
|
|
|
+ $temp = Db::name('standing_book')->field('id')->where('bk_code', $standing_book_da['bk_code'])->find();
|
|
|
+ if (!empty($temp)) Db::name('standing_book')->where('id', $temp['id'])->update($standing_book_da);
|
|
|
+ else Db::name('standing_book')->insert(array_merge($standing_book_da, ['addtime' => date('Y-m-d H:i:s')]));
|
|
|
+ }else Db::name('standing_book')->insert(array_merge($standing_book_da, ['addtime' => date('Y-m-d H:i:s')]));
|
|
|
+
|
|
|
Db::commit();
|
|
|
return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
|
|
|
}
|
|
@@ -428,7 +447,7 @@ class Sale extends Base
|
|
|
}
|
|
|
|
|
|
//采购单
|
|
|
- public function createCgd($data){
|
|
|
+ public function createCgd($data,array &$standing_book_da=[]){
|
|
|
$cgdCode = makeNo("CG");
|
|
|
$supplier=Db::name("supplier")->where(["code"=>$data['supplierNo'],"is_del"=>0])->find();
|
|
|
if($supplier==false){
|
|
@@ -517,6 +536,16 @@ class Sale extends Base
|
|
|
"order_status" => $cg['status'],"before_status"=> 0
|
|
|
]);
|
|
|
|
|
|
+ $standing_book_da = array_merge($standing_book_da, [
|
|
|
+ 'orderCode' => $data['orderCode'],
|
|
|
+ 'cgdNo' => $cgdCode,
|
|
|
+ 'spuCode' => $data['spuCode'],
|
|
|
+ 'skuCode' => $data['skuCode'],
|
|
|
+ 'order_type' => $data['order_type'],
|
|
|
+ 'supplierNo' => $data['supplierNo'],
|
|
|
+ "companyNo" => $data['companyNo'],
|
|
|
+ ]);
|
|
|
+
|
|
|
$rela=[
|
|
|
"orderCode"=>$data['orderCode'],
|
|
|
"cgdNo"=>$cgdCode,
|
|
@@ -743,11 +772,17 @@ class Sale extends Base
|
|
|
"order_id" => Db::name("order_out")->getLastInsID(),
|
|
|
"order_status" => $status,"before_status"=> 0
|
|
|
]);
|
|
|
+
|
|
|
+ //处理台账-既然是根据orderCode更新的数据,那么肯定是有数据的,只需要更新就行了
|
|
|
+ $standing_book_id = Db::name('standing_book')->where('orderCode', $orderCode)->value('id');
|
|
|
+ if (!empty($standing_book_id)) {
|
|
|
+ Db::name('standing_book')
|
|
|
+ ->where('id', $standing_book_id)
|
|
|
+ ->update(['outCode' => $outCode, 'updatetime' => date('Y-m-d H:i:s')]);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//维护商品所在仓库的库存 --- end
|
|
|
-
|
|
|
-
|
|
|
}else{
|
|
|
Db::rollback();
|
|
|
return error_show(1002,"发货地址添加创建失败");
|
|
@@ -912,6 +947,9 @@ class Sale extends Base
|
|
|
];
|
|
|
$datainfo = Db::name('sale')->insert($data, true);
|
|
|
if($datainfo>0){
|
|
|
+
|
|
|
+ $standing_book_data = ['infoNo' => $zxinfo['infoNo'], 'updatetime' => date('Y-m-d H:i:s')];
|
|
|
+
|
|
|
//修改状态,添加待办
|
|
|
ActionLog::logAdd($this->post['token'], [
|
|
|
"order_code" =>$orderCode,//销售单code
|
|
@@ -943,7 +981,7 @@ class Sale extends Base
|
|
|
], "ZXD", 5, $zx);
|
|
|
|
|
|
}
|
|
|
- $bol=$this->createCgd($cgd);
|
|
|
+ $bol=$this->createCgd($cgd,$standing_book_data);
|
|
|
if($bol==false){
|
|
|
Db::rollback();
|
|
|
return error_show(1002,"咨询订单创建失败");
|
|
@@ -1064,6 +1102,9 @@ class Sale extends Base
|
|
|
"order_id" => Db::name("order_out")->getLastInsID(),
|
|
|
"order_status" => 0,"before_status"=> 0
|
|
|
]);
|
|
|
+
|
|
|
+ //将发货编号添加到台账中
|
|
|
+ $standing_book_data['outCode']=$outCode;
|
|
|
}
|
|
|
$order['send_num']+=$value['receipt_quantity'];
|
|
|
$order['wsend_num']-=$value['receipt_quantity'];
|
|
@@ -1094,6 +1135,11 @@ class Sale extends Base
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //处理台账
|
|
|
+ $standing_book_id = Db::name('standing_book')->where('infoNo', $standing_book_data['infoNo'])->value('id');
|
|
|
+ if (!empty($standing_book_id)) Db::name('standing_book')->where('id', $standing_book_id)->update($standing_book_data);
|
|
|
+
|
|
|
Db::commit();
|
|
|
return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
|
|
|
}
|
|
@@ -1174,6 +1220,8 @@ class Sale extends Base
|
|
|
$good['rm']=$rm;
|
|
|
$good['ri']=$ri;
|
|
|
$good['send_num']=0;
|
|
|
+
|
|
|
+ $standing_book_data=['projectNo'=>$plan['projectNo'],'updatetime'=>date('Y-m-d H:i:s')];
|
|
|
if($value['sendtype']==1){
|
|
|
if(!isset($value['addrlist'])||empty($value['addrlist'])){
|
|
|
Db::rollback();
|
|
@@ -1184,7 +1232,7 @@ class Sale extends Base
|
|
|
}
|
|
|
if($feedback['data_source']==1){
|
|
|
|
|
|
- $feed=$this->project_good($good);
|
|
|
+ $feed=$this->project_good($good,$standing_book_data);
|
|
|
if($feed !==true){
|
|
|
Db::rollback();
|
|
|
switch ($feed){
|
|
@@ -1207,7 +1255,7 @@ class Sale extends Base
|
|
|
return error_show(1002,$msg);
|
|
|
}
|
|
|
}else{
|
|
|
- $feed=$this->project_zx($good);
|
|
|
+ $feed=$this->project_zx($good,$standing_book_data);
|
|
|
if($feed==false){
|
|
|
Db::rollback();
|
|
|
return error_show(1002, "咨询订单生成失败");
|
|
@@ -1221,6 +1269,9 @@ class Sale extends Base
|
|
|
Db::rollback();
|
|
|
return error_show(1002, "项目订单生成失败");
|
|
|
}
|
|
|
+
|
|
|
+ //处理台账
|
|
|
+ Db::name('standing_book')->where('projectNo',$plan['projectNo'])->update($standing_book_data);
|
|
|
}
|
|
|
$old_plan_status = $plan['status'];
|
|
|
$plan['status']=2;
|
|
@@ -1270,6 +1321,7 @@ class Sale extends Base
|
|
|
], "PRT", 2, $this->post);
|
|
|
$process = ["order_code" => $project['projectNo'], "order_id" => $project['id'], "order_status" =>2, "order_type" =>"PRT","before_status"=> 1];
|
|
|
ProcessOrder::AddProcess($this->post['token'], $process);
|
|
|
+
|
|
|
Db::commit();
|
|
|
return app_show(0, "咨询订单生成成功");
|
|
|
}catch (\Exception $e){
|
|
@@ -1288,7 +1340,7 @@ class Sale extends Base
|
|
|
*
|
|
|
*/
|
|
|
|
|
|
- public function project_zx($data){
|
|
|
+ public function project_zx($data,array &$standing_book_data=[]){
|
|
|
$goodinfo = Db::name("consult_bids")->where(["spuCode"=>$data['spuCode'],"is_del"=>0])->find();
|
|
|
if($goodinfo==false){
|
|
|
return false;
|
|
@@ -1361,6 +1413,7 @@ class Sale extends Base
|
|
|
];
|
|
|
$datainfo = Db::name('sale')->insert($datas, true);
|
|
|
if($datainfo>0){
|
|
|
+ $standing_book_data['customer_code']=$datas['customer_code'];
|
|
|
//修改状态,添加待办
|
|
|
ActionLog::logAdd($this->post['token'], [
|
|
|
"order_code" =>$orderCode,//项目编码
|
|
@@ -1375,7 +1428,7 @@ class Sale extends Base
|
|
|
"order_id" => $datainfo,
|
|
|
"order_status" => 0,"before_status"=> 0
|
|
|
]);
|
|
|
- $bol = $this->createCgd($cgd);
|
|
|
+ $bol = $this->createCgd($cgd,$standing_book_data);
|
|
|
if ($bol == false) {
|
|
|
return false;
|
|
|
}
|
|
@@ -1528,6 +1581,8 @@ class Sale extends Base
|
|
|
if ($sen == false) {
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ $standing_book_data['outCode'] = $outCode;
|
|
|
}
|
|
|
|
|
|
} else {
|
|
@@ -1546,7 +1601,7 @@ class Sale extends Base
|
|
|
* @throws \think\db\exception\DbException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
*/
|
|
|
- public function project_good($data){
|
|
|
+ public function project_good($data,array &$standing_book_data=[]){
|
|
|
$good=Db::name('good')
|
|
|
->alias("a")
|
|
|
->leftJoin("good_platform b","a.spuCode=b.spuCode")
|
|
@@ -1665,7 +1720,7 @@ class Sale extends Base
|
|
|
'send_way'=>2
|
|
|
];
|
|
|
if($good['is_stock']==0) {
|
|
|
- $bol = $this->createCgd($cgd);
|
|
|
+ $bol = $this->createCgd($cgd,$standing_book_data);
|
|
|
if ($bol == false) {
|
|
|
return 3;//关联采购失败
|
|
|
}
|
|
@@ -1677,7 +1732,7 @@ class Sale extends Base
|
|
|
return 1; //库存不足
|
|
|
}
|
|
|
|
|
|
- $bol =$this->RelaCgd(['orderCode'=>$orderCode,"good_num"=>$data['good_num'],"spuCode"=>$good['spuCode'],"companyNo"=>$data['companyNo'],"cost_fee"=>$goodlass['cost_fee']]);
|
|
|
+ $bol =$this->RelaCgd(['orderCode'=>$orderCode,"good_num"=>$data['good_num'],"spuCode"=>$good['spuCode'],"companyNo"=>$data['companyNo'],"cost_fee"=>$goodlass['cost_fee']],$standing_book_data);
|
|
|
if($bol==false){
|
|
|
return 3;//关联采购失败
|
|
|
}
|
|
@@ -1724,6 +1779,7 @@ class Sale extends Base
|
|
|
$temp['arrive_time'] = $data['arrtime'];
|
|
|
$vmp = Db::name('order_addr')->insert($temp, true);
|
|
|
if ($vmp > 0) {
|
|
|
+ $standing_book_data['customer_code'] = $temp['customer_code'];
|
|
|
// if ($good['is_stock'] == 1) {
|
|
|
$order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
|
|
|
->lock(true)->find();
|
|
@@ -1780,6 +1836,7 @@ class Sale extends Base
|
|
|
if ($ou == false) {
|
|
|
return 0;
|
|
|
} else {
|
|
|
+ $standing_book_data['outCode'] = $outCode;
|
|
|
//修改状态,添加待办
|
|
|
ActionLog::logAdd($this->post['token'], [
|
|
|
"order_code" => $outCode,//出库单号
|
|
@@ -3481,7 +3538,7 @@ class Sale extends Base
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- public function RelaCgd($outinfo){
|
|
|
+ public function RelaCgd($outinfo,array &$standing_book_da=[]){
|
|
|
$cgd = Db::name("order_bk")->where([["spuCode","=",$outinfo['spuCode']],["is_del","=",0],["balance_num",">=",
|
|
|
$outinfo['good_num']],['companyNo',"=",$outinfo['companyNo']]])->lock(true)->find();
|
|
|
if($cgd==false){
|
|
@@ -3537,6 +3594,19 @@ class Sale extends Base
|
|
|
$insetrCgd=Db::name("purchease_order")->insert($QrdCgd);
|
|
|
if($insetrCgd==false){
|
|
|
return false;
|
|
|
+ }else{
|
|
|
+ $standing_book_da = array_merge($standing_book_da, [
|
|
|
+// 'standBookNo' => makeNo("IO"),
|
|
|
+ 'bk_code' => $cgdinfo['bkcode'],
|
|
|
+ 'orderCode' => $outinfo['orderCode'],
|
|
|
+ 'cgdNo' => $QrdCgd['cgdNo'],
|
|
|
+ 'spuCode' => $outinfo['spuCode'],
|
|
|
+ 'order_type' => $QrdCgd['order_type'],
|
|
|
+ 'supplierNo' => $cgdinfo['supplierNo'],
|
|
|
+ "companyNo" => $cgdinfo['companyNo'],
|
|
|
+// 'addtime' => date('Y-m-d H:i:s'),
|
|
|
+// 'updatetime' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
}
|
|
|
if($good['is_gold_price']==1 && $good['is_stock']==1){
|
|
|
$gold = Db::name("gold_price1")
|