Browse Source

Merge branch 'master-new-dev-wf' of wugg/phpstock into master-new

wufeng 2 years ago
parent
commit
f56f874a67
2 changed files with 39 additions and 12 deletions
  1. 11 5
      app/admin/controller/Reorder.php
  2. 28 7
      app/admin/controller/ReorderChild.php

+ 11 - 5
app/admin/controller/Reorder.php

@@ -947,14 +947,20 @@ class Reorder extends Base
                                     $outup = Db::name("order_out")->save($out);
                                     if ($outup == false) throw new Exception('地址发货单更新失败');
 
-                                    //维护发货工单的数量
-                                    Db::name('order_out_child')
+                                    $tmp = Db::name('order_out_child')
                                         ->where(['is_del' => 0, 'outCode' => $value['outCode']])
-                                        ->limit(1)
-                                        ->dec('num', $value['return_num'])
-                                        ->update(['updatetime' => $date]);
+                                        ->findOrEmpty();
 
+                                    $tmp['num'] -= $value['return_num'];
+                                    if ($tmp['num'] <= 0) {
+                                        $tmp['status'] = 4;
+                                        $tmp['is_del'] = 1;
+                                    }
 
+                                    //维护发货工单的数量
+                                    Db::name('order_out_child')
+                                        ->where(['id' => $tmp['id']])
+                                        ->update($tmp);
                                 }
                             }
                         }

+ 28 - 7
app/admin/controller/ReorderChild.php

@@ -88,7 +88,7 @@ class ReorderChild extends Base
                     'returnCode' => $param['returnCode'],
                     'outCode' => $param['outCode'],
                     'outChildCode' => $value['outChildCode'] ?? '',
-                    'order_out_child_status' =>isset($value['outChildCode'])?($orderOutChild[$value['outChildCode']]['status'] ?? 0) :0,
+                    'order_out_child_status' => isset($value['outChildCode']) ? ($orderOutChild[$value['outChildCode']]['status'] ?? 0) : 0,
                     'saleReturnChildCode' => substr(makeNo('KCC'), 0, -2) . str_pad($i++, 2, '0', STR_PAD_LEFT),
 //                    'type' => $param['type'],
                     'companyNo' => $saleReturn['companyNo'],
@@ -101,8 +101,8 @@ class ReorderChild extends Base
                     'addtime' => $date,
                     'updatetime' => $date,
                     'record' => '',
-                    'send_wsm_code' =>  isset($value['outChildCode'])?($orderOutChild[$value['outChildCode']]['wsm_code'] ?? ''):"",
-                    'send_num' =>  isset($value['outChildCode'])?($orderOutChild[$value['outChildCode']]['num'] ?? 0):"",
+                    'send_wsm_code' => isset($value['outChildCode']) ? ($orderOutChild[$value['outChildCode']]['wsm_code'] ?? '') : "",
+                    'send_num' => isset($value['outChildCode']) ? ($orderOutChild[$value['outChildCode']]['num'] ?? 0) : "",
                     'return_num' => $value['return_num'],
                     'return_wsm_code' => $value['return_wsm_code'],
                     'good_receive_type' => 0,
@@ -207,7 +207,7 @@ class ReorderChild extends Base
             'remark|备注' => 'max:255'
         ]);
 
-        if ($val->check($param)==false) return json_show(1004, $val->getError());
+        if ($val->check($param) == false) return json_show(1004, $val->getError());
 
         $info = Db::name('sale_return_child')
             ->alias('a')
@@ -344,10 +344,31 @@ class ReorderChild extends Base
             }
 
             //发货工单数量减少
-            Db::name('order_out_child')
+            $tmp = Db::name('order_out_child')
                 ->where(['is_del' => 0, 'outChildCode' => $info['outChildCode']])
-                ->dec('num', $info['return_num'])
-                ->update(['updatetime' => $date]);
+                ->field('id,num')
+                ->findOrEmpty();
+            $tmp['num'] -= $info['return_num'];
+            $tmp['updatetime'] = $date;
+            if ($tmp['num'] <= 0) $tmp['is_del'] = 1;
+
+            Db::name('order_out_child')
+                ->where(['is_del' => 0, 'id' => $tmp['id']])
+                ->update($tmp);
+
+            //维护发货单
+            $temp = Db::name('order_out')
+                ->field('id,send_num')
+                ->where(['is_del' => 0, 'outCode' => $info['outCode']])
+                ->findOrEmpty();
+
+            $temp['send_num'] -= $info['return_num'];
+            $temp['updatetime'] = $date;
+            if ($temp['send_num'] <= 0) $temp['is_del'] = 1;
+
+            Db::name('order_out')
+                ->where('id', $temp['id'])
+                ->update($temp);
 
             //维护bn
             if ($info['order_out_status'] == 1) {