|
@@ -21,6 +21,11 @@ public function create(){
|
|
|
if($good_code==""){
|
|
|
return error_show(1002,"商品code不能为空");
|
|
|
}
|
|
|
+ $ct = Db::name('good')->alias('a')->join('good_type b','b.good_code=a.good_code','left')
|
|
|
+ ->where(['b.type_code'=>$good_code])->find();
|
|
|
+ if($ct==""){
|
|
|
+ return error_show(1002,"未找到商品数据");
|
|
|
+ }
|
|
|
$customer_code= $this->post['customer_code'] && $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :"";
|
|
|
if($customer_code==""){
|
|
|
return error_show(1002,"客户code不能为空");
|
|
@@ -31,13 +36,19 @@ public function create(){
|
|
|
}
|
|
|
$rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
|
|
|
$ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
|
|
|
- $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']) :"";
|
|
|
- $good_num=isset($this->post['good_num']) && $this->post['good_num'] !=="" ? intval($this->post['good_num']) :"";
|
|
|
- $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !=="" ? intval($this->post['origin_price']) :"";
|
|
|
- $sale_price=isset($this->post['sale_price']) && $this->post['sale_price'] !=="" ? trim($this->post['sale_price']) :"";
|
|
|
- $total_price=isset($this->post['total_price']) && $this->post['total_price'] !=="" ? trim($this->post['total_price']) :"";
|
|
|
+ // $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']) :"";
|
|
|
+ //$good_num=isset($this->post['good_num']) && $this->post['good_num'] !=="" ? intval($this->post['good_num']) :"";
|
|
|
+ // if($good_num==""){
|
|
|
+ // return error_show(1002,"参数good_num不能为空");
|
|
|
+ //}
|
|
|
+ // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !=="" ? intval($this->post['origin_price']) :"";
|
|
|
+ //$sale_price=isset($this->post['sale_price']) && $this->post['sale_price'] !=="" ? trim($this->post['sale_price']) :"";
|
|
|
+ // $total_price=isset($this->post['total_price']) && $this->post['total_price'] !=="" ? trim($this->post['total_price']) :"";
|
|
|
$post_fee=isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? trim($this->post['post_fee']) :"";
|
|
|
$status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
|
|
|
+// $send_num = isset($this->post['send_num']) && $this->post['send_num'] !=="" ? intval($this->post['send_num']) :"";
|
|
|
+// $wsend_num = isset($this->post['wsend_num']) && $this->post['wsend_num'] !=="" ? intval($this->post['wsend_num']) :"";
|
|
|
+// $send_status = isset($this->post['send_status']) && $this->post['send_status'] !=="" ? intval($this->post['send_status']) :"";
|
|
|
$va= isset($this->post['order_addr']) && $this->post['order_addr'] !=="" ? $this->post['order_addr']:"";
|
|
|
if($va==""){
|
|
|
return error_show(1002,"参数order_addr不能为空");
|
|
@@ -46,24 +57,28 @@ public function create(){
|
|
|
if($vi==""){
|
|
|
return error_show(1002,"参数good_stock不能为空");
|
|
|
}
|
|
|
+ $good_num = intval(array_sum(array_column($vi,"num")));
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
$data=[
|
|
|
"orderCode"=>$orderCode,
|
|
|
"good_code"=>$good_code,
|
|
|
"customer_code"=>$customer_code,
|
|
|
- "good_name"=>$good_name,
|
|
|
+ "good_name"=>$ct['good_name'],
|
|
|
"good_num"=>$good_num,
|
|
|
"apply_id"=>$rm,
|
|
|
"apply_name"=>$ri,
|
|
|
- "origin_price"=>$origin_price,
|
|
|
- "sale_price"=>$sale_price,
|
|
|
- "total_price"=>$total_price,
|
|
|
+ "origin_price"=>$ct['original_price'],
|
|
|
+ "sale_price"=>$ct['original_price'],
|
|
|
"post_fee"=>$post_fee,
|
|
|
"status"=>$status,
|
|
|
+ "send_num"=>0,
|
|
|
+ "wsend_num"=>$good_num,
|
|
|
+ "send_status"=>1,
|
|
|
"is_del"=>0,
|
|
|
"addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
+ 'total_price'=>$ct['original_price']*$good_num,
|
|
|
];
|
|
|
$datainfo = Db::name('sale')->insert($data,true);
|
|
|
$vat=[];
|
|
@@ -76,7 +91,7 @@ public function create(){
|
|
|
$iten['stock_id']="";
|
|
|
$iten['num']=$ion['num'];
|
|
|
$iten['status']=0;
|
|
|
- $iten['sale_price']=0;
|
|
|
+ $iten['sale_price']=$ct['original_price'];
|
|
|
$iten['addtime'] =date("Y-m-d H:i:s");
|
|
|
$iten['updatetime'] =date("Y-m-d H:i:s");
|
|
|
$inn[]=$iten;
|
|
@@ -86,13 +101,26 @@ public function create(){
|
|
|
// return error_show(1002,"超出库存数量");
|
|
|
// }
|
|
|
$vp= Db::name('sale_info')->insertAll($inn);
|
|
|
+ if($vp==""){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"添加失败");
|
|
|
+ }
|
|
|
foreach ($va as $value){
|
|
|
$temp=[];
|
|
|
+ $addrs=[];
|
|
|
+ if($value['addr_code']!==''&&is_array($value['addr_code'])){
|
|
|
+ $addrs['provice_code'] = $value['addr_code'][0];
|
|
|
+ $addrs['city_code'] = $value['addr_code'][1];
|
|
|
+ $addrs['area_code'] = $value['addr_code'][2];
|
|
|
+ $addr = json_encode($addrs);
|
|
|
+ }else{
|
|
|
+ $addr = isset($value['addr_code'])?$value['addr_code']:'';
|
|
|
+ }
|
|
|
$temp['orderCode']=$orderCode;
|
|
|
$temp['contactor']=$value['contactor'];
|
|
|
$temp['mobile'] = $value['mobile'];
|
|
|
$temp['addr'] = $value['addr'];
|
|
|
- $temp['addr_code'] =$value['addr_code'];
|
|
|
+ $temp['addr_code']=$addr;
|
|
|
$temp['customer_code'] =$customer_code;
|
|
|
$temp['receipt_quantity']=$value['receipt_quantity'];
|
|
|
$temp['post_fee'] =0;
|
|
@@ -253,14 +281,51 @@ public function info(){
|
|
|
if($id==""){
|
|
|
return error_show(1002,"参数id不能为空");
|
|
|
}
|
|
|
- $einfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->field('good_code,good_name,good_num,customer_code,orderCode')->find();
|
|
|
+ //->field('good_code,good_name,good_num,customer_code,orderCode')
|
|
|
+ $einfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->find();
|
|
|
if(empty($einfo)){
|
|
|
return error_show(1002,"未找到销售订单数据");
|
|
|
}
|
|
|
- $fo = Db::name('order_addr')->where(['orderCode'=>$einfo['orderCode'],'is_del'=>0])->field('addr,contactor,mobile,receipt_quantity,arrive_time')->select();
|
|
|
- $st = Db::name('sale_info')->where(['orderCode'=>$einfo['orderCode']])->field('wsm_code,num,sale_price,stock_id,wsm_code')->select();
|
|
|
- $einfo['item']=$fo;
|
|
|
- $einfo['iten']=$st;
|
|
|
+ $in= Db::name('customer_info')->where(['companyNo'=>$einfo['customer_code']])->field('companyName')->find();
|
|
|
+ // ->field('addr,contactor,mobile,receipt_quantity,arrive_time')
|
|
|
+ $fo = Db::name('order_addr')->where(['orderCode'=>$einfo['orderCode'],'is_del'=>0])->select();
|
|
|
+//.$value['addr']
|
|
|
+ $addrs=[];
|
|
|
+ foreach ($fo as $value){
|
|
|
+ $value['addr_info']="";
|
|
|
+ if($value['addr_code']!=""){
|
|
|
+ $addr=GetAddr($value['addr_code']);
|
|
|
+ $value['addr_info'] = $addr;
|
|
|
+ $value['addr_code'] = json_decode($value['addr_code'],true);
|
|
|
+ }
|
|
|
+ $addrs[]=$value;
|
|
|
+ }
|
|
|
+ //->field('num,sale_price,wsm_code,stock_id')
|
|
|
+ $st = Db::name('sale_info')->where(['orderCode'=>$einfo['orderCode']])->select();
|
|
|
+ $data=[];
|
|
|
+ foreach ($st as $value){
|
|
|
+ $value['wsm_name']="";
|
|
|
+ $value['wsm_supplier']="";
|
|
|
+ $value['wsm_supplierNo']="";
|
|
|
+ $value['usable_stock']=0;
|
|
|
+ $value['send_num']=0;
|
|
|
+ if($value['wsm_code']!=""){
|
|
|
+ $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
|
|
|
+ ->where(["a.wsm_code"=>$value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
|
|
|
+ $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
|
|
|
+ $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
|
|
|
+ $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
|
|
|
+ $dn = Db::name('good_stock')->where(['wsm_code'=>$value['wsm_code'],'good_type_code'=>$einfo['good_code']])->find();
|
|
|
+ $value['usable_stock'] =isset($dn['usable_stock']) ?$dn['usable_stock']:"0";
|
|
|
+ $send =Db::name("order_out")->where(["wsm_code"=>$value['wsm_code']])->sum("send_num");
|
|
|
+ $value['send_num'] = $send??0;
|
|
|
+ }
|
|
|
+ $value['wsend_num']=$value['num']-$value['send_num'];
|
|
|
+ $data[]=$value;
|
|
|
+ }
|
|
|
+ $einfo['info']=$data;
|
|
|
+ $einfo['companyName']=isset($in['companyName']) ? $in['companyName']:"";
|
|
|
+ $einfo['addrs']=$addrs;
|
|
|
if(empty($einfo)){
|
|
|
return error_show(1002,"未找到销售订单数据");
|
|
|
}else{
|
|
@@ -296,10 +361,44 @@ public function status(){
|
|
|
if(empty($dio)){
|
|
|
return error_show(1002,"销售单信息未找到");
|
|
|
}
|
|
|
- $dio['status']=$status;
|
|
|
- $dio['updatetime']=date("Y-m-d H:i:s");
|
|
|
- $st = Db::name('sale')->save($dio);
|
|
|
- return error_show(0,"订单状态更新成功");
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $dio['status']=$status;
|
|
|
+ $dio['updatetime']=date("Y-m-d H:i:s");
|
|
|
+ $st = Db::name('sale')->save($dio);
|
|
|
+ if($st) {
|
|
|
+ if($status==3){
|
|
|
+ $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
|
|
|
+ foreach ($dn as $value) {
|
|
|
+ $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
|
|
|
+ if($dm==""){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"未找到商品数据");
|
|
|
+ }
|
|
|
+ if($value['num']>$dm['usable_stock']){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"超出库存数量");
|
|
|
+ }
|
|
|
+ $dm['usable_stock']-=$value['num'];
|
|
|
+ $dm['wait_out_stock']+=$value['num'];
|
|
|
+ $send =Db::name("order_out")->where(["wsm_code"=>$value['wsm_code']])->sum("send_num");
|
|
|
+ $value['send_num'] = $send??0;
|
|
|
+ $value['wsend_num']=$value['num']-$value['send_num'];
|
|
|
+ $Db = Db::name('good_stock')->update($dm);
|
|
|
+ $Db['updatetime']= date('Y-m-d H:i:s');
|
|
|
+ if($Db==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"状态更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return error_show(0,"订单状态更新成功");
|
|
|
+ }catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, $e->getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
public function fee(){
|
|
|
$id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
|
|
@@ -348,10 +447,22 @@ public function fee(){
|
|
|
}
|
|
|
public function out(){
|
|
|
$token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
|
|
|
- $orderCode=makeNo("CK");
|
|
|
- $outCode = isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode']) :"";
|
|
|
- if($outCode==""){
|
|
|
- return error_show(1002,"参数outcode不能为空");
|
|
|
+ $outCode=makeNo("CK");
|
|
|
+ $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
|
|
|
+ if($orderCode==""){
|
|
|
+ return error_show(1002,"参数orderCoder不能为空");
|
|
|
+ }
|
|
|
+ $der = Db::name('sale')->where(['orderCode'=>$orderCode])->find();
|
|
|
+ if($der==""){
|
|
|
+ return error_show(1002,"未找到出库订单单号");
|
|
|
+ }
|
|
|
+ $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']) :"";
|
|
|
+ if($wsm_code==""){
|
|
|
+ return error_show(1002,"参数wsm_code不能为空");
|
|
|
+ }
|
|
|
+ $wsm= Db::name('sale_info')->where(['wsm_code'=>$wsm_code,'orderCode'=>$der['orderCode']])->find();
|
|
|
+ if($wsm==""){
|
|
|
+ return error_show(1002,"未找到仓库编码");
|
|
|
}
|
|
|
$post_name= isset($this->post['post_name']) && $this->post['post_name'] !=="" ? trim($this->post['post_name']) :"";
|
|
|
if($post_name==""){
|
|
@@ -363,7 +474,14 @@ public function out(){
|
|
|
}
|
|
|
$post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? intval($this->post['post_fee']) :"";
|
|
|
if($post_fee==""){
|
|
|
- return error_show(1002,"物流费用不能为空");
|
|
|
+ return error_show(1002,"物流费不能为空");
|
|
|
+ }
|
|
|
+ $send_num = isset($this->post['send_num']) && $this->post['send_num'] !=="" ? $this->post['send_num'] :"";
|
|
|
+ if($send_num==""){
|
|
|
+ return error_show(1002,"发货数量不能为空");
|
|
|
+ }
|
|
|
+ if($send_num>$wsm['num']){
|
|
|
+ return error_show(1002,"超出可发货数量");
|
|
|
}
|
|
|
$apply_id =GetUserInfo($token);
|
|
|
if(empty($apply_id)||$apply_id['code']!=0){
|
|
@@ -372,55 +490,141 @@ public function out(){
|
|
|
$rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
|
|
|
$ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
|
|
|
$addrid = isset($this->post['addrid']) && $this->post['addrid'] !=="" ? intval($this->post['addrid']) :"";
|
|
|
+ $dr = Db::name('order_addr')->where(['id'=>$addrid,'is_del'=>0])->find();
|
|
|
+ if(empty($dr)){
|
|
|
+ return error_show(1003,"收货人信息未找到");
|
|
|
+ }
|
|
|
+ if($dr['orderCode']!== $orderCode){
|
|
|
+ return error_show(1002,"订单code不存在");
|
|
|
+ }
|
|
|
$sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !=="" ? $this->post['sendtime']:date("Y-m-d H:i:s");
|
|
|
- $send_num = isset($this->post['send_num']) && $this->post['send_num'] !=="" ? $this->post['send_num'] :"";
|
|
|
- $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
|
|
|
- $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
|
|
|
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? $this->post['status'] :"";
|
|
|
- $data=[
|
|
|
- "orderCode"=>$orderCode,
|
|
|
- "outCode"=>$outCode,
|
|
|
- "apply_id"=>$rm,
|
|
|
- "apply_name"=>$ri,
|
|
|
- "addrid"=>$addrid,
|
|
|
- "post_name"=>$post_name,
|
|
|
- "post_code"=>$post_code,
|
|
|
- "post_fee"=>$post_fee,
|
|
|
- "sendtime"=>$sendtime,
|
|
|
- "send_num"=>$send_num,
|
|
|
- "check_num"=>$check_num,
|
|
|
- "error_num"=>$error_num,
|
|
|
- "status"=>$status,
|
|
|
- "addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- $datainfo = Db::name('order_out')->insert($data);
|
|
|
- if($datainfo){
|
|
|
- return error_show(0,"创建成功");
|
|
|
- }else{
|
|
|
- return error_show(1003,"创建失败");
|
|
|
+// $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
|
|
|
+// $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
|
|
|
+ $status = isset($this->post['status']) && $this->post['status'] !=="" ? $this->post['status'] :"0";
|
|
|
+ //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $data=[
|
|
|
+ "wsm_code"=>$wsm_code,
|
|
|
+ "orderCode"=>$orderCode,
|
|
|
+ "outCode"=>$outCode,
|
|
|
+ "apply_id"=>$rm,
|
|
|
+ "apply_name"=>$ri,
|
|
|
+ "addrid"=>$dr['id'],
|
|
|
+ "post_name"=>$post_name,
|
|
|
+ "post_code"=>$post_code,
|
|
|
+ "post_fee"=>$post_fee,
|
|
|
+ "sendtime"=>$sendtime,
|
|
|
+ "send_num"=>$send_num,
|
|
|
+ "check_num"=>0,
|
|
|
+ "error_num"=>0,
|
|
|
+ "status"=>$status,
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $datainfo = Db::name('order_out')->insert($data);
|
|
|
+ if($datainfo) {
|
|
|
+ if ($status==1) {
|
|
|
+ $var = Db::name('sale_info')->where(['orderCode' => $datainfo['orderCode'],'wsm_code'=>$wsm_code])->find();
|
|
|
+ $send =Db::name("order_out")->where(["wsm_code"=>$wsm_code,'orderCode'=>$orderCode])->sum("send_num");
|
|
|
+ $der['send_num']+= $send;
|
|
|
+ $der['wsend_num']-=$send ;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
|
|
|
+ $der['send_status']=$der['send_num']==0 ? 1 :$der['wsend_num']==0?3:2;
|
|
|
+ $der['status']=$der['send_num']==0 ? 3 :$der['wsend_num']==0?5:4;
|
|
|
+ $der['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $si = Db::name('sale')->save($der);
|
|
|
+ if($si==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"更新失败");
|
|
|
+ }
|
|
|
+ $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'],'good_type_code'=>$der['good_code']])->find();
|
|
|
+ if ($str == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002, "商品数据未找到");
|
|
|
+ }
|
|
|
+ if ($var['num'] > $str['usable_stock']) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002, "超出库存数量");
|
|
|
+ }
|
|
|
+ $str['wait_out_stock'] -= $var['num'];
|
|
|
+ $str['intra_stock'] += $var['num'];
|
|
|
+ $str['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $stre = Db::name('good_stock')->save($str);
|
|
|
+ if ($stre == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002, "状态更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ return error_show(0,"创建成功");
|
|
|
+ }else{
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"创建失败");
|
|
|
+ }
|
|
|
+ }catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
public function customer(){
|
|
|
- $orderCode= isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
|
|
|
- if(empty($orderCode)){
|
|
|
+ $outCode= isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode']) :"";
|
|
|
+ if(empty($outCode)){
|
|
|
return error_show(1002,"销售订单编号不能为空");
|
|
|
}
|
|
|
+ $codeinfo = Db::name('order_out')->where(['outCode'=>$outCode])->find();
|
|
|
+ if($codeinfo==""){
|
|
|
+ return error_show(1003,"未找到订单数据");
|
|
|
+ }
|
|
|
+// $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
|
|
|
+// if($orderCode==""){
|
|
|
+// return error_show(1002,"参数orderCoder不能为空");
|
|
|
+// }
|
|
|
+ $dr = Db::name('sale')->where(['orderCode'=>$codeinfo['orderCode']])->find();
|
|
|
+ if($dr==""){
|
|
|
+ return error_show(1002,"未找到销售订单");
|
|
|
+ }
|
|
|
$status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] :"";
|
|
|
if($status==""){
|
|
|
return error_show(10002,"状态不能为空");
|
|
|
}
|
|
|
- $codeinfo = Db::name('order_out')->where(['orderCode'=>$orderCode])->find();
|
|
|
- if($codeinfo==""){
|
|
|
- return error_show(1003,"未找到订单数据");
|
|
|
- }
|
|
|
- $codeinfo['status']=$status;
|
|
|
- $codeinfo['updatetime']=date("Y-m-d H:i:s");
|
|
|
- $cust = Db::name('order_out')->save($codeinfo);
|
|
|
- if($cust){
|
|
|
- return error_show(0,"销售订单更新成功");
|
|
|
- }else{
|
|
|
- return error_show(1003,"销售订单更新失败");
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $codeinfo['status']=$status;
|
|
|
+ $codeinfo['updatetime']=date("Y-m-d H:i:s");
|
|
|
+ $cust = Db::name('order_out')->save($codeinfo);
|
|
|
+ if($cust){
|
|
|
+ if($status==2){
|
|
|
+ $ct =Db::name('sale_info')->where(['orderCode' => $dr['orderCode'],'wsm_code'=>$codeinfo['wsm_code']])->find();
|
|
|
+ if($ct==false){
|
|
|
+ return error_show(1002,"未找到数据");
|
|
|
+ }
|
|
|
+ $var = Db::name('good_stock')->where(['wsm_code'=>$codeinfo['wsm_code'],'good_type_code'=>$dr['good_code']])->find();
|
|
|
+ if($var==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"未找到商品数据");
|
|
|
+ }
|
|
|
+ if($ct['num']>$var['intra_stock']){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"超出库存数量");
|
|
|
+ }
|
|
|
+ $var['intra_stock']-=$codeinfo['send_num'];
|
|
|
+ $var['updatetime']=date("Y-m-d H:i:s");
|
|
|
+ $stre = Db::name('good_stock')->save($var);
|
|
|
+ if ($stre == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002, "状态更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return error_show(0,"出库订单更新成功");
|
|
|
+ }else{
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"出库订单更新失败");
|
|
|
+ }
|
|
|
+ }catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|