Browse Source

售前退货优化

wufeng 2 years ago
parent
commit
77ee814ff8
1 changed files with 45 additions and 34 deletions
  1. 45 34
      app/admin/controller/ReorderChild.php

+ 45 - 34
app/admin/controller/ReorderChild.php

@@ -43,7 +43,7 @@ class ReorderChild extends Base
             //所有发货工单
             $orderOutChild = Db::name('order_out_child')
                 ->where(['is_del' => 0, 'outChildCode' => array_unique(array_column($param['list'], 'outChildCode'))])
-                ->column('outCode,wsm_code,num,status', 'outChildCode');
+                ->column('id,outCode,wsm_code,num,status', 'outChildCode');
 
             $saleReturnAddr = Db::name('sale_returnaddr')
                 ->field('id,return_num,is_sale_return_child')
@@ -138,6 +138,13 @@ class ReorderChild extends Base
                     'holder_id' => $this->uid
                 ]);
 
+                //维护发货工单
+                Db::name('order_out_child')
+                    ->data(['updatetime' => $date])
+                    ->dec('num', $value['return_num'])
+                    ->where('id', $orderOutChild[$value['outChildCode']]['id'])
+                    ->update();
+
                 if ($param['outCode'] != '') {
                     //维护发货单和发货工单
                     $addrinfo = Db::name("order_addr")
@@ -159,7 +166,7 @@ class ReorderChild extends Base
                     $out_code_info['is_del'] = $out_code_info['send_num'] == 0 ? 1 : 0;
                     $out_code_info['updatetime'] = $date;
                     $outup = Db::name("order_out")->save($out_code_info);
-                    if ($outup == false) throw new Exception("地址发货单更新失败");
+                    if ($outup == false) throw new Exception("发货单更新失败");
                 }
             }
 
@@ -435,6 +442,9 @@ class ReorderChild extends Base
                                     'updatetime' => $date,
                                     'status' => 0,
                                     'is_stock' => 1,
+                                    'status' => 7,
+                                    'createrid' => 0,
+                                    'creater' => 'system',
                                 ]));
                             }
                         } else {
@@ -496,9 +506,9 @@ class ReorderChild extends Base
                                     'nake_price' => 0,
                                     'is_step' => 0,
                                     'is_online' => 0,
-                                    'status' => 0,
-                                    'createrid' => $good['createrid'],
-                                    'creater' => $good['creater'],
+                                    'status' => 7,
+                                    'createrid' => 0,
+                                    'creater' => 'system',
                                     'field_change' => '',
                                     'is_del' => 0,
                                     'addtime' => $date,
@@ -603,36 +613,37 @@ class ReorderChild extends Base
                 }
             }
 
+            //在创建退货工单的时候,已经减掉了,这里不用重复减了
             //有地址就会有发货单,继而有发货工单
-            if ($info['is_addr'] == 1) {
-                //发货工单数量减少
-                $tmp = Db::name('order_out_child')
-                    ->where(['is_del' => 0, 'outChildCode' => $info['outChildCode']])
-                    ->field('id,num')
-                    ->findOrEmpty();
-                halt($info['outChildCode']);
-                $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);
-            }
+//            if ($info['is_addr'] == 1) {
+//                //发货工单数量减少
+//                $tmp = Db::name('order_out_child')
+//                    ->where(['is_del' => 0, 'outChildCode' => $info['outChildCode']])
+//                    ->field('id,num')
+//                    ->findOrEmpty();
+//
+//                $tmp['num'] -= $info['return_num'];   halt($tmp);
+//                $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