Browse Source

售前退货单有地址时优化

wufeng 2 years ago
parent
commit
c9951c8425
1 changed files with 76 additions and 76 deletions
  1. 76 76
      app/admin/controller/Reorder.php

+ 76 - 76
app/admin/controller/Reorder.php

@@ -141,73 +141,73 @@ class Reorder extends Base
                 Db::execute("UPDATE `wsm_standing_book` SET `returnGoodCode`=CONCAT(IFNULL(`returnGoodCode`,''),',{$returnCode}'),`updatetime`='" . $date . "' WHERE `orderCode`='{$ordeCode}'");
 
                 //如果有退货地址,那么可能有发货单,可能有发货工单
-//                if ($returnadr != "") {
-//                    $inf = [];
-//                    foreach ($returnadr as $val) {
-//
-//                        if ($val['return_num'] == 0) continue;//当退货数量为0时,跳过
-//
-//                        $temp = [];
-//                        $addrinfo = Db::name("order_addr")->where(['id' => $val['id'], "orderCode" => $ordeCode])->findOrEmpty();
-//                        if ($addrinfo == false) throw new Exception("地址信息未找到");
-//
-//                        $send = Db::name('order_out')->where([["addrid", "=", $val['id']]])->findOrEmpty();
-//                        if ($send['status'] >= 2) throw new Exception("地址已发货");
-//
-//                        if ($order['is_stock'] == 1) {
-//                            if ($addrinfo['receipt_quantity'] < $val['return_num']) throw new Exception("地址发货数量不足");
-//
-//                            $addrinfo['receipt_quantity'] -= $val['return_num'];
-//                            $addrinfo['is_del'] = $addrinfo['receipt_quantity'] <= 0 ? 1 : 0;
-//                            $addrinfo['updatetime'] = $date;
-//                            $addrup = Db::name("order_addr")->save($addrinfo);
-//                            if ($addrup == false) throw new Exception("地址发货数量更新失败");
-//
-//                            $out = Db::name("order_out")->where(["addrid" => $val['id']])->findOrEmpty();
-//                            if ($out == false) throw new Exception("地址发货单数据未找到");
-//
-////                                if ($send!=false) {
-//                            if ($out['status'] >= 2) throw new Exception("地址发货单已发货");
-//
-//                            if ($out['send_num'] < $val['return_num']) throw new Exception("地址发货单发货数量不足");
-//
-//                            $out['send_num'] -= $val['return_num'];
-//                            $out['is_del'] = $out['send_num'] == 0 ? 1 : 0;
-//                            $out['updatetime'] = $date;
-//                            $outup = Db::name("order_out")->save($out);
-//                            if ($outup == false) throw new Exception("地址发货单更新失败");
-//
-//
-////                                    $ordersend = Db::name("order_send")->where(["outCode" => $out['outCode']])->find();
-////                                    if ($ordersend['send_num'] < $val['return_num']) {
-////                                        Db::rollback();
-////                                        return json_show(1004, "发货单发货数量不足");
-////                                    }
-////                                    $ordersend['send_num'] -= $val['return_num'];
-////                                    $ordersend['status'] = $ordersend['send_num'] <= 0 ? 0 : 1;
-////                                    $ordersend['updatetime'] = $date;
-////                                    $sendip = Db::name("order_send")->save($ordersend);
-////                                    if ($sendip == false) {
-////                                        Db::rollback();
-////                                        return json_show(1004, "发货单更新失败");
-////                                    }
-//
-////                                }
-//                        }
-//                        $temp['returnCode'] = $returnCode;
-//                        $temp['orderCode'] = $ordeCode;
-//                        $temp['outCode'] = isset($send['outCode']) ? $send['outCode'] : "";
-//                        $temp['addrid'] = $val['id'];
-//                        $temp['send_num'] = $addrinfo['receipt_quantity'];
-//                        $temp['return_num'] = $val['return_num'];
-//                        $temp['is_del'] = 0;
-//                        $temp['addtime'] = $date;
-//                        $temp['updatetime'] = $date;
-//                        $inf[] = $temp;
-//                    }
-//                    $inadd = Db::name("sale_returnaddr")->insertAll($inf);
-//                    if ($inadd == 0) throw new Exception("退货单新建失败");
-//                }
+                if ($returnadr != "") {
+                    $inf = [];
+                    foreach ($returnadr as $val) {
+
+                        if ($val['return_num'] == 0) continue;//当退货数量为0时,跳过
+
+                        $temp = [];
+                        $addrinfo = Db::name("order_addr")->where(['id' => $val['id'], "orderCode" => $ordeCode])->findOrEmpty();
+                        if ($addrinfo == false) throw new Exception("地址信息未找到");
+
+                        $send = Db::name('order_out')->where([["addrid", "=", $val['id']]])->findOrEmpty();
+                        if ($send['status'] >= 2) throw new Exception("地址已发货");
+
+                        if ($order['is_stock'] == 1) {
+                            if ($addrinfo['receipt_quantity'] < $val['return_num']) throw new Exception("地址发货数量不足");
+
+                            $addrinfo['receipt_quantity'] -= $val['return_num'];
+                            $addrinfo['is_del'] = $addrinfo['receipt_quantity'] <= 0 ? 1 : 0;
+                            $addrinfo['updatetime'] = $date;
+                            $addrup = Db::name("order_addr")->save($addrinfo);
+                            if ($addrup == false) throw new Exception("地址发货数量更新失败");
+
+                            $out = Db::name("order_out")->where(["addrid" => $val['id']])->findOrEmpty();
+                            if ($out == false) throw new Exception("地址发货单数据未找到");
+
+//                                if ($send!=false) {
+                            if ($out['status'] >= 2) throw new Exception("地址发货单已发货");
+
+                            if ($out['send_num'] < $val['return_num']) throw new Exception("地址发货单发货数量不足");
+
+                            $out['send_num'] -= $val['return_num'];
+                            $out['is_del'] = $out['send_num'] == 0 ? 1 : 0;
+                            $out['updatetime'] = $date;
+                            $outup = Db::name("order_out")->save($out);
+                            if ($outup == false) throw new Exception("地址发货单更新失败");
+
+
+//                                    $ordersend = Db::name("order_send")->where(["outCode" => $out['outCode']])->find();
+//                                    if ($ordersend['send_num'] < $val['return_num']) {
+//                                        Db::rollback();
+//                                        return json_show(1004, "发货单发货数量不足");
+//                                    }
+//                                    $ordersend['send_num'] -= $val['return_num'];
+//                                    $ordersend['status'] = $ordersend['send_num'] <= 0 ? 0 : 1;
+//                                    $ordersend['updatetime'] = $date;
+//                                    $sendip = Db::name("order_send")->save($ordersend);
+//                                    if ($sendip == false) {
+//                                        Db::rollback();
+//                                        return json_show(1004, "发货单更新失败");
+//                                    }
+
+//                                }
+                        }
+                        $temp['returnCode'] = $returnCode;
+                        $temp['orderCode'] = $ordeCode;
+                        $temp['outCode'] = isset($send['outCode']) ? $send['outCode'] : "";
+                        $temp['addrid'] = $val['id'];
+                        $temp['send_num'] = $addrinfo['receipt_quantity'];
+                        $temp['return_num'] = $val['return_num'];
+                        $temp['is_del'] = 0;
+                        $temp['addtime'] = $date;
+                        $temp['updatetime'] = $date;
+                        $inf[] = $temp;
+                    }
+                    $inadd = Db::name("sale_returnaddr")->insertAll($inf);
+                    if ($inadd == 0) throw new Exception("退货单新建失败");
+                }
 
                 if ($in['status'] == 4 && $order['is_stock'] == 1) {
 
@@ -1863,22 +1863,22 @@ class Reorder extends Base
 
         if ($val->check($param) == false) return json_show(1004, $val->getError());
 
-        $sale_return = Db::name('sale_return')
-            ->field('id,orderCode')
-            ->where(['is_del' => 0, 'returnCode' => $param['returnCode']])
-            ->findOrEmpty();
-        if (empty($sale_return)) return json_show(1004, '该售后申请单不存在');
+//        $sale_return = Db::name('sale_return')
+//            ->field('id,orderCode')
+//            ->where(['is_del' => 0, 'returnCode' => $param['returnCode']])
+//            ->findOrEmpty();
+//        if (empty($sale_return)) return json_show(1004, '该售后申请单不存在');
 
-        $where = ['a.is_del' => 0, 'a.orderCode' => $sale_return['orderCode']];
-        $count = Db::name('order_out')
+        $where = ['a.is_del' => 0, 'a.returnCode' => $param['returnCode']];
+        $count = Db::name('sale_returnaddr')
             ->alias('a')
             ->leftJoin('order_addr b', 'b.id=a.addrid and b.is_del=0')
             ->where($where)
             ->count('a.id');
 
-        $list = Db::name('order_out')
+        $list = Db::name('sale_returnaddr')
             ->alias('a')
-            ->field('a.id,a.outCode,a.send_num,b.contactor,b.mobile,b.addr_code,b.addr,"" addr_code_cn')
+            ->field('a.id,a.outCode,a.send_num,a.return_num,b.contactor,b.mobile,b.addr_code,b.addr,"" addr_code_cn')
             ->leftJoin('order_addr b', 'b.id=a.addrid and b.is_del=0')
             ->where($where)
             ->order(['a.addtime' => 'desc', 'a.id' => 'desc'])