Browse Source

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

wufeng 2 năm trước cách đây
mục cha
commit
1b138d66a4
2 tập tin đã thay đổi với 205 bổ sung162 xóa
  1. 160 161
      app/admin/controller/Reorder.php
  2. 45 1
      app/admin/controller/ReorderChild.php

+ 160 - 161
app/admin/controller/Reorder.php

@@ -873,40 +873,40 @@ class Reorder extends Base
                 $ste = ["order_code" => $code, "status" => $temp, "action_remark" => '', "action_type" => "status"];
                 ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $ste, "XSTHD", $status, $info);
                 if ($status == 4) {
-                    if ($info['is_addr'] == 1) {
-                        if (isset($addr) && !empty($addr)) {
-                            foreach ($addr as $value) {
-                                $addrinfo = Db::name("order_addr")
-                                    ->where(['id' => $value['addrid'], "is_del" => 0])
-                                    ->findOrEmpty();
-                                if (empty($addrinfo)) throw new Exception("地址数据未找到");
-
-                                if ($addrinfo['receipt_quantity'] < $value['return_num']) throw new Exception("地址发货数量不足");
-
-                                $addrinfo['receipt_quantity'] -= $value['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('地址发货数量更新失败');
-
-                                if ($value['outCode'] != "") {
-                                    $out = Db::name("order_out")->where(["outCode" => $value['outCode']])->findOrEmpty();
-                                    if (empty($out)) throw new Exception('地址发货单数据未找到');
-
-                                    if ($out['status'] >= 2) throw new Exception('地址发货单已发货');
-
-                                    if ($out['send_num'] < $value['return_num']) throw new Exception('地址发货单发货数量不足');
-
-                                    $out['send_num'] -= $value['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('地址发货单更新失败');
-
-                                }
-                            }
-                        }
-                    }
+//                    if ($info['is_addr'] == 1) {
+//                        if (isset($addr) && !empty($addr)) {
+//                            foreach ($addr as $value) {
+//                                $addrinfo = Db::name("order_addr")
+//                                    ->where(['id' => $value['addrid'], "is_del" => 0])
+//                                    ->findOrEmpty();
+//                                if (empty($addrinfo)) throw new Exception("地址数据未找到");
+//
+//                                if ($addrinfo['receipt_quantity'] < $value['return_num']) throw new Exception("地址发货数量不足");
+//
+//                                $addrinfo['receipt_quantity'] -= $value['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('地址发货数量更新失败');
+//
+//                                if ($value['outCode'] != "") {
+//                                    $out = Db::name("order_out")->where(["outCode" => $value['outCode']])->findOrEmpty();
+//                                    if (empty($out)) throw new Exception('地址发货单数据未找到');
+//
+//                                    if ($out['status'] >= 2) throw new Exception('地址发货单已发货');
+//
+//                                    if ($out['send_num'] < $value['return_num']) throw new Exception('地址发货单发货数量不足');
+//
+//                                    $out['send_num'] -= $value['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('地址发货单更新失败');
+//
+//                                }
+//                            }
+//                        }
+//                    }
 
                     if ($orderinfo['wsend_num'] < $info['num']) throw new Exception('销售单未发货数量不足退货');
 
@@ -1453,7 +1453,6 @@ class Reorder extends Base
 //        }
         $userCommon = \app\admin\common\User::getIns();
         $tmp = $userCommon->handle('sInfo', ['code' => $goon['supplierNo']]);
-        if (!isset($tmp['code']) || $tmp['code'] != 0) return json_show($tmp['code'], $tmp['message'], $tmp['data']);
         $supplier = $tmp['data'];
         if (empty($supplier)) return json_show(1005, "未找到商品供应商数据");
 
@@ -1523,72 +1522,72 @@ class Reorder extends Base
                 ProcessOrder::AddProcess(["id" => $this->uid, "nickname" => $this->uname], $process);
                 //维护台账信息
                 Db::execute("UPDATE `wsm_standing_book` SET `returnGoodCode`=CONCAT(IFNULL(`returnGoodCode`,''),',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `orderCode`='{$orderCode}'");
-                if (count($addr) != 0) {
-                    $inf = [];
-                    foreach ($addr as $val) {
-                        if ($val['receipt_quantity'] == 0) continue;//当退货数量为0时,跳过
-
-                        $temp = [];
-                        $send = Db::name('order_out')->where([["addrid", "=", $val['id']]])->find();
-                        if ($send == false) throw new Exception("地址发货单未找到");
-
-                        if ($send['status'] >= 2) throw new Exception("地址已发货");
-
-
-                        if ($order['is_stock'] == 1) {
-
-                            $val['is_del'] = 1;
-                            $val['updatetime'] = date("Y-m-d H:i:s");
-                            $addrup = Db::name("order_addr")->save($val);
-                            if ($addrup == false) throw new Exception("地址更新失败");
-
-
-                            $send['is_del'] = 1;
-                            $send['remark'] = '全退';
-                            $send['updatetime'] = date("Y-m-d H:i:s");
-                            $outup = Db::name("order_out")->save($send);
-                            if ($outup == false) throw new Exception("地址发货单更新失败");
-
-
-                            //处理发货申请单流程
-                            ProcessOrder::AddProcess(["id" => $this->uid, "nickname" => $this->uname], [
-                                "order_type" => 'CKD',
-                                "order_code" => $send["outCode"],//出库单号
-                                "order_id" => $send["id"],
-                                "order_status" => 4,//全部退货
-                                "before_status" => $send['status'],
-                                'holder_id=' => $send['apply_id']
-                            ]);
-//                                    $ordersend = Db::name("order_send")->where(["outCode" => $send['outCode']])->find();
-//                                    if($ordersend==false){
-//                                    	Db::rollback();
-//                                        return json_show(1004, "发货单关联数据未找到");
-//                                    }
-//                                    $ordersend['status'] = 0;
-//                                    $ordersend['updatetime'] = date("Y-m-d H:i:s");
-//                                    $sendip = Db::name("order_send")->save($ordersend);
-//                                    if ($sendip == false) {
-//                                        Db::rollback();
-//                                        return json_show(1004, "发货单更新失败");
-//                                    }
-                        }
-                        $temp['returnCode'] = $returnCode;
-                        $temp['orderCode'] = $orderCode;
-                        $temp['outCode'] = isset($send['outCode']) ? $send['outCode'] : "";
-                        $temp['addrid'] = $val['id'];
-                        $temp['send_num'] = $val['receipt_quantity'];
-                        $temp['return_num'] = $val['receipt_quantity'];
-                        $temp['is_del'] = 0;
-                        $temp['addtime'] = date("Y-m-d H:i:s");
-                        $temp['updatetime'] = date("Y-m-d H:i:s");
-                        $inf[] = $temp;
-                    }
-                    $inadd = Db::name("sale_returnaddr")->insertAll($inf);
-                    if ($inadd == 0) throw new Exception("退货单新建失败");
-
-                }
+//                if (count($addr) != 0) {
+//                    $inf = [];
+//                    foreach ($addr as $val) {
+//                        if ($val['receipt_quantity'] == 0) continue;//当退货数量为0时,跳过
+//
+//                        $temp = [];
+//                        $send = Db::name('order_out')->where([["addrid", "=", $val['id']]])->find();
+//                        if ($send == false) throw new Exception("地址发货单未找到");
+//
+//                        if ($send['status'] >= 2) throw new Exception("地址已发货");
+//
+//
+//                        if ($order['is_stock'] == 1) {
+//
+//                            $val['is_del'] = 1;
+//                            $val['updatetime'] = date("Y-m-d H:i:s");
+//                            $addrup = Db::name("order_addr")->save($val);
+//                            if ($addrup == false) throw new Exception("地址更新失败");
+//
+//
+//                            $send['is_del'] = 1;
+//                            $send['remark'] = '全退';
+//                            $send['updatetime'] = date("Y-m-d H:i:s");
+//                            $outup = Db::name("order_out")->save($send);
+//                            if ($outup == false) throw new Exception("地址发货单更新失败");
+//
+//
+//                            //处理发货申请单流程
+//                            ProcessOrder::AddProcess(["id" => $this->uid, "nickname" => $this->uname], [
+//                                "order_type" => 'CKD',
+//                                "order_code" => $send["outCode"],//出库单号
+//                                "order_id" => $send["id"],
+//                                "order_status" => 4,//全部退货
+//                                "before_status" => $send['status'],
+//                                'holder_id=' => $send['apply_id']
+//                            ]);
+////                                    $ordersend = Db::name("order_send")->where(["outCode" => $send['outCode']])->find();
+////                                    if($ordersend==false){
+////                                    	Db::rollback();
+////                                        return json_show(1004, "发货单关联数据未找到");
+////                                    }
+////                                    $ordersend['status'] = 0;
+////                                    $ordersend['updatetime'] = date("Y-m-d H:i:s");
+////                                    $sendip = Db::name("order_send")->save($ordersend);
+////                                    if ($sendip == false) {
+////                                        Db::rollback();
+////                                        return json_show(1004, "发货单更新失败");
+////                                    }
+//                        }
+//                        $temp['returnCode'] = $returnCode;
+//                        $temp['orderCode'] = $orderCode;
+//                        $temp['outCode'] = isset($send['outCode']) ? $send['outCode'] : "";
+//                        $temp['addrid'] = $val['id'];
+//                        $temp['send_num'] = $val['receipt_quantity'];
+//                        $temp['return_num'] = $val['receipt_quantity'];
+//                        $temp['is_del'] = 0;
+//                        $temp['addtime'] = date("Y-m-d H:i:s");
+//                        $temp['updatetime'] = date("Y-m-d H:i:s");
+//                        $inf[] = $temp;
+//                    }
+//                    $inadd = Db::name("sale_returnaddr")->insertAll($inf);
+//                    if ($inadd == 0) throw new Exception("退货单新建失败");
+//
+//                }
 
-                if ($order['is_stock'] == 1) {
+                if ($in['status'] == 4 && $order['is_stock'] == 1) {
                     $lor = $order['status'];
                     $thnum = $order['wsend_num'];
                     $order['send_num'] += $thnum;
@@ -1617,67 +1616,67 @@ class Reorder extends Base
                         'holder_id=' => $order['apply_id']
                     ]);
 
-                    $saleinfo = Db::name("sale_info")->where([["orderCode", "=", $orderCode], ["num", ">", 0]])->select()->toArray();
-                    if (empty($saleinfo)) {
-                        $ordernum = Db::name("order_num")->where(['orderCode' => $orderCode])->findOrEmpty();
-                        if (empty($ordernum)) throw new Exception('未找到关联采购单');
-
-                        $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->findOrEmpty();
-                        if (empty($cgd)) throw new Exception('未找到采购单数据');
-
-                        $bn = makeNo("BN");
-                        $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'wsm_code' => $cgd['wsm_code'], "is_del" => 0, "status" => 1])->find();
-                        if ($stock == false) throw new Exception('商品库存数据未找到');
-
-                        $stock['usable_stock'] += $thnum;
-                        $stock['wait_out_stock'] -= $thnum;
-                        $stock['updatetime'] = date("Y-m-d H:i:s");
-                        $st_up = Db::name("good_stock")->save($stock);
-                        if ($st_up == false) throw new Exception('可售商品入库失败');
-
-                        $yp = GoodStockInfo::AddBn($stock['id'], $bn, $thnum, $cgd['good_price']);
-                        if ($yp == false) throw new Exception('商品批次退货入库失败');
-
-
-                    } else {
-                        $tempnum = $thnum;
-                        foreach ($saleinfo as $va) {
-                            if ($tempnum == 0) break;
-                            $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'id' => $va['stockid']])->findOrEmpty();
-                            if ($stock == false) throw new Exception('商品库存数据未找到');
-
-                            if ($va['num'] >= $tempnum) {
-                                $tnm = $tempnum;
-                                $va['num'] -= $tempnum;
-                                $va['th_num'] += $tempnum;
-                                $tempnum = 0;
-                            } else {
-                                $tnm = $va['num'];
-                                $tempnum -= $va['num'];
-                                $va['th_num'] += $va['num'];
-                                $va['num'] = 0;
-                            }
-                            $stock['usable_stock'] += $tnm;
-                            $stock['wait_out_stock'] -= $tnm;
-                            $stock['updatetime'] = date("Y-m-d H:i:s");
-                            $st_up = Db::name("good_stock")->save($stock);
-                            if ($st_up == false) throw new Exception('可售商品入库失败');
-
-                            $ps = GoodStockInfo::AddBn($va['stockid'], $va['bnCode'], $tnm);
-                            if ($ps == false) throw new Exception('商品批次退货入库失败');
-
-                            $ret = GoodStockInfo::ReturnBn($returnCode, $va['id'], $tnm);
-                            if ($ret == false) throw new Exception('商品批次退货入库失败');
-
-                            $va['updatetime'] = date("Y-m-d H:i:s");
-                            $sal = Db::name("sale_info")->save($va);
-                            if ($sal == false) throw new Exception('商品批次退货入库失败');
-
-                            $good_data[] = ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 1, 'stock' => $tnm, "stock_name" => "usable_stock"];
-                            $good_data[] = ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 2, 'stock' => $tnm, "stock_name" => "wait_out_stock"];
-                            GoodLog::LogAdd(['id' => $this->uid, 'nickname' => $this->uname], $good_data, 'XSTHD');
-                        }
-                    }
+//                    $saleinfo = Db::name("sale_info")->where([["orderCode", "=", $orderCode], ["num", ">", 0]])->select()->toArray();
+//                    if (empty($saleinfo)) {
+//                        $ordernum = Db::name("order_num")->where(['orderCode' => $orderCode])->findOrEmpty();
+//                        if (empty($ordernum)) throw new Exception('未找到关联采购单');
+//
+//                        $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->findOrEmpty();
+//                        if (empty($cgd)) throw new Exception('未找到采购单数据');
+//
+//                        $bn = makeNo("BN");
+//                        $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'wsm_code' => $cgd['wsm_code'], "is_del" => 0, "status" => 1])->find();
+//                        if ($stock == false) throw new Exception('商品库存数据未找到');
+//
+//                        $stock['usable_stock'] += $thnum;
+//                        $stock['wait_out_stock'] -= $thnum;
+//                        $stock['updatetime'] = date("Y-m-d H:i:s");
+//                        $st_up = Db::name("good_stock")->save($stock);
+//                        if ($st_up == false) throw new Exception('可售商品入库失败');
+//
+//                        $yp = GoodStockInfo::AddBn($stock['id'], $bn, $thnum, $cgd['good_price']);
+//                        if ($yp == false) throw new Exception('商品批次退货入库失败');
+//
+//
+//                    } else {
+//                        $tempnum = $thnum;
+//                        foreach ($saleinfo as $va) {
+//                            if ($tempnum == 0) break;
+//                            $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'id' => $va['stockid']])->findOrEmpty();
+//                            if ($stock == false) throw new Exception('商品库存数据未找到');
+//
+//                            if ($va['num'] >= $tempnum) {
+//                                $tnm = $tempnum;
+//                                $va['num'] -= $tempnum;
+//                                $va['th_num'] += $tempnum;
+//                                $tempnum = 0;
+//                            } else {
+//                                $tnm = $va['num'];
+//                                $tempnum -= $va['num'];
+//                                $va['th_num'] += $va['num'];
+//                                $va['num'] = 0;
+//                            }
+//                            $stock['usable_stock'] += $tnm;
+//                            $stock['wait_out_stock'] -= $tnm;
+//                            $stock['updatetime'] = date("Y-m-d H:i:s");
+//                            $st_up = Db::name("good_stock")->save($stock);
+//                            if ($st_up == false) throw new Exception('可售商品入库失败');
+//
+//                            $ps = GoodStockInfo::AddBn($va['stockid'], $va['bnCode'], $tnm);
+//                            if ($ps == false) throw new Exception('商品批次退货入库失败');
+//
+//                            $ret = GoodStockInfo::ReturnBn($returnCode, $va['id'], $tnm);
+//                            if ($ret == false) throw new Exception('商品批次退货入库失败');
+//
+//                            $va['updatetime'] = date("Y-m-d H:i:s");
+//                            $sal = Db::name("sale_info")->save($va);
+//                            if ($sal == false) throw new Exception('商品批次退货入库失败');
+//
+//                            $good_data[] = ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 1, 'stock' => $tnm, "stock_name" => "usable_stock"];
+//                            $good_data[] = ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 2, 'stock' => $tnm, "stock_name" => "wait_out_stock"];
+//                            GoodLog::LogAdd(['id' => $this->uid, 'nickname' => $this->uname], $good_data, 'XSTHD');
+//                        }
+//                    }
 
 //                    $data=[
 //                        "orderCode"=>$orderCode,

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

@@ -3,6 +3,8 @@
 namespace app\admin\controller;
 
 //销售单退货工单
+use app\admin\model\ActionLog;
+use app\admin\model\ProcessOrder;
 use think\Exception;
 use think\facade\Db;
 use think\facade\Validate;
@@ -159,9 +161,10 @@ class ReorderChild extends Base
 
         $info = Db::name('sale_return_child')
             ->alias('a')
-            ->field('a.id,a.num,a.status,a.returnCode,a.outChildCode,a.return_num,a.return_wsm_code,a.orderCode,a.outCode,b.good_code spuCode,c.status order_out_status')
+            ->field('a.id,a.num,a.status,a.returnCode,a.outChildCode,a.return_num,a.return_wsm_code,a.orderCode,a.outCode,b.good_code spuCode,c.status order_out_status,b.id saleid,d.num thnum')
             ->leftJoin('sale b', 'b.orderCode=a.orderCode')
             ->leftJoin('order_out_child c', 'c.outChildCode=a.outChildCode AND c.is_del=0')
+            ->leftJoin('sale_return d', 'd.returnCode=a.returnCode')
             ->where(['a.is_del' => 0, 'a.id' => $param['id']])
             ->findOrEmpty();
         if (empty($info)) return json_show(1004, '该退货工单不存在');
@@ -195,6 +198,46 @@ class ReorderChild extends Base
                 Db::name('sale_return')
                     ->where(['is_del' => 0, 'returnCode' => $info['returnCode'], 'status' => 12])
                     ->update(['status' => 4, 'updatetime' => $date]);
+
+                //维护销售单
+                $order = Db::name('sale')->where(['is_del' => 0, 'id' => $info['saleid']])->findOrEmpty();
+                //未发货数量要减去发货单上的发货数量
+                $out_send_num = Db::name('order_out')
+                    ->where(['is_del' => 0, 'orderCode' => $info['orderCode'], 'status' => [0, 1]])
+                    ->sum('send_num');
+
+                $order['wsend_num'] -= $out_send_num;
+
+                $thnum = $info['thnum'];//退货总数量
+                if ($order['wsend_num'] < $thnum) throw new Exception("销售单未发货数量不足退货");
+
+                $lor = $order['status'];
+                $order['wsend_num'] -= $thnum;
+                $order['send_num'] += $thnum;
+                $order['status'] = $order['wsend_num'] == 0 ? 2 : ($order['send_num'] == 0 ? 0 : 1);
+                $order['send_status'] = $order['wsend_num'] == 0 ? 3 : ($order['send_num'] == 0 ? 1 : 2);
+                $order['th_num'] += $thnum;
+                if ($order['th_num'] == $order['send_num'] && $order['wsend_num'] == 0) {
+                    $order['status'] = 3;
+                }
+                $order['th_fee'] += round($thnum * $order['sale_price'], 2);
+                $order['updatetime'] = $date;
+                $uap = Db::name("sale")->save($order);
+                if ($uap == false) throw new Exception('销售单订单更新失败');
+
+                ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
+                    "order_code" => $order["orderCode"],//出库单号
+                    "status" => $lor,//这里的status是之前的值
+                    "action_remark" => '',//备注
+                    "action_type" => "status"//新建create,编辑edit,更改状态status
+                ], "XSQRD", $order['status'], $order);
+
+                ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
+                    "order_type" => 'XSQRD',
+                    "order_code" => $order["orderCode"],//出库单号
+                    "order_id" => $order["id"],
+                    "order_status" => $order['status'], "before_status" => $lor
+                ]);
             }
 
             //发货工单数量减少
@@ -217,6 +260,7 @@ class ReorderChild extends Base
                     ->update(['updatetime' => $date]);
             }
 
+
             Db::commit();
             return json_show(0, '设置退货工单成功');