wugg 2 年 前
コミット
d719185fe3

+ 313 - 310
app/admin/controller/After.php

@@ -90,7 +90,7 @@ class After extends Base
         } else {
             $goon = Db::name('good_platform')
                 ->alias('a')
-                ->field("b.creater,b.createrid,b.supplierNo")
+                ->field("b.creater,b.createrid,b.supplierNo,b.supplierName")
                 ->join('good b', 'b.spuCode=a.spuCode', 'left')
                 ->where(['a.skuCode' => $oder['skuCode']])
                 ->findOrEmpty();
@@ -109,7 +109,7 @@ class After extends Base
 //        if (!isset($supplier['code']) || $supplier['code'] != 0) return json_show($supplier['code'], $supplier['message'], $supplier['data']);
         $supplier = $supplier['data'];
 
-        $names = $userCommon->handle('getCodeAndName', ['code' => [$oder['customer_code'], $oder['supplierNo']]]);
+//        $names = $userCommon->handle('getCodeAndName', ['code' => [$oder['customer_code'], $oder['supplierNo']]]);
 
 //         $supplier =Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
 //        if($supplier==false){
@@ -157,11 +157,11 @@ class After extends Base
                 "good_code" => $oder['good_code'],
                 "good_name" => $oder['good_name'],
                 "customer_code" => $oder['customer_code'],
-                "customer_name" => $names['data'][$oder['customer_code']] ?? '',
+                "customer_name" =>$oder['customerName'],
                 "apply_id" => $rm,
                 "apply_name" => $ri,
                 'supplierNo' => $goon['supplierNo'],
-                'supplierName' => $supplier['name'],
+                'supplierName' => $goon['supplierName'],
                 "cgder" => $wsm['contactor_name'] ?? '',
                 "cgderid" => $wsm['contactor'] ?? 0,
                 "person" => $supplier['person'] ?? '',
@@ -177,7 +177,7 @@ class After extends Base
                 "except_code" => $param['except_code'],
                 "order_type" => $orderout['order_type'],
                 'companyNo' => $oder['supplierNo'],
-                'companyName' => $names['data'][$oder['supplierNo']] ?? '',
+                'companyName' => $oder['supplierName'],
                 "status" => 1,
                 "is_del" => 0,
                 "addtime" => date("Y-m-d H:i:s"),
@@ -213,13 +213,13 @@ class After extends Base
                 $process = ["order_code" => $returnCode, "order_id" => $create, "order_status" => $in['status'], "order_type" => 'SHD', "before_status" => 0, 'holder_id' => $in['apply_id']];
                 ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
                 Db::commit();
-                return app_show(0, "售后申请单新建成功", ["returnCode" => $returnCode]);
+                return json_show(0, "售后申请单新建成功", ["returnCode" => $returnCode]);
             }
             Db::rollback();
             return error_show(1005, "售后申请单新建失败");
-        } catch (Exception $e) {
+        } catch (Exception $exception) {
             Db::rollback();
-            return error_show(1005, $e->getMessage());
+            return json_show(1005, $exception->getMessage());
         }
     }
 
@@ -384,6 +384,8 @@ class After extends Base
 //        $info['supplierNo'] = $goon['supplierNo'];
 
         $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
+        $info['can'] = $int;
+
         $addcode = '';
         if ($info['addr_code'] != "") {
             list($a, $b, $c) = explode(",", $info['addr_code']);
@@ -401,27 +403,27 @@ class After extends Base
                 ->alias("a")
 //                ->leftJoin("supplier b", "a.supplierNo=b.code")
                 ->where(["a.wsm_code" => $info['return_wsm']])
-                ->field("a.name as wsm_name,a.wsm_code,a.contactor_name,a.position,a.mobile,a.addrs_code,a.addr,a.companyNo,a.supplierNo")
+//                ->field("a.name as wsm_name,a.wsm_code,a.contactor_name,a.position,a.mobile,a.addrs_code,a.addr,a.companyNo,a.supplierNo")
                 ->find();
 
         }
 
-        $userCommon = \app\admin\common\User::getIns();
-        $names = $userCommon->handle('getCodeAndName', ['code' => [
-            $wsmcode['supplierNo'] ?? '',
-            $wsmcode['companyNo'] ?? '',
-//            $info['customer_code'],
-//            $info['companyNo'],
-//            $info['supplierNo'],
-        ]]);
+//        $userCommon = \app\admin\common\User::getIns();
+//        $names = $userCommon->handle('getCodeAndName', ['code' => [
+//            $wsmcode['supplierNo'] ?? '',
+//            $wsmcode['companyNo'] ?? '',
+////            $info['customer_code'],
+////            $info['companyNo'],
+////            $info['supplierNo'],
+//        ]]);
 
         if ($info['return_wsm'] != '') {
             $info['wsm_supplierNo'] = $wsmcode['supplierNo'] ?? "";
-            $info['wsm_supplier'] = $names['data'][$wsmcode['supplierNo']] ?? '';//isset($wsmcode['name']) ? $wsmcode['name'] : "";
-            $info['wsm_customer_name'] = $names['data'][$wsmcode['companyNo']] ?? '';//isset($customer['company']) ? trim($customer['company']) : '';
+            $info['wsm_supplier'] = $wsmcode['supplierName'];//isset($wsmcode['name']) ? $wsmcode['name'] : "";
+            $info['wsm_customer_name'] = $wsmcode['companyName'];//isset($customer['company']) ? trim($customer['company']) : '';
             $info['wsm_customer_code'] = $wsmcode['companyNo'] ?? "";//isset($customer['companyNo']) ? trim($customer['companyNo']) : '';
             $info['wsm_code'] = isset($wsmcode['wsm_code']) ? $wsmcode['wsm_code'] : "";
-            $info['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
+            $info['wsm_name'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
         }
 
 //        $customer = [];
@@ -433,8 +435,6 @@ class After extends Base
 //        $info['companyName'] = $names['data'][$info['companyNo']] ?? '';
 //        $info['supplierName'] = $names['data'][$info['supplierNo']] ?? '';
 
-        $info['can'] = $int;
-
         //仓库的联系人、职位、电话、省市区和地址
         isset($wsmcode['contactor_name']) ? $info['contactor'] = $wsmcode['contactor_name'] : '';//联系人
         isset($wsmcode['mobile']) ? $info['mobile'] = $wsmcode['mobile'] : '';//电话
@@ -446,14 +446,15 @@ class After extends Base
 //        $info['addr'] = $wsmcode['addr'];//地址
         $info['spuCode'] = $orderinfo['good_code'];
         $info['skuCode'] = $orderinfo['skuCode'];
-        $info['return_tag'] = $info['return_tag'] == 0 ? "" : $info['return_tag'];//地址
-        $info['is_th'] = $info['is_th'] == 0 ? "" : $info['is_th'];//地址
+        $info['return_tag'] = $info['return_tag'] == 0 ? "" : $info['return_tag'];
+        $info['is_th'] = $info['is_th'] == 0 ? "" : $info['is_th'];
 
         return app_show(0, "获取成功", $info);
     }
 
     //售后申请单 审核
-    //申请单状态:1待业务审核,2待采购审核,3待设置仓库(该节点废除),4待客户退货,5售后已完成,6业务已驳回,7采购已驳回(该节点废除),8申请已取消,9供应商审核,10业务公司修改待供应商确认
+    //申请单状态:1待业务审核,2待采购审核,3待设置仓库(该节点废除),4待客户退货(已收到货才有),5售后已完成,6业务已驳回,7采购已驳回(该节点废除),8申请已取消,9供应商审核,10业务公司修改待供应商确认
+    //11待设置退货工单(已收到货才有),12待库管收货(已收到货才有)
     public function status()
     {
         try {
@@ -472,7 +473,7 @@ class After extends Base
 
             $val = Validate::rule([
                 'returnCode' => 'require',
-                'status' => 'require|number|in:1,2,4,5,6,9,10',
+                'status' => 'require|number|in:1,2,4,5,6,9,10,11',
                 'remark' => 'requireIf:status,6|requireIf:status,2|requireIf:status,10',
 //                'contactor|收货人' => 'requireIf:status,4',
 //                'mobile|联系电话' => 'requireIf:status,4',
@@ -500,7 +501,9 @@ class After extends Base
                     if (in_array($param['status'], [6, 9]) == false) throw new Exception('选项错误');
                     break;
                 case 9:
-                    if (in_array($param['status'], [2, 4, 5]) == false) throw new Exception('选项错误');
+                    if ((($info['is_receive'] == 1) && (in_array($param['status'], [2, 4]) == false) || (($info['is_receive'] == 0) && (in_array($param['status'], [2, 5]) == false)))) throw new Exception('选项错误');
+
+//                    if (in_array($param['status'], [2, 4, 5]) == false) throw new Exception('选项错误');
 //                    if ($this->level != 3) throw new Exception('当前状态下只能由供应商账号操作');
                     if ($param['status'] == 4) {
                         if ($param['contactor'] == '') throw new Exception('收货人不能为空');
@@ -510,22 +513,13 @@ class After extends Base
                     }
                     break;
                 case 2:
-                    if (in_array($param['status'], [10, 4, 5]) == false) throw new Exception('选项错误');
-                    if ($param['status'] == 4) {
-                        if ($param['wsm_code'] == '') throw new Exception('请填写退回仓库');
-                        else {
-                            $ware = Db::name('warehouse_info')
-                                ->field('contactor_name contactor,mobile,addr,addrs_code addr_code')
-                                ->where(['wsm_code' => $param['wsm_code'], 'is_del' => 0])
-                                ->findOrEmpty();
-                            if (empty($ware)) throw new Exception('该仓库不存在');
-                            else $param = array_merge($param, $ware);
-                        }
-                    }
+
+                    if ((($info['is_receive'] == 1) && (in_array($param['status'], [10, 11]) == false) || (($info['is_receive'] == 0) && (in_array($param['status'], [10, 5]) == false)))) throw new Exception('选项错误');
 
                     break;
                 case 10:
-                    if (in_array($param['status'], [2, 4, 5]) == false) throw new Exception('选项错误');
+                    if ((($info['is_receive'] == 1) && (in_array($param['status'], [2, 4]) == false) || (($info['is_receive'] == 0) && (in_array($param['status'], [2, 5]) == false)))) throw new Exception('选项错误');
+
                     if ($param['status'] == 4) {
                         if ($param['contactor'] == '') throw new Exception('收货人不能为空');
                         if ($param['mobile'] == '') throw new Exception('联系电话不能为空');
@@ -573,7 +567,7 @@ class After extends Base
 
                 //判断 退回供应商 or 退回业务公司
                 if ($info['status'] == 9) {
-                    if ($param['status'] == 4) $info['return_tag'] = 1;
+                    if (in_array($param['status'],[4,5])) $info['return_tag'] = 1;
                     else $info['return_tag'] = 2;
                 }
 
@@ -1317,8 +1311,17 @@ class After extends Base
                 ->update($returninfo);
 
             if ($up) {
+
+                //查看是否有退货工单
+                $temp = Db::name('order_return_child')
+                    ->field('id')
+                    ->where(['is_del' => 0, 'returnCode' => $bkcode])
+                    ->findOrEmpty();
+                if (empty($temp)) $info['status'] = 5;//没有退货工单,更新到status5,售后申请已结束
+                else $info['status'] = 12;//存在退货工单,要更新到status12(待库管收货)
+
                 $old_info_status = $info['status'];
-                $info['status'] = 5;
+//                $info['status'] = 5;
                 $info['updatetime'] = date("y-m-d H:i:s");
                 $ro = Db::name("order_return")->save($info);
                 if ($ro) {
@@ -1341,281 +1344,281 @@ class After extends Base
                     ]);
 
                     //售后退货单数据
-                    $thNo = makeNo("ST");
-                    $thdata = [
-                        "thNo" => $thNo,
-                        "orderCode" => $out["orderCode"],
-                        "outCode" => $out["outCode"],
-                        "order_type" => $info["order_type"],
-                        "returnCode" => $info["returnCode"],
-                        "good_code" => $info["good_code"],
-                        "good_name" => $info["good_name"],
-                        "return_wsm" => $returninfo["return_wsm"],
-                        "total_fee" => round($sale['sale_price'] * $info["error_num"], 2),
-                        "good_price" => $sale['sale_price'],
-                        "platform_id" => $sale['platform_id'],
-                        "return_msg" => $info["error_msg"],
-                        "return_num" => $info["error_num"],
-                        "normal_num" => 0,
-                        "received_num" => 0,
-                        "apply_id" => $info['apply_id'],
-                        "apply_name" => $info['apply_name'],
-                        "cgder" => $info['cgder'],
-                        "cgderid" => $info['cgderid'],
-                        "person" => $info['person'],
-                        "person_id" => $info['person_id'],
-                        "contactor" => $returninfo["contactor"],
-                        "mobile" => $returninfo["mobile"],
-                        "addr" => $returninfo["addr"],
-                        "addr_code" => $returninfo["addr_code"],
-                        "return_code" => $info["error_code"],
-                        "post_fee" => $returninfo["post_fee"],
-                        "post_code" => $returninfo["post_code"],
-                        "post_company" => $returninfo["post_company"],
-                        "customer_code" => $info["customer_code"],
-                        "customer_name" => $info["customer_name"],
-                        "status" => $info['return_tag'] == 1 ? 4 : 1, //return_tag==1退回供应商,status:4完成退货,1待验收
-                        "addtime" => date("Y-m-d H:i:s"),
-                        "updatetime" => date("Y-m-d H:i:s"),
-                        'supplierNo' => $info['supplierNo'],
-                        'supplierName' => $info['supplierName'],
-                        'companyNo' => $info['companyNo'],
-                        'companyName' => $info['companyName'],
-                    ];
-                    $sav = Db::name("order_back")->insert($thdata, true);
-                    if ($sav) {
-
-                        //修改状态,添加待办
-                        ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
-                            "order_code" => $thdata['thNo'],//销售单code
-                            "status" => $thdata['status'],//这里的status是之前的值
-                            "action_remark" => '',//备注
-                            "action_type" => "create"//新建create,编辑edit,更改状态status
-                        ], "CKTHD", $thdata['status'], $thdata);
-
-
-                        //售后退货单,供应商不同意退货,退回到业务公司仓的时候,要把待办数据推给供应商负责人和库管人员
-                        if ($thdata['status'] == 1) {
-
-                            //31库管人员,41库管-张凯旋
-                            $uids = Db::name('user_role')
-                                ->where(['is_del' => 0, 'roleid' => [31, 41], 'status' => 1])
-                                ->column('uid');
-
-                            ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
-                                "order_type" => 'CKTHD',
-                                "order_code" => $thdata['thNo'],//销售单code
-                                "order_id" => $sav,
-                                "order_status" => $thdata['status'],
-                                "before_status" => 0,
-                                'handle_user_list' => implode(',', array_merge($uids, [$sale['cgderid']])),
-                            ]);
-                        } else {
-                            ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
-                                "order_type" => 'CKTHD',
-                                "order_code" => $thdata['thNo'],//销售单code
-                                "order_id" => $sav,
-                                "order_status" => $thdata['status'],
-                                "before_status" => 0
-                            ]);
-                        }
-
-
-                        //维护台账记录
-//                        Db::name('standing_book')
-//                            ->where(['returnCode' => $bkcode])
-//                            ->update([
-//                                'thNo' => $thNo,
-//                                'updatetime' => date("Y-m-d H:i:s")
-//                            ]);
-                        Db::execute("UPDATE `wsm_standing_book` SET `thNo`=CONCAT(IFNULL(`thNo`,''),',{$thNo}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET('{$bkcode}',`returnCode`)");//这里的returnCode可能有多个
-                        // 库存品退货 不退商品 需要计算成本
-//						if($info['except_code']==1){
-//							$sabebn =Db::name("sale_info")->where(["orderCode"=>$info['orderCode']])->select()->toArray();
-//                            	 if(!empty($sabebn)){
-//                        	$total_num =$info["error_num"];
-//                        	foreach ($sabebn as $ve){
+//                    $thNo = makeNo("ST");
+//                    $thdata = [
+//                        "thNo" => $thNo,
+//                        "orderCode" => $out["orderCode"],
+//                        "outCode" => $out["outCode"],
+//                        "order_type" => $info["order_type"],
+//                        "returnCode" => $info["returnCode"],
+//                        "good_code" => $info["good_code"],
+//                        "good_name" => $info["good_name"],
+//                        "return_wsm" => $returninfo["return_wsm"],
+//                        "total_fee" => round($sale['sale_price'] * $info["error_num"], 2),
+//                        "good_price" => $sale['sale_price'],
+//                        "platform_id" => $sale['platform_id'],
+//                        "return_msg" => $info["error_msg"],
+//                        "return_num" => $info["error_num"],
+//                        "normal_num" => 0,
+//                        "received_num" => 0,
+//                        "apply_id" => $info['apply_id'],
+//                        "apply_name" => $info['apply_name'],
+//                        "cgder" => $info['cgder'],
+//                        "cgderid" => $info['cgderid'],
+//                        "person" => $info['person'],
+//                        "person_id" => $info['person_id'],
+//                        "contactor" => $returninfo["contactor"],
+//                        "mobile" => $returninfo["mobile"],
+//                        "addr" => $returninfo["addr"],
+//                        "addr_code" => $returninfo["addr_code"],
+//                        "return_code" => $info["error_code"],
+//                        "post_fee" => $returninfo["post_fee"],
+//                        "post_code" => $returninfo["post_code"],
+//                        "post_company" => $returninfo["post_company"],
+//                        "customer_code" => $info["customer_code"],
+//                        "customer_name" => $info["customer_name"],
+//                        "status" => $info['return_tag'] == 1 ? 4 : 1, //return_tag==1退回供应商,status:4完成退货,1待验收
+//                        "addtime" => date("Y-m-d H:i:s"),
+//                        "updatetime" => date("Y-m-d H:i:s"),
+//                        'supplierNo' => $info['supplierNo'],
+//                        'supplierName' => $info['supplierName'],
+//                        'companyNo' => $info['companyNo'],
+//                        'companyName' => $info['companyName'],
+//                    ];
+//                    $sav = Db::name("order_back")->insert($thdata, true);
+//                    if ($sav) {
+//
+//                        //修改状态,添加待办
+//                        ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
+//                            "order_code" => $thdata['thNo'],//销售单code
+//                            "status" => $thdata['status'],//这里的status是之前的值
+//                            "action_remark" => '',//备注
+//                            "action_type" => "create"//新建create,编辑edit,更改状态status
+//                        ], "CKTHD", $thdata['status'], $thdata);
+//
 //
-//                        		$tempnum=0;
-//                        		if ($total_num==0) break;
-//                        		if($total_num>=$ve['num']){
-//                        			$tempnum = $ve['num'];
-//                        			$total_num-=$ve['num'];
-//                        			$ve['num']=0;
-//                        		}else{
-//                        		    $tempnum = $total_num;
-//                        			$ve['num']-=$total_num;
-//                        			$total_num=0;
-//                        		}
-//                        		$bnin=GoodStockInfo::ReturnAdd($stockid,$ve['bnCode'],$tempnum,$ve['stockid']);
-//                        		if($bnin==false){
-//                        			 Db::rollback();
-//                                    return error_show(1005, '可售商品Bn库存数入库失败');
-//                        		}
-//								$up=Db::name("sale_info")->save($ve);
-//                        		if($up==false){
-//                        			 Db::rollback();
-//                                    return error_show(1005, '可售商品Bn库存数入库失败');
-//                        		}
-//								$bnin=GoodStockInfo::ReturnBn($info['returnCode'],$ve['id'],$tempnum);
-//                        		if($bnin==false){
-//                        			 Db::rollback();
-//                                    return error_show(1005, '可售商品Bn库存数入库失败');
-//                        		}
-//                        	}
+//                        //售后退货单,供应商不同意退货,退回到业务公司仓的时候,要把待办数据推给供应商负责人和库管人员
+//                        if ($thdata['status'] == 1) {
+//
+//                            //31库管人员,41库管-张凯旋
+//                            $uids = Db::name('user_role')
+//                                ->where(['is_del' => 0, 'roleid' => [31, 41], 'status' => 1])
+//                                ->column('uid');
+//
+//                            ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
+//                                "order_type" => 'CKTHD',
+//                                "order_code" => $thdata['thNo'],//销售单code
+//                                "order_id" => $sav,
+//                                "order_status" => $thdata['status'],
+//                                "before_status" => 0,
+//                                'handle_user_list' => implode(',', array_merge($uids, [$sale['cgderid']])),
+//                            ]);
+//                        } else {
+//                            ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
+//                                "order_type" => 'CKTHD',
+//                                "order_code" => $thdata['thNo'],//销售单code
+//                                "order_id" => $sav,
+//                                "order_status" => $thdata['status'],
+//                                "before_status" => 0
+//                            ]);
 //                        }
-//						}else{
 //
-//						}
-
-                        //退回供应商的时候,处理库存
-                        if ($info['return_tag'] == 1) {
-                            $sale['th_num'] += $info['error_num'];
-                            if ($sale['th_num'] == $sale['send_num'] && $sale['wsend_num'] == 0) {
-                                $sale['status'] = 3;
-                            }
-                            $sale['th_fee'] += round($info['error_num'] * $sale['sale_price'], 2);
-                            $sale['updatetime'] = date("Y-m-d H:i:s");
-                            $uap = Db::name("sale")->save($sale);
-
-                            if ($uap == false) throw new Exception('销售单订单更新失败');
-//                            if($uap==false){
-//                                Db::rollback();
-//                                return error_show(1005,'销售单订单更新失败');
+//
+//                        //维护台账记录
+////                        Db::name('standing_book')
+////                            ->where(['returnCode' => $bkcode])
+////                            ->update([
+////                                'thNo' => $thNo,
+////                                'updatetime' => date("Y-m-d H:i:s")
+////                            ]);
+//                        Db::execute("UPDATE `wsm_standing_book` SET `thNo`=CONCAT(IFNULL(`thNo`,''),',{$thNo}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET('{$bkcode}',`returnCode`)");//这里的returnCode可能有多个
+//                        // 库存品退货 不退商品 需要计算成本
+////						if($info['except_code']==1){
+////							$sabebn =Db::name("sale_info")->where(["orderCode"=>$info['orderCode']])->select()->toArray();
+////                            	 if(!empty($sabebn)){
+////                        	$total_num =$info["error_num"];
+////                        	foreach ($sabebn as $ve){
+////
+////                        		$tempnum=0;
+////                        		if ($total_num==0) break;
+////                        		if($total_num>=$ve['num']){
+////                        			$tempnum = $ve['num'];
+////                        			$total_num-=$ve['num'];
+////                        			$ve['num']=0;
+////                        		}else{
+////                        		    $tempnum = $total_num;
+////                        			$ve['num']-=$total_num;
+////                        			$total_num=0;
+////                        		}
+////                        		$bnin=GoodStockInfo::ReturnAdd($stockid,$ve['bnCode'],$tempnum,$ve['stockid']);
+////                        		if($bnin==false){
+////                        			 Db::rollback();
+////                                    return error_show(1005, '可售商品Bn库存数入库失败');
+////                        		}
+////								$up=Db::name("sale_info")->save($ve);
+////                        		if($up==false){
+////                        			 Db::rollback();
+////                                    return error_show(1005, '可售商品Bn库存数入库失败');
+////                        		}
+////								$bnin=GoodStockInfo::ReturnBn($info['returnCode'],$ve['id'],$tempnum);
+////                        		if($bnin==false){
+////                        			 Db::rollback();
+////                                    return error_show(1005, '可售商品Bn库存数入库失败');
+////                        		}
+////                        	}
+////                        }
+////						}else{
+////
+////						}
+//
+//                        //退回供应商的时候,处理库存
+//                        if ($info['return_tag'] == 1) {
+//                            $sale['th_num'] += $info['error_num'];
+//                            if ($sale['th_num'] == $sale['send_num'] && $sale['wsend_num'] == 0) {
+//                                $sale['status'] = 3;
+//                            }
+//                            $sale['th_fee'] += round($info['error_num'] * $sale['sale_price'], 2);
+//                            $sale['updatetime'] = date("Y-m-d H:i:s");
+//                            $uap = Db::name("sale")->save($sale);
+//
+//                            if ($uap == false) throw new Exception('销售单订单更新失败');
+////                            if($uap==false){
+////                                Db::rollback();
+////                                return error_show(1005,'销售单订单更新失败');
+////                            }
+//                            if ($sale['is_stock'] == 0) {
+//                                $ordernum = Db::name("order_num")
+//                                    ->where(['orderCode' => $info['orderCode']])
+//                                    ->find();
+//                                if ($ordernum == false) throw new Exception('未找到关联采购单1');
+////	                            if($ordernum==false){
+////	                                Db::rollback();
+////	                                return error_show(1005,'未找到关联采购单');
+////	                            }
+//                                $ordernum['send_num'] -= $info['error_num'];
+//                                $orderup = Db::name("order_num")->save($ordernum);
+//
+//                                if ($orderup == false) throw new Exception('关联数据更新失败');
+//
+////	                            if($orderup==false){
+////	                                Db::rollback();
+////	                                return error_show(1005,'关联数据更新失败');
+////	                            }
+//                                $cgd = Db::name("purchease_order")
+//                                    ->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])
+//                                    ->findOrEmpty();
+//                                if (empty($cgd)) throw new Exception('未找到采购单数据');
+////	                            if($cgd==false){
+////	                                Db::rollback();
+////	                                return error_show(1005,'未找到采购单数据');
+////	                            }
+//                                $cgd['th_num'] += $info['error_num'];
+//                                if ($cgd['th_num'] == $cgd['send_num'] && $cgd['wsend_num'] == 0) {
+//                                    $cgd['status'] = 4;
+//                                }
+//                                $cgd['th_fee'] += round($info['error_num'] * $cgd['good_price'], 2);
+//                                $cgd['updatetime'] = date("Y-m-d H:i:s");
+//                                $cgdup = Db::name("purchease_order")->save($cgd);
+//
+//                                if ($cgdup == false) throw new Exception('采购单数据更新失败');
+////	                            if($cgdup==false){
+////	                                Db::rollback();
+////	                                return error_show(1005,'采购单数据更新失败');
+////	                            }
 //                            }
-                            if ($sale['is_stock'] == 0) {
-                                $ordernum = Db::name("order_num")
-                                    ->where(['orderCode' => $info['orderCode']])
-                                    ->find();
-                                if ($ordernum == false) throw new Exception('未找到关联采购单1');
-//	                            if($ordernum==false){
-//	                                Db::rollback();
-//	                                return error_show(1005,'未找到关联采购单');
-//	                            }
-                                $ordernum['send_num'] -= $info['error_num'];
-                                $orderup = Db::name("order_num")->save($ordernum);
-
-                                if ($orderup == false) throw new Exception('关联数据更新失败');
-
-//	                            if($orderup==false){
-//	                                Db::rollback();
-//	                                return error_show(1005,'关联数据更新失败');
-//	                            }
-                                $cgd = Db::name("purchease_order")
-                                    ->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])
-                                    ->findOrEmpty();
-                                if (empty($cgd)) throw new Exception('未找到采购单数据');
-//	                            if($cgd==false){
-//	                                Db::rollback();
-//	                                return error_show(1005,'未找到采购单数据');
-//	                            }
-                                $cgd['th_num'] += $info['error_num'];
-                                if ($cgd['th_num'] == $cgd['send_num'] && $cgd['wsend_num'] == 0) {
-                                    $cgd['status'] = 4;
-                                }
-                                $cgd['th_fee'] += round($info['error_num'] * $cgd['good_price'], 2);
-                                $cgd['updatetime'] = date("Y-m-d H:i:s");
-                                $cgdup = Db::name("purchease_order")->save($cgd);
-
-                                if ($cgdup == false) throw new Exception('采购单数据更新失败');
-//	                            if($cgdup==false){
-//	                                Db::rollback();
-//	                                return error_show(1005,'采购单数据更新失败');
-//	                            }
-                            }
-
-                            $sabebn = Db::name("sale_info")
-                                ->where([["orderCode", "=", $info['orderCode']], ["num", ">", 0]])
-                                ->select()
-                                ->toArray();
-                            if (!empty($sabebn)) {
-                                $total_num = $info["error_num"];
-                                foreach ($sabebn as $ve) {
-                                    $tempnum = 0;
-                                    if ($total_num == 0) break;
-                                    if ($total_num >= $ve['num']) {
-                                        $tempnum = $ve['num'];
-                                        $total_num -= $ve['num'];
-                                        $ve['th_num'] += $ve['num'];
-                                        $ve['num'] = 0;
-                                    } else {
-                                        $tempnum = $total_num;
-                                        $ve['num'] -= $total_num;
-                                        $ve['th_num'] += $total_num;
-                                        $total_num = 0;
-                                    }
-
-                                    if ($info['except_code'] == 1) {
-//		                                	if($sale['is_stock']==1){
-//		                                		$bnin=GoodStockInfo::AddBn($ve['stockid'],$ve['bnCode'],$tempnum);
-//				                                if($bnin==false){
-//				                                     Db::rollback();
-//				                                    return error_show(1005, '可售商品Bn库存数入库失败');
-//				                                }
-//		                                	}
-                                        $up = Db::name("sale_info")->save($ve);
-
-                                        if ($up == false) throw new Exception('可售商品Bn库存数入库失败');
-//				                                if($up==false){
-//				                                     Db::rollback();
-//				                                    return error_show(1005, '可售商品Bn库存数入库失败');
-//				                                }
-                                    }
-
-                                    $bnin = GoodStockInfo::ReturnBn($info['returnCode'], $ve['id'], $tempnum);
-                                    if ($bnin == false) throw new Exception('可售商品Bn库存数入库失败');
-//		                                if($bnin==false){
-//		                                     Db::rollback();
-//		                                    return error_show(1005, '可售商品Bn库存数入库失败');
-//		                                }
-                                }
-                            }
-                            if ($info['error_num'] >= $out['send_num']) {
-                                $out['status'] = 4;
-                                $out['updatetime'] = date("Y-m-d H:i:s");
-                                $upout = Db::name("order_out")->save($out);
-                                if ($upout == false) throw new Exception('出库单数据更新失败');
-//                                    if($upout==false){
-//                                        Db::rollback();
-//                                        return error_show(1005,'出库单数据更新失败');
+//
+//                            $sabebn = Db::name("sale_info")
+//                                ->where([["orderCode", "=", $info['orderCode']], ["num", ">", 0]])
+//                                ->select()
+//                                ->toArray();
+//                            if (!empty($sabebn)) {
+//                                $total_num = $info["error_num"];
+//                                foreach ($sabebn as $ve) {
+//                                    $tempnum = 0;
+//                                    if ($total_num == 0) break;
+//                                    if ($total_num >= $ve['num']) {
+//                                        $tempnum = $ve['num'];
+//                                        $total_num -= $ve['num'];
+//                                        $ve['th_num'] += $ve['num'];
+//                                        $ve['num'] = 0;
+//                                    } else {
+//                                        $tempnum = $total_num;
+//                                        $ve['num'] -= $total_num;
+//                                        $ve['th_num'] += $total_num;
+//                                        $total_num = 0;
 //                                    }
-                            }
-                            $data = [
-                                "orderCode" => $info['orderCode'],
-                                "th_type" => 3,
-                                "th_num" => $info['error_num'],
-                                "th_fee" => round($sale['sale_price'] * $info["error_num"], 2),
-                                "thCode" => $thNo,
-                                "spuCode" => $sale['good_code'],
-                                "good_name" => $sale['good_name'],
-                                "cat_id" => $sale['cat_id'],
-                                "apply_id" => $info['apply_id'],
-                                "apply_name" => $info['apply_name'],
-                                "addtime" => date("Y-m-d H:i:s"),
-                                "status" => 1,
-                                "is_del" => 0
-                            ];
-                            $inse = Db::name("th_data")->insert($data);
-                            if ($inse == false) throw new Exception('退货单更新失败');
-
-
-//                            if($inse==false){
-//                                Db::rollback();
-//                                return error_show(1004,"退货单更新失败");
+//
+//                                    if ($info['except_code'] == 1) {
+////		                                	if($sale['is_stock']==1){
+////		                                		$bnin=GoodStockInfo::AddBn($ve['stockid'],$ve['bnCode'],$tempnum);
+////				                                if($bnin==false){
+////				                                     Db::rollback();
+////				                                    return error_show(1005, '可售商品Bn库存数入库失败');
+////				                                }
+////		                                	}
+//                                        $up = Db::name("sale_info")->save($ve);
+//
+//                                        if ($up == false) throw new Exception('可售商品Bn库存数入库失败');
+////				                                if($up==false){
+////				                                     Db::rollback();
+////				                                    return error_show(1005, '可售商品Bn库存数入库失败');
+////				                                }
+//                                    }
+//
+//                                    $bnin = GoodStockInfo::ReturnBn($info['returnCode'], $ve['id'], $tempnum);
+//                                    if ($bnin == false) throw new Exception('可售商品Bn库存数入库失败');
+////		                                if($bnin==false){
+////		                                     Db::rollback();
+////		                                    return error_show(1005, '可售商品Bn库存数入库失败');
+////		                                }
+//                                }
 //                            }
-
-                        }
-
-                        Db::commit();
-                        return app_show(0, "退货单新建成功", ["thNo" => $thNo]);
-                    }
+//                            if ($info['error_num'] >= $out['send_num']) {
+//                                $out['status'] = 4;
+//                                $out['updatetime'] = date("Y-m-d H:i:s");
+//                                $upout = Db::name("order_out")->save($out);
+//                                if ($upout == false) throw new Exception('出库单数据更新失败');
+////                                    if($upout==false){
+////                                        Db::rollback();
+////                                        return error_show(1005,'出库单数据更新失败');
+////                                    }
+//                            }
+//                            $data = [
+//                                "orderCode" => $info['orderCode'],
+//                                "th_type" => 3,
+//                                "th_num" => $info['error_num'],
+//                                "th_fee" => round($sale['sale_price'] * $info["error_num"], 2),
+//                                "thCode" => $thNo,
+//                                "spuCode" => $sale['good_code'],
+//                                "good_name" => $sale['good_name'],
+//                                "cat_id" => $sale['cat_id'],
+//                                "apply_id" => $info['apply_id'],
+//                                "apply_name" => $info['apply_name'],
+//                                "addtime" => date("Y-m-d H:i:s"),
+//                                "status" => 1,
+//                                "is_del" => 0
+//                            ];
+//                            $inse = Db::name("th_data")->insert($data);
+//                            if ($inse == false) throw new Exception('退货单创建失败');
+//
+//
+////                            if($inse==false){
+////                                Db::rollback();
+////                                return error_show(1004,"退货单更新失败");
+////                            }
+//
+//                        }
+//
+//                        Db::commit();
+//                        return app_show(0, "退货单新建成功", ["thNo" => $thNo]);
+//                    }
                 }
             }
-            Db::rollback();
-            return error_show(1004, '退货失败');
+            Db::commit();
+            return json_show(0, '退货成功');
         } catch (Exception $e) {
             Db::rollback();
-            return error_show(1004, $e->getMessage());
+            return json_show(1004, $e->getMessage());
         }
     }
 
@@ -1636,11 +1639,11 @@ class After extends Base
                 ->field('id,status,apply_id')
                 ->where([
                     ['returnCode', '=', $data['returnCode']],
-                    ['is_del', '=', 0],
-                    ['status', '<>', 8]
+                    ['is_del', '=', 0]
                 ])->findOrEmpty();
 
-            if (!$rs) throw new Exception('该售后单记录不存在');
+            if (empty($rs)) throw new Exception('该售后单记录不存在');
+            if (in_array($rs['status'], [4, 12, 5, 8])) throw new Exception('不允许取消');
 
             //修改记录
             $res = Db::name('order_return')->where(['id' => $rs['id']])->update(['status' => 8, 'updatetime' => date('Y-m-d H:i:s')]);

+ 464 - 0
app/admin/controller/AfterChild.php

@@ -0,0 +1,464 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\admin\model\GoodStockInfo;
+use think\Exception;
+use think\facade\Db;
+use think\facade\Validate;
+
+//退货工单
+class AfterChild extends Base
+{
+
+    //退货工单列表
+    public function getList()
+    {
+
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'returnCode' => '', 'status' => '', 'orderCode' => '', 'outCode' => ''], 'post', 'trim');
+
+        $where = [['a.is_del', '=', 0]];
+        if ($param['returnCode'] != '') $where[] = ['a.returnCode', 'like', '%' . $param['returnCode'] . '%'];
+        if ($param['status'] !== '') $where[] = ['a.status', '=', $param['status']];
+        if ($param['orderCode'] != '') $where[] = ['a.orderCode', 'like', '%' . $param['orderCode'] . '%'];
+        if ($param['outCode'] != '') $where[] = ['a.outCode', 'like', '%' . $param['outCode'] . '%'];
+
+        $count = Db::name('order_return_child')
+            ->alias('a')
+            ->leftJoin('warehouse_info b', 'b.wsm_code=a.send_wsm_code')
+            ->leftJoin('warehouse_info c', 'c.wsm_code=a.return_wsm_code')
+            ->where($where)
+            ->count('a.id');
+
+        $list = Db::name('order_return_child')
+            ->alias('a')
+            ->field('a.id,a.returnCode,a.orderCode,a.outCode,a.order_out_status,a.outChildCode,b.supplierName send_supplierName,b.supplierNo send_supplierNo,b.name send_wsm_name,a.send_wsm_code,b.contactor_name send_contactor_name,a.send_num,a.return_num,c.supplierName return_supplierName,c.supplierNo return_supplierNo,c.name return_wsm_name,a.return_wsm_code,c.contactor_name return_contactor_name,a.status')
+            ->leftJoin('warehouse_info b', 'b.wsm_code=a.send_wsm_code')
+            ->leftJoin('warehouse_info c', 'c.wsm_code=a.return_wsm_code')
+            ->where($where)
+            ->order(['a.addtime' => 'desc', 'a.id' => 'desc'])
+            ->page($param['page'], $param['size'])
+            ->select()
+            ->toArray();
+
+        return json_show(0, '获取列表成功', ['count' => $count, 'list' => $list]);
+
+    }
+
+    //设置退货工单
+    public function setOrderReturnChild()
+    {
+
+        $param = $this->request->only(['returnCode', 'list'], 'post', 'trim');
+
+        $val = Validate::rule([
+            'returnCode|售后申请单编码' => 'require',
+            'list|工单集合' => 'require|array|max:100',
+        ]);
+        if ($val->check($param) == false) return json_show(1004, $val->getError());
+
+        $info = Db::name('order_return')
+            ->where(['is_del' => 0, 'returnCode' => $param['returnCode']])
+            ->findOrEmpty();
+        if (empty($info)) return json_show(1004, '售后申请单不存在');
+        if ($info['status'] != 11) return json_show(1004, '售后申请单状态错误');
+        if ($info['is_receive'] != 1) return json_show(1004, '未收到货,无需设置退货工单');
+
+        $order_out = Db::name('order_out')
+            ->field('id,status order_out_status,orderCode')
+            ->where(['is_del' => 0, 'outCode' => $info['outCode']])
+            ->findOrEmpty();
+        if (empty($order_out)) return json_show(1004, '未找到对应的发货单');
+
+        $val_child = Validate::rule([
+            'outChildCode|发货工单号' => 'require',
+            'return_num|退货数量' => 'require|number|gt:0|max:999999999999',
+            'return_wsm_code|退货仓库编码' => 'require'
+        ]);
+
+        //发货工单详情
+        $order_out_child = Db::name('order_out_child')
+            ->where(['is_del' => 0, 'outCode' => $info['outCode'], 'outChildCode' => array_column($param['list'], 'outChildCode')])
+            ->column('num,wsm_code', 'outChildCode');
+
+        //所有仓库详情
+        $wsm_info = Db::name('warehouse_info')
+            ->where(['is_del' => 0, 'wsm_code' => array_unique(array_merge(array_column($order_out_child, 'wsm_code'), array_column($param['list'], 'return_wsm_code')))])
+            ->column('id', 'wsm_code');
+
+        Db::startTrans();
+        try {
+
+            $insert = [];
+            $date = date('Y-m-d H:i:s');
+            foreach ($param['list'] as $value) {
+                if ($val_child->check($value) == false) throw new Exception($val_child->getError());
+
+                if (!isset($order_out_child[$value['outChildCode']])) throw new Exception($value['outChildCode'] . '发货工单不存在');
+                if (!isset($wsm_info[$value['return_wsm_code']])) throw new Exception($value['return_wsm_code'] . '退货仓库不存在');
+
+                $insert[] = [
+                    'returnCode' => $param['returnCode'],
+                    'orderCode' => $order_out['orderCode'],
+                    'outCode' => $info['outCode'],
+                    'order_out_status' => $order_out['order_out_status'],
+                    'outChildCode' => $value['outChildCode'],
+                    'send_wsm_code' => $order_out_child[$value['outChildCode']]['wsm_code'],
+                    'send_num' => $order_out_child[$value['outChildCode']]['num'],
+                    'return_num' => $value['return_num'],
+                    'return_wsm_code' => $value['return_wsm_code'],
+                    'can_sell_num' => 0,
+                    'defective_num' => 0,
+                    'loss_num' => 0,
+                    'apply_id' => $this->uid,
+                    'apply_name' => $this->uname,
+                    'status' => 1,
+                    'is_del' => 0,
+                    'remark' => '',
+                    'addtime' => $date,
+                    'updatetime' => $date,
+                ];
+
+            }
+
+            if ($insert) Db::name('order_return_child')->insertAll($insert);
+
+            Db::name('order_return')
+                ->where(['is_del' => 0, 'id' => $info['id'], 'status' => 11])
+                ->update(['status' => 4, 'updatetime' => $date]);
+
+            Db::commit();
+            return json_show(0, '设置退货工单成功');
+        } catch (Exception $exception) {
+            Db::rollback();
+            return json_show(1004, $exception->getMessage());
+        }
+
+
+    }
+
+    //库管收货
+    public function deliveryOrderReturnChild()
+    {
+        $param = $this->request->only(['returnCode', 'list'], 'post', 'trim');
+
+        $val = Validate::rule([
+            'returnCode|退货申请单号' => 'require',
+            'list|退货工单集合' => 'require|array|max:100',
+        ]);
+
+        if ($val->check($param)) return json_show(1004, $val->getError());
+
+        $order_return = Db::name('order_return')
+            ->alias('a')
+            ->field('a.id,a.good_code,a.outCode,b.orderCode,c.is_stock,c.order_type')
+            ->leftJoin('order_out b', 'b.outCode=a.outCode AND b.is_del=0')
+            ->leftJoin('sale c', 'c.orderCode=b.orderCode AND c.is_del=0')
+            ->where(['a.is_del' => 0, 'a.returnCode' => $param['returnCode']])
+            ->findOrEmpty();
+        if (empty($order_return)) return json_show(1004, '售后申请单不存在');
+
+        $info = Db::name('order_return_child')
+            ->alias('a')
+            ->leftJoin('order_out_child b', 'b.outChildCode=a.outChildCode')
+            ->where(['a.is_del' => 0, 'a.returnCode' => $param['returnCode'], 'a.id' => array_column($param['list'], 'id')])
+            ->column('a.id,a.return_wsm_code,a.outChildCode,b.wsm_code,a.status', 'a.id');
+        if (empty($info)) return json_show(1004, '退货工单不存在');
+
+        $val_child = Validate::rule([
+            'id|退货工单id' => 'require|gt:0|max:999999999',
+            'can_sell_num|销售仓入库数量' => 'require|number|egt:0|max:999999999999',
+            'defective_num|次品仓入库数量' => 'require|number|egt:0|max:999999999999',
+            'loss_num|丢失数量' => 'require|number|egt:0|max:999999999999',
+            'remark|备注' => 'max:255'
+        ]);
+
+        Db::startTrans();
+        try {
+
+            $date = date('Y-m-d H:i:s');
+            foreach ($param['list'] as $value) {
+                if ($val_child->check($value) == false) throw new Exception($val_child->getError());
+                if (!isset($info[$value['id']])) throw new Exception($value['id'] . '退货工单不存在');
+                if ($info[$value['id']]['status'] != 1) throw new Exception($value['id'] . '退货工单状态有误');
+
+                //退货工单
+                Db::name('order_return_child')
+                    ->where(['is_del' => 0, 'id' => $value['id']])
+                    ->update([
+                        'can_sell_num' => $value['can_sell_num'],
+                        'defective_num' => $value['defective_num'],
+                        'loss_num' => $value['loss_num'],
+                        'remark' => $value['remark'],
+                        'updatetime' => $date,
+                        'status' => 2
+                    ]);
+            }
+
+            $total = array_sum(array_column($param['list'],'can_sell_num'));
+
+            if($total>0){
+                if ($order_return['is_stock'] != 1) {
+                    //根据转化表判断该非库存品是否转化为库存品
+                    $spuCode = Db::name('good_change_stock')
+                        ->where(['old_spuCode'=>$order_return['good_code'],'old_order_type'=>$order_return['order_type']])
+                        ->value('spuCode','');
+                    if ($spuCode=='') {
+                        //将非库存品转化为库存品
+                        if ($order_return['order_type'] == 2) {
+                            $good = Db::name('good_basic')
+                                ->where('spuCode',$order_return['good_code'])
+                                ->findOrEmpty();
+                        } else {
+                            $good = Db::name('good_zixun')
+                                ->where([])
+                                ->findOrEmpty();
+                        }
+
+                        if (!empty($good)) {
+                            $spuCode = makeNo('SKU');
+                            Db::name('good_basic')->insert([
+                                'spuCode' => $spuCode,
+                                'good_code' => $good['good_code'],
+                                'good_name' => $good['good_name'],
+                                'cat_id' => $good['cat_id'],
+                                'brand_id' => $good['brand_id'],
+                                'companyNo' => $good['companyNo'],
+                                'companyName' => $good['companyName'],
+                                'good_unit' => $good['good_unit'],
+                                'good_type' => $good['good_type'],
+                                'moq' => $good['moq'],
+                                'is_exclusive' => 0,
+                                'customized' => $good['customized'],
+                                'tax' => $good['tax'],
+                                'supplierNo' => $good['supplierNo'],
+                                'supplierName' => $good['supplierName'],
+                                'is_auth' => $good['is_auth'],
+                                'auth_img' => $good['auth_img'],
+                                'is_stock' => 1,
+                                'after_sales' => '',
+                                'craft_desc' => $good['craft_desc'],
+                                'good_remark' => $good['good_remark'],
+                                'good_size' => '',
+                                'weight' => $good['weight'],
+                                'packing_way' => '',
+                                'packing_size' => '',
+                                'packing_spec' => '',
+                                'packing_list' => '',
+                                'packing_weight' => 0,
+                                'good_bar' => '',
+                                'supply_area' => $good['supply_area'],
+                                'delivery_place' => '',
+                                'origin_place' => '',
+                                'delivery_day' => '',
+                                'lead_time' => '',
+                                'sample_day' => '',
+                                'sample_fee' => '',
+                                'good_img' => $good['good_img'],
+                                'good_thumb_img' => $good['good_thumb_img'],
+                                'good_info_img' => $good['good_info_img'],
+                                'cert_fee' => 0,
+                                'packing_fee' => 0,
+                                'cost_fee' => 0,
+                                'mark_fee' => 0,
+                                'demo_fee' => 0,
+                                'open_fee' => 0,
+                                'noble_metal' => $good['noble_metal'],
+                                'noble_weight' => 0,
+                                'is_gold_price' => $good['is_gold_price'],
+                                'cgd_gold_price' => 0,
+                                'market_price' => 0,
+                                'nake_price' => 0,
+                                'is_step' => 0,
+                                'is_online' => 0,
+                                'status' => 0,
+                                'createrid' => $good['createrid'],
+                                'creater' => $good['creater'],
+                                'field_change' => '',
+                                'is_del' => 0,
+                                'addtime' => $date,
+                                'updatetime' => $date,
+                                'is_diff' => 0,
+                                'config' => '',
+                                'other_config' => '',
+                                'stock_moq' => 0,
+                                'is_support_barter' => 1,
+                                'chargerid' => $good['createrid'],
+                                'charger' => $good['creater'],
+                                'is_support_stock' => 1
+                            ]);
+
+                            //关联表增数据
+                            Db::name('good_change_stock')
+                                ->insert([
+                                    'old_spuCode'=>$order_return['good_code'],
+                                    'old_order_type'=>$order_return['order_type'],
+                                    'spuCode'=>$spuCode,
+                                    'addtime' => $date,
+                                    'updatetime' => $date,
+                                ]);
+
+                        }throw new Exception('未找到对应的商品数据');
+
+                    }
+
+                    //新增bn记录,维护旧有bn记录
+                    $child_bns=Db::name('child_bn')
+                        ->field('id,num,origin_price')
+                        ->where(['orderCode'=>$order_return['orderCode'],'outCode'=>$order_return['outCode']])
+                        ->order(['num'=>'desc','id'=>'asc'])
+                        ->cursor();
+
+                    $origin_price=$j=0;
+                    foreach ($child_bns as $child_bn){
+                        if($origin_price===0) $origin_price=$child_bn['origin_price'];
+                        Db::name('child_bn')
+                            ->where(['id'=>$child_bn['id']])
+                            ->dec('num',($child_bn['num']>=$total)?$total:$child_bn['num'])
+                            ->update(['updatetime'=>$date]);
+                        $total=($child_bn['num']>=$total)?0:($total-$child_bn['num']);
+                        if($total==0) break;
+                    }
+
+                    foreach ($param['list'] as $value) {
+                        if ($value['can_sell_num'] > 0) {
+                            $stockid = Db::name('good_stock')
+                                ->insertGetId([
+                                    'project_code' => '',
+                                    'spuCode' => $spuCode,
+                                    'wsm_code' => $value['return_wsm_code'],
+                                    'wait_in_stock' => 0,
+                                    'wait_out_stock' => 0,
+                                    'usable_stock' => $value['can_sell_num'],
+                                    'intra_stock' => 0,
+                                    'total_stock' => $value['can_sell_num'],
+                                    'status' => 1,
+                                    'is_del' => 0,
+                                    'warn_stock' => 0,
+                                    'addtime' => $date,
+                                    'updatetime' => $date,
+                                ]);
+
+                            Db::name('good_stock_info')
+                                ->insert([
+                                    'stockid'=>$stockid,
+                                    'bnCode'=>substr(makeNo("BN"), 0, -2) . str_pad($j++, 2, '0', STR_PAD_LEFT),
+                                    'total_num'=>$value['can_sell_num'],
+                                    'used_num'=>0,
+                                    'balance_num'=>$value['can_sell_num'],
+                                    'origin_price'=>$origin_price,
+                                    'addtime' => $date,
+                                    'updatetime' => $date,
+                                ]);
+                        }
+                    }
+                }
+                else{
+                    //库存品,直接维护stock和info
+                    $stockids=Db::name('good_stock')
+                        ->where(['is_del'=>0,'spuCode'=>$order_return['good_code'],'wsm_code'=>array_column($info,'return_wsm_code')])
+                        ->column('id','wsm_code');
+
+                    foreach ($param['list'] as $value){
+
+                        //定义了stockid,维护bn
+                        if(isset($stockids[$info[$value['id']]['return_wsm_code']])){
+                            $good_stock_info=Db::name('good_stock_info')
+                                ->where(['stockid'=>$stockids[$info[$value['id']]['return_wsm_code']]])
+                                ->findOrEmpty();
+
+                            if(empty($good_stock_info)){
+                                //从child_bn查询bn号并维护,新建到good_stock_info中
+                                $child_bns=Db::name('child_bn')
+                                    ->field('id,num,bnCode,origin_price')
+                                    ->where(['orderCode'=>$order_return['orderCode'],'outCode'=>$order_return['outCode'],'childCode'=>$info[$value['id']]['outChildCode']])
+                                    ->order(['num'=>'desc','id'=>'asc'])
+                                    ->cursor();
+
+                                $total = $value['can_sell_num'];
+                                foreach ($child_bns as $child_bn){
+                                    Db::name('child_bn')
+                                        ->where(['id'=>$child_bn['id']])
+                                        ->dec('num',($child_bn['num']>=$total)?$total:$child_bn['num'])
+                                        ->update(['updatetime'=>$date]);
+
+                                    Db::name('good_stock_info')
+                                        ->insert([
+                                            'stockid'=>$stockids[$info[$value['id']]['return_wsm_code']],
+                                            'bnCode'=>$child_bn['bnCode'],
+                                            'total_num'=>($child_bn['num']>=$total)?$total:$child_bn['num'],
+                                            'used_num'=>0,
+                                            'balance_num'=>($child_bn['num']>=$total)?$total:$child_bn['num'],
+                                            'origin_price'=>$child_bn['origin_price'],
+                                            'addtime'=>$date,
+                                            'updatetime'=>$date,
+                                        ]);
+
+                                    $total=($child_bn['num']>=$total)?0:($total-$child_bn['num']);
+                                    if($total==0) break;
+                                }
+                            }else{
+                                //维护记录
+                                Db::name('good_stock_info')
+                                    ->where(['id'=>$good_stock_info['id']])
+                                    ->inc('balance_num',$value['can_sell_num'])//可用数量增加
+                                    ->dec('used_num',$value['can_sell_num'])//已用数量减少
+                                    ->update(['updatetime'=>$date]);
+                            }
+                        }
+                        else{
+                            //新建good_stock和good_stock_info
+
+                            $stockid = Db::name('good_stock')
+                                ->insertGetId([
+                                    'project_code' => '',
+                                    'spuCode' => $order_return['good_code'],
+                                    'wsm_code' => $value['return_wsm_code'],
+                                    'wait_in_stock' => 0,
+                                    'wait_out_stock' => 0,
+                                    'usable_stock' => $value['can_sell_num'],
+                                    'intra_stock' => 0,
+                                    'total_stock' => $value['can_sell_num'],
+                                    'status' => 1,
+                                    'is_del' => 0,
+                                    'warn_stock' => 0,
+                                    'addtime' => $date,
+                                    'updatetime' => $date,
+                                ]);
+
+                            Db::name('good_stock_info')
+                                ->insert([
+                                    'stockid'=>$stockid,
+                                    'bnCode'=>substr(makeNo("BN"), 0, -2) . str_pad($j++, 2, '0', STR_PAD_LEFT),
+                                    'total_num'=>$value['can_sell_num'],
+                                    'used_num'=>0,
+                                    'balance_num'=>$value['can_sell_num'],
+                                    'origin_price'=>$origin_price,
+                                    'addtime' => $date,
+                                    'updatetime' => $date,
+                                ]);
+
+
+
+
+
+                        }
+
+
+
+                    }
+
+                }
+            }
+
+            Db::commit();
+            return json_show(0,'库管收货成功');
+        } catch (Exception $exception) {
+            Db::rollback();
+            return json_show(1004, $exception->getMessage());
+        }
+
+
+    }
+
+}

+ 38 - 37
app/admin/controller/CompanyCatProfit.php

@@ -200,57 +200,58 @@ class CompanyCatProfit extends Base
             ['a.is_del', '=', 0],
             ['b.level', '=', 3],
         ];
+        if ($param['cat_name'] !== '') $where[] = ['b.search', 'like', '%' . $param['cat_name'] . '%'];
 
         //如果搜索名字,要把所有符合要求的三级分类id展现出来
-        if ($param['cat_name'] != '') {
-
-            $cat_id = Db::name('cat')
-                ->where(['is_del' => 0])
-                ->whereLike('cat_name', '%' . $param['cat_name'] . '%')
-                ->column('id');
-            if (!empty($cat_id)) {
-                $catid = [];
+//        if ($param['cat_name'] != '') {
+//
+//            $cat_id = Db::name('cat')
+//                ->where(['is_del' => 0])
+//                ->whereLike('cat_name', '%' . $param['cat_name'] . '%')
+//                ->column('id');
+//            if (!empty($cat_id)) {
+//                $catid = [];
+////                $tmp_1 = Db::name('cat')
+////                    ->where(['is_del'=>0,'pid'=>$cat_id,'level'=>3])
+////                    ->column('id');
+////                if(!empty($tmp_1)) $catid = array_merge($catid,$tmp_1);
+//
 //                $tmp_1 = Db::name('cat')
-//                    ->where(['is_del'=>0,'pid'=>$cat_id,'level'=>3])
+//                    ->where(['is_del' => 0, 'pid' => $cat_id])
 //                    ->column('id');
-//                if(!empty($tmp_1)) $catid = array_merge($catid,$tmp_1);
-
-                $tmp_1 = Db::name('cat')
-                    ->where(['is_del' => 0, 'pid' => $cat_id])
-                    ->column('id');
-                if (!empty($tmp_1)) {
-                    $catid = array_merge($catid, $tmp_1);
-                    $tmp_2 = Db::name('cat')
-                        ->where(['is_del' => 0, 'pid' => $tmp_1])
-                        ->column('id');
-                    if (!empty($tmp_2)) {
-                        $catid = array_merge($catid, $tmp_2);
-                        $tmp_3 = Db::name('cat')
-                            ->where(['is_del' => 0, 'pid' => $tmp_2])
-                            ->column('id');
-                        if (!empty($tmp_3)) $catid = array_merge($catid, $tmp_3);
-                    }
-                }
-
-                if ($catid) $where[] = ['a.cat_id', 'in', $catid];
-            }
-
-        }
+//                if (!empty($tmp_1)) {
+//                    $catid = array_merge($catid, $tmp_1);
+//                    $tmp_2 = Db::name('cat')
+//                        ->where(['is_del' => 0, 'pid' => $tmp_1])
+//                        ->column('id');
+//                    if (!empty($tmp_2)) {
+//                        $catid = array_merge($catid, $tmp_2);
+//                        $tmp_3 = Db::name('cat')
+//                            ->where(['is_del' => 0, 'pid' => $tmp_2])
+//                            ->column('id');
+//                        if (!empty($tmp_3)) $catid = array_merge($catid, $tmp_3);
+//                    }
+//                }
+//
+//                if ($catid) $where[] = ['a.cat_id', 'in', $catid];
+//            }
+//
+//        }
 
         $count = Db::name('company_cat_profit')
             ->alias('a')
             ->leftJoin('cat b', 'b.id=a.cat_id')
-            ->leftJoin('cat c', 'b.id=b.pid')
-            ->leftJoin('cat d', 'd.id=c.pid')
+//            ->leftJoin('cat c', 'b.id=b.pid')
+//            ->leftJoin('cat d', 'd.id=c.pid')
             ->where($where)
             ->count('a.id');
 
         $list = Db::name('company_cat_profit')
             ->alias('a')
             ->leftJoin('cat b', 'b.id=a.cat_id')
-            ->leftJoin('cat c', 'c.id=b.pid')
-            ->leftJoin('cat d', 'd.id=c.pid')
-            ->field('a.id,concat_ws("_",d.cat_name,c.cat_name,b.cat_name) cat_name,a.cat_id,a.rate,a.order_rate,a.money_rate,a.low_rate,a.sale_rate,a.status,c.pid')
+//            ->leftJoin('cat c', 'c.id=b.pid')
+//            ->leftJoin('cat d', 'd.id=c.pid')
+            ->field('a.id,b.search cat_name,a.cat_id,a.rate,a.order_rate,a.money_rate,a.low_rate,a.sale_rate,a.status')
             ->where($where)
             ->order(['a.id' => 'desc'])
             ->page($param['page'], $param['size'])

+ 13 - 13
app/admin/controller/Consult.php

@@ -99,7 +99,7 @@ class Consult extends Base
         $all_createrid = array_column($list,'createrid');
         $item = get_company_name_by_uid($all_createrid);
 
-		 $userCommon = new \app\admin\common\User();
+		 $userCommon = \app\admin\common\User::getIns();
         $names = $userCommon->handle('getCodeAndName', ['code' =>array_unique(array_merge(array_column($list,"khNo"),array_column($list,"companyNo")))]);
 //        $kh = $tmp['data']??[];
 
@@ -108,7 +108,7 @@ class Consult extends Base
             ->where(['id'=>array_column($list,'brand_id')])
             ->column('brand_name','id');
 
-//        $userCommon = new \app\admin\common\User();
+//        $userCommon = \app\admin\common\User::getIns();
 //        $names = $userCommon->handle('getCodeAndName', ['code' => array_column($list, 'khNo')]);
 
 
@@ -417,7 +417,7 @@ class Consult extends Base
 ////            $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
 //=======
 
-        $userCommon = new \app\admin\common\User();
+        $userCommon = \app\admin\common\User::getIns();
         $tmp = $userCommon->handle('getCodeAndName', ['code' => [$zxorder['companyNo'],$zxorder['khNo']]]);
 
 //        if($zxorder['khNo']!==""){
@@ -443,7 +443,7 @@ class Consult extends Base
 //            $kccode[]=$zxorder['companyNo'];
 //        }
 //        if(!empty($kccode)){
-//            $userCommon = new \app\admin\common\User();
+//            $userCommon = \app\admin\common\User::getIns();
 //            $tmp = $userCommon->handle('getCodeAndName', ['code' =>$kccode]);
 ////=======
 ////>>>>>>> master-new
@@ -911,7 +911,7 @@ class Consult extends Base
 //            ->field('id,person,personid')
 //            ->where('code',$supplierNo)
 //            ->findOrEmpty();
-	    $userCommon= new \app\admin\common\User();
+	    $userCommon= \app\admin\common\User::getIns();
         $supplier_temp =$userCommon->handle("hqInfo",["code"=>$supplierNo]);
         if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,"供应商信息未找到");
 		$supplierArr=$supplier_temp['data']??[];
@@ -1094,7 +1094,7 @@ class Consult extends Base
         $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
         $info['cat_info'] = made($info['cat_id'],[]);
         $info['noble_weight'] = $info['good_weight'];
-        $user= new \app\admin\common\User();
+        $user= \app\admin\common\User::getIns();
         $supplier =$user->handle("getCodeAndName",["code"=>$info['supplierNo']]);
 //        $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
         $info['supplierName'] = isset($supplier['data'][$info['supplierNo']])?$supplier['data'][$info['supplierNo']]:"";
@@ -1260,7 +1260,7 @@ class Consult extends Base
             $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
             $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
         }
-        $userCommon= new \app\admin\common\User();
+        $userCommon= \app\admin\common\User::getIns();
         $supplier_temp =$userCommon->handle("hqInfo",["code"=>$supplierNo]);
         if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,"供应商信息未找到");
 		$supplierArr=$supplier_temp['data']??[];
@@ -1918,7 +1918,7 @@ class Consult extends Base
             $info['origin_addr'] = $addr;
         }
         $info['supplierNo'] =$bidinfos['supplierNo'];
-        $user= new \app\admin\common\User();
+        $user= \app\admin\common\User::getIns();
         $supplier_temp =$user->handle("getCodeAndName",["code"=>$info['supplierNo']]);
 //        if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('该供应商不存在');
 		$supplier=$supplier_temp['data']??[];
@@ -2014,7 +2014,7 @@ class Consult extends Base
         $page = $page >= $total ? $total : $page;
         $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
         $data=[];
-        $user= new \app\admin\common\User();
+        $user= \app\admin\common\User::getIns();
         $supplier_temp =$user->handle("getCodeAndName",["code"=>array_column($list,"supplierNo")]);
 //        if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('该供应商不存在');
 		$supplier=$supplier_temp['data']??[];
@@ -2144,7 +2144,7 @@ class Consult extends Base
         }
         $list =Db::name('consult_bids')->where($where)->select();
         $data=[];
-        $user= new \app\admin\common\User();
+        $user= \app\admin\common\User::getIns();
         $supplier_temp =$user->handle("getCodeAndName",["code"=>array_column($list,"supplierNo")]);
 //        if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('该供应商不存在');
 		$supplier=$supplier_temp['data']??[];
@@ -2298,7 +2298,7 @@ class Consult extends Base
         $all_createrid = array_column($list, 'createrid');
         $item = get_company_name_by_uid($all_createrid);
 
-        $userCommon = new \app\admin\common\User();
+        $userCommon = \app\admin\common\User::getIns();
         $names = $userCommon->handle('getCodeAndName', ['code' => array_column($list, 'companyNo')]);
 
         $bidinfos_list = Db::name('consult_bids')
@@ -2413,7 +2413,7 @@ class Consult extends Base
         if ($status !== "") {
             $where[]= ["a.status",'=',$status];
         }
-        $userCommon=new \app\admin\common\User();
+        $userCommon=\app\admin\common\User::getIns();
 
         $supplierNo = trim($this->post['supplierNo'] ?? '');
         if ($supplierNo != '') {
@@ -2575,7 +2575,7 @@ class Consult extends Base
             ->select()
             ->toArray();
         $data = [];
-        $user= new \app\admin\common\User();
+        $user= \app\admin\common\User::getIns();
         $supplier_temp =$user->handle("getCodeAndName",["code"=>array_unique(array_merge(array_column($list,"supplierNo"),array_column($list,"companyNo")))]);
 //        if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('该供应商不存在');
 		$supplier=$supplier_temp['data']??[];

+ 405 - 287
app/admin/controller/Purchin.php

@@ -625,338 +625,456 @@ class Purchin extends Base
     public function addBatch()
     {
 
-        $param = $this->request->only(['cgdNo', 'list'], 'post', 'trim');
+        $param = $this->request->filter('trim')->only(['cgdNo'], 'post');
 
-        $val = Validate::rule([
-            'cgdNo|采购单编号' => 'require',
-            'list' => 'require|array|max:100',
-        ]);
+        $val = Validate::rule(['cgdNo|订单编号' => 'require|array|max:100']);
 
-        if ($val->check($param) == false) return json_show(1004, $val->getError());
+        //入库方式 供应商包邮,
+        //运费 0
 
-        $val_child = Validate::rule([
-            'send_num|入库数量' => 'require|number|gt:0',
-            'sendtype|发货方式' => 'require|number|in:1,2',
-            'post_time|发货时间' => 'require|date',
-            'post_fee|物流费用' => 'require|float|max:99999999.99',
-            'status|状态' => 'require|number|in:1,4'
-        ]);
+        if (!$val->check($param)) return json_show(1004, $val->getError());
 
         $cgdinfo = Db::name("purchease_order")
-            ->where(['cgdNo' => $param['cgdNo'], 'is_del' => 0])
-            ->findOrEmpty();
-        if (empty($cgdinfo)) return json_show(1005, "未找到采购单数据");
-        if ($cgdinfo['status'] == 0) return json_show(1005, "采购单未确认");
-        $isreturn = cgd_sale_return($param['cgdNo']);
-        if ($isreturn) return error_show(1005, "关联销售单存在退货单正在进行");
-
-        $wsminfo = Db::name("warehouse_info")
-            ->where(["wsm_code" => $cgdinfo['wsm_code'], "is_del" => 0])
-            ->findOrEmpty();
-        if (empty($wsminfo)) return error_show(1004, "未找到仓库信息");
+            ->whereIn('cgdNo', $param['cgdNo'])
+            ->where(['is_del' => 0, 'supplierNo' => $this->request->user['supplierNo']])
+            ->where('status', 'in', [1, 2])//1待入库,2部分入库
+            ->column('id,wsm_code,good_num,good_price,spuCode,order_type,send_status,status,supplierNo', 'cgdNo');
 
-        $recep = Db::name('warehouse_addr')
-            ->field('wsm_name')
-            ->where(["wsm_code" => $cgdinfo['wsm_code'], "is_del" => 0])
-            ->findOrEmpty();
-
-        $wsmin_num = Db::name("purchease_in")
-            ->where([["cgdNo", "=", $param['cgdNo']], ["is_del", "=", 0], ["status", "not in", [4, 6]]])
-            ->sum("send_num");
-        if (array_sum(array_column($param['list'], 'send_num')) > $cgdinfo['wsend_num'] - $wsmin_num) return error_show(1009, "采购单剩余未发货数量不足");
+        if (empty($cgdinfo)) return json_show(1005, "未找到采购单数据或采购单未发货");
 
-        if ($this->level == 2) {
-            //如果开通了供应商账号,则只允许level3账号操作,level2账号不允许操作
-            $all_has_supplier_account = checkHasAccountBySupplierNos([$cgdinfo['supplierNo']]);
-            if (isset($all_has_supplier_account[$cgdinfo['supplierNo']])) return error_show(1009, '已开通供应商账号,当前账号不能操作');
-        }
+        $all_wsm_code = array_column($cgdinfo, 'wsm_code');
 
-        $userCommon = \app\admin\common\User::getIns();
-        $supplier_temp = $userCommon->handle('sInfo', ['code' => $cgdinfo['supplierNo']]);
-        $person = $supplier_temp['data'];
-
-        if ($this->level == 2 && $this->uid != $person['personid']) throw new Exception('只能由供应商负责人操作');
+        $recep = Db::name('warehouse_addr')
+            ->where('is_del', 0)
+            ->whereIn('wsm_code', $all_wsm_code)
+            ->column('wsm_name', 'wsm_code');
 
-        $is_stock = Db::name('good_basic')
-            ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']])
-            ->value('is_stock');
+        $uid = $this->request->user['uid'];
+        $nickname = $this->request->user['nickname'];
 
         Db::startTrans();
         try {
 
             $date = date('Y-m-d H:i:s');
 
-            $i = 0;
-            foreach ($param['list'] as $item) {
-
-                if ($val_child->check($item)) throw new Exception($val_child->getError());
-
-                $wsm_in_code = substr(makeNo("CF"), 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
-                $bn_code = substr(makeNo("BN"), 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
-
-                if ($item['sendtype'] == 2 || $cgdinfo['order_type'] != 1) $item['status'] = 4;
+//            $supplier_cgderid = Db::name('supplier')
+//                ->where('is_del',0)
+//                ->whereIn('code',array_column($cgdinfo,'supplierNo'))
+//                ->column('personid,person','code');
+            $codes = array_unique(array_column($cgdinfo, 'supplierNo'));
+            $temp = \app\admin\common\User::getIns()->handle('sGetList', ['more_code' => $codes, 'size' => count($codes)]);
+
+            $supplier_cgderid = [];
+            foreach ($temp['data']['list'] as $da) {
+                if (!isset($supplier_cgderid[$da['code']])) $supplier_cgderid[$da['code']] = [
+                    'personid' => $da['personid'],
+                    'person' => $da['person'],
+                ];
+            }
 
-                $orin = [
+            $i = 0;
+            $status = 4;//4入库完成
+            foreach ($param['cgdNo'] as $cgdNo) {
+                $isreturn = cgd_sale_return($cgdNo);
+                if ($isreturn) {
+                    throw new Exception("{$cgdNo}关联销售单存在退货单正在进行");
+                }
+                if (empty($cgdinfo[$cgdNo])) throw new Exception('未找到采购单数据或采购单未发货');
+
+                $wsm_in_code = makeNo("CF");
+                $bn_code = makeNo("BN");
+                $send_num = $cgdinfo[$cgdNo]['good_num'];
+                //改变编码规则,将原编码后两位换成序列号
+                //str_pad字符串填充
+                $wsm_in_code = substr($wsm_in_code, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
+                $i++;
+
+                //入库单
+                $win = Db::name("purchease_in")->insertGetId([
                     "wsm_in_code" => $wsm_in_code,
-                    "cgdNo" => $param['cgdNo'],
+                    "cgdNo" => $cgdNo,
                     "bnCode" => $bn_code,
-                    "wsm_code" => $cgdinfo['wsm_code'],
-                    "wsm_reaper" => $recep['wsm_name'] ?? '',
-                    "send_num" => $item['send_num'],
-                    "post_company" => $item['post_company'] ?? '',
-                    "post_code" => $item['post_code'] ?? '',
-                    "post_fee" => $item['post_fee'],
-                    "sendtime" => $item['post_time'],
-                    "apply_id" => $this->uid,
-                    "apply_name" => $this->uname,
+                    "wsm_code" => $cgdinfo[$cgdNo]['wsm_code'],
+                    "wsm_reaper" => isset($recep[$cgdinfo[$cgdNo]['wsm_code']]) ? $recep[$cgdinfo[$cgdNo]['wsm_code']] : '',
+                    "send_num" => $cgdinfo[$cgdNo]['good_num'],
+                    "post_company" => '',
+                    "post_code" => '',
+                    "post_fee" => 0,//运费固定值:0
+                    "sendtime" => $date,
+                    "apply_id" => $this->request->user['uid'],
+                    "apply_name" => $this->request->user['nickname'],
                     "wait_num" => 0,
                     "wsm_num" => 0,
-                    "sendtype" => $item['sendtype'],
-                    "status" => $item['status'],
+                    "sendtype" => 2,//发货方式,固定值,供应商包邮2
+                    "status" => $status,
                     "addtime" => $date,
                     "updatetime" => $date
-                ];
+                ]);
 
-                $win = Db::name("purchease_in")->insertGetId($orin);
                 if ($win) {
-                    $sto = ["order_code" => $wsm_in_code, "status" => $item['status'], "action_remark" => '', "action_type" => "edit"];
-                    ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $sto, "RKD", $item['status'], $param);
+                    $sto = ["order_code" => $wsm_in_code, "status" => $status, "action_remark" => '', "action_type" => "edit"];
+                    ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], $sto, "RKD", $status, $this->request->filter('trim')->post());
+                    $process = ["order_code" => $wsm_in_code, "order_id" => $win, "order_status" => $status, "order_type" => 'RKD', "before_status" => $status, 'holder_id' => $this->request->user['uid']];
+                    ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], $process);
+                    $order = ["order_code" => $cgdNo, "status" => $cgdinfo[$cgdNo]['status'], "action_remark" => '', "action_type" => "edit"];
 
-//                	  $uid = Db::name('user_role')
-//                                ->where([
-//                                    ['is_del', '=', 0],
-//                                    ['roleid', 'in', [31, 41]],
-//                                    ['status', '=', 1]
-//                                ])->column('uid');
-//                	  $handle_user_list = implode(',', $uid);
+                    //维护台账信息
+                    Db::execute("UPDATE `wsm_standing_book` SET `wsm_in_code`=CONCAT(IFNULL(`wsm_in_code`,''),',{$wsm_in_code}'),`updatetime`='" . $date . "' WHERE `cgdNo`='{$cgdNo}'");
+
+                    //////////////////
+                    $good = Db::name("good_stock")
+                        ->where(["wsm_code" => $cgdinfo[$cgdNo]['wsm_code'], "spuCode" => $cgdinfo[$cgdNo]['spuCode'], "is_del" => 0])
+                        ->lock(true)
+                        ->find();
+                    if (empty($good)) {
+                        $good = [
+                            "spuCode" => $cgdinfo[$cgdNo]['spuCode'],
+                            "wsm_code" => $cgdinfo[$cgdNo]['wsm_code'],
+                            "usable_stock" => 0,
+                            "wait_out_stock" => 0,
+                            "wait_in_stock" => $send_num,
+                            "total_stock" => 0,
+                            "addtime" => date("Y-m-d H:i:s"),
+                            "updatetime" => date("Y-m-d H:i:s"),
+                        ];
+//                        $order = ["order_code" => $good['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "create"];
+                    } else {
+//                        $order = ["order_code" => $good['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "edit"];
+                    }
+                    $good['wait_in_stock'] -= $send_num;
+//                    if ($good['presale_stock'] > 0) {
+//                        if ($good['presale_stock'] >= $send_num) {
+//                            $good['presale_stock'] -= $send_num;
+//                            $good['wait_out_stock'] += $send_num;
+//                        } else {
+//                            $good['presale_stock'] = 0;
+//                            $good['usable_stock'] += $send_num - $good['presale_stock'];
+//                            $good['wait_out_stock'] += $good['presale_stock'];
+//                        }
+//                    } else {
+                    $good['usable_stock'] += $send_num;
+//                    }
 
-                    $process = ["order_code" => $wsm_in_code, "order_id" => $win, "order_status" => $item['status'], "order_type" => 'RKD', "before_status" => $item['status'], 'holder_id' => $orin['apply_id'], "handle_user_list" => $handle_user_list ?? ""];
-                    ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
-                    $order = ["order_code" => $param['cgdNo'], "status" => $cgdinfo['status'], "action_remark" => '', "action_type" => "edit"];
+                    $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
+                    $good['updatetime'] = date("Y-m-d H:i:s");
+                    $upd = Db::name("good_stock")->save($good);
+                    $stockid = $good['id'] ?? Db::name("good_stock")->getLastInsID();
+                    //商品变动日志表,good_log_code字段存储采购单单号
+                    $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => $stockid, "type" => 1, 'stock' => $send_num, "stock_name" => "usable_stock"];
+                    $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => $stockid, "type" => 2, 'stock' => $send_num, "stock_name" => "wait_in_stock"];
+                    if ($upd) {
+                        GoodLog::LogAdd(['id' => $uid, 'nickname' => $nickname], $good_data, 'RKD');
+                        if ($cgdinfo[$cgdNo]['order_type'] == 1) {
+                            $bnin = GoodStockInfo::AddBn($stockid, $bn_code, $send_num, $cgdinfo[$cgdNo]['good_price']);
+                            if ($bnin == false) {
+                                Db::rollback();
+                                return error_show(1004, "库存bn数据新增失败");
+                            }
+                            $bk = Db::name("order_bk")->where(['cgdNo' => $cgdNo])->find();
+                            if ($bk == false) {
+                                $bk = [
+                                    "cgdNo" => $cgdNo,
+                                    "spuCode" => $cgdinfo[$cgdNo]['spuCode'],
+                                    "companyNo" => $cgdinfo[$cgdNo]['companyNo'],
+                                    "total_num" => $send_num,
+                                    "merge_num" => 0,
+                                    "balance_num" => $send_num,
+                                    "status" => 1,
+                                    "is_del" => 0,
+                                    'addtime' => date("Y-m-d H:i:s"),
+                                    "updatetime" => date("Y-m-d H:i:s")
+                                ];
+                                $upcgd = Db::name("order_bk")->save($bk);
+                            } else {
+                                $where = ['id' => $bk['id'], 'total_num' => $bk['total_num'], 'balance_num' => $bk['balance_num']];
+                                $bk['balance_num'] += $send_num;
+                                $bk['total_num'] += $send_num;
+                                $bk['updatetime'] = date("Y-m-d H:i:s");
+                                $upcgd = Db::name("order_bk")->where($where)->update($bk);
+                            }
 
-                    //维护台账信息
-                    Db::execute("UPDATE `wsm_standing_book` SET `wsm_in_code`=CONCAT(IFNULL(`wsm_in_code`,''),',{$wsm_in_code}'),`updatetime`='" . $date . "' WHERE `cgdNo`='{$param['cgdNo']}'");
-
-                    if ($item['status'] == 1) continue;
-                    elseif ($item['status'] == 4) {
-                        $cgdinfo['wsend_num'] -= $item['send_num'];
-                        $cgdinfo['send_num'] += $item['send_num'];
-                        $cgdinfo['send_status'] = $cgdinfo['wsend_num'] == 0 ? 3 : ($cgdinfo['send_num'] == 0 ? 1 : 2);
-                        $cgdinfo['status'] = $cgdinfo['wsend_num'] == 0 ? 3 : ($cgdinfo['send_num'] == 0 ? 1 : 2);
-                        $cgdinfo['updatetime'] = $date;
-                        $up = Db::name("purchease_order")->save($cgdinfo);
-                        if ($up == false) throw new Exception('更新采购单失败');
-                        $good = Db::name("good_stock")
-                            ->where(["wsm_code" => $cgdinfo['wsm_code'], "spuCode" => $cgdinfo['spuCode'], "is_del" => 0])
-                            ->lock(true)->findOrEmpty();
-                        if (empty($good)) {
-                            $good = [
-                                "spuCode" => $cgdinfo['spuCode'],
-                                "wsm_code" => $cgdinfo['wsm_code'],
-                                "usable_stock" => 0,
-                                "wait_out_stock" => 0,
-                                "wait_in_stock" => $item['send_num'],
-                                "total_stock" => 0,
-                                "addtime" => $date,
-                                "updatetime" => $date,
-                            ];
+                            if ($upcgd == false) throw new Exception('采购单数量更新失败');
                         }
-                        $good['wait_in_stock'] -= $item['send_num'];
-                        $good['usable_stock'] += $item['send_num'];
-                        $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
-                        $good['updatetime'] = $date;
-                        $upd = Db::name("good_stock")->save($good);
-                        $stockid = $good['id'] ?? Db::name("good_stock")->getLastInsID();
-                        //商品变动日志表,good_log_code字段存储采购单单号
-                        $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => $stockid, "type" => 1, 'stock' => $item['send_num'], "stock_name" => "usable_stock"];
-                        $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => $stockid, "type" => 2, 'stock' => $item['send_num'], "stock_name" => "wait_in_stock"];
-                        if ($upd) {
-                            GoodLog::LogAdd(['id' => $this->uid, 'nickname' => $this->uname], $good_data, 'RKD');
-
-                            $bnin = GoodStockInfo::AddBn($stockid, $bn_code, $item['send_num'], $cgdinfo['good_price']);
-                            if ($bnin == false) throw new Exception('库存bn数据新增失败');
-
-                            //todo:: 新增bn编号库存数据修改
-                            if ($cgdinfo['order_type'] == 1) {
-//                        	$bnin=GoodStockInfo::AddBn($stockid,$bn_code,$send_num,$cgdinfo['good_price']);
-//	                        if($bnin==false){
-//	                            Db::rollback();
-//	                            return error_show(1004,"库存bn数据新增失败");
-//	                        }
-                                $bk = Db::name("order_bk")->where(['cgdNo' => $cgdinfo['cgdNo']])->find();
-                                if ($bk == false) {
-                                    $bk = [
-                                        "cgdNo" => $cgdinfo['cgdNo'],
-                                        "spuCode" => $cgdinfo['spuCode'],
-                                        "companyNo" => $cgdinfo['companyNo'],
-                                        "total_num" => $item['send_num'],
-                                        "merge_num" => 0,
-                                        "balance_num" => $item['send_num'],
-                                        "status" => 1,
-                                        "is_del" => 0,
-                                        'addtime' => $date,
-                                        "updatetime" => $date
-                                    ];
-                                    $upcgd = Db::name("order_bk")->save($bk);
-                                } else {
-                                    $where = ['id' => $bk['id'], 'total_num' => $bk['total_num'], 'balance_num' => $bk['balance_num']];
-                                    $bk['balance_num'] += $item['send_num'];
-                                    $bk['total_num'] += $item['send_num'];
-                                    $bk['updatetime'] = $date;
-                                    $upcgd = Db::name("order_bk")->where($where)->update($bk);
-                                }
-
-                                if ($upcgd == false) throw new Exception('采购单数量更新失败');
+                        if (in_array($cgdinfo[$cgdNo]['send_status'], [1, 2]) && $cgdinfo[$cgdNo]['order_type'] != 1) {
+                            $send = Db::name("order_send")->where(["cgdNo" => $cgdNo, "status" => 1])->column("outCode");
+                            if (!empty($send)) {
+                                $out = Db::name("order_out")->where(["outCode" => $send, "status" => 0])->select()->toArray();
+                                if (!empty($out)) {
+                                    $up = Db::name("order_out")->where(["outCode" => $send, "status" => 0])->update(["status" => 1, 'wsm_code' => $cgdinfo[$cgdNo]['wsm_code'], "updatetime" => date('Y-m-d H:i:s')]);
+                                    if ($up == false) throw new Exception('出库单出库失败');
+                                    else {
 
-                                //商品表里的'可用总库存数'增加
-                                Db::name('good')
-                                    ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']])
-                                    ->inc('usable_stock', $item['send_num'])
-                                    ->update(['updatetime' => $date]);
+                                        //查询是否有非库存品订单
+                                        $is_stock = Db::name('sale')
+                                            ->where([
+                                                ['is_del', '=', 0],
+                                                ['orderCode', 'in', array_column($out, 'orderCode')]
+                                            ])->column('is_stock', 'orderCode');
 
-                            }
-                            if ($cgdinfo['send_status'] == 3 && $cgdinfo['order_type'] != 1) {
-                                $send = Db::name("order_send")->where(["cgdNo" => $param['cgdNo'], "status" => 1])->column("outCode");
-                                if (!empty($send)) {
-                                    $out = Db::name("order_out")
-                                        ->where(["outCode" => $send, "status" => 0, "is_del" => 0])
-                                        ->select()
-                                        ->toArray();
-                                    if (!empty($out)) {
-                                        $up = Db::name("order_out")
-                                            ->where(["outCode" => $send, "status" => 0, "is_del" => 0])
-                                            ->update(["status" => 1, 'wsm_code' => $cgdinfo['wsm_code'], "updatetime" => $date]);
-                                        if ($up == false) throw new Exception('出库单出库失败');
-                                        else {
-
-                                            //尝试拆单
-                                            \app\admin\model\OrderOutChild::makeChild($send);
-
-                                            //查询是否有非库存品订单
-//                                        $is_stock = Db::name('sale')
-//                                            ->where([
-//                                                ['is_del','=',0],
-//                                                ['orderCode','in',array_column($out,'orderCode')]
-//                                            ])->column('is_stock','orderCode');
+                                        foreach ($out as $k => $v_outCode) {
+                                            //修改状态,添加待办
+                                            ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], [
+                                                "order_code" => $v_outCode['outCode'],//出库单号
+                                                "status" => 0,//这里的status是之前的值
+                                                "action_remark" => '',//备注
+                                                "action_type" => "status"//新建create,编辑edit,更改状态status
+                                            ], "CKD", 1, $param);
 
-//                                        $supplier = Db::name('supplier')
-//                                            ->field('person,personid')
-//                                            ->where(['code'=>$cgdinfo['supplierNo'],'is_del'=>0])
-//                                            ->findOrEmpty();
 
-                                            foreach ($out as $k => $v_outCode) {
-                                                ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
+                                            //库存品,推给库管和库管-张凯旋
+                                            if ($is_stock[$v_outCode['orderCode']] == 1) {
+                                                $roleid = config('app.wsm_cgder_role');
+                                                $uids = Db::name('user_role')
+                                                    ->where('is_del', 0)
+                                                    ->whereIn('roleid', $roleid)
+                                                    ->column('uid');
+                                                ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [
+                                                    "order_type" => 'CKD',
                                                     "order_code" => $v_outCode['outCode'],//出库单号
-                                                    "status" => 0,//这里的status是之前的值
-                                                    "action_remark" => '',//备注
-                                                    "action_type" => "status"//新建create,编辑edit,更改状态status
-                                                ], "CKD", 1, $this->post);
-
-                                                if ($is_stock == 1) {
-                                                    //库存品,推给库管和库管-张凯旋
-                                                    $roleid = config('app.wsm_cgder_role');
-                                                    $uids = Db::name('user_role')
-                                                        ->where('is_del', 0)
-                                                        ->whereIn('roleid', $roleid)
-                                                        ->column('uid');
-                                                    ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
-                                                        "order_type" => 'CKD',
-                                                        "order_code" => $v_outCode['outCode'],//出库单号
-                                                        "order_id" => $v_outCode['id'],
-                                                        "order_status" => 1,
-                                                        "before_status" => 0,
-//                                                    'wait_id' => $supplier['personid'],
-//                                                    'wait_name' => $supplier['person'],
-//                                                    'holder_id' => $supplier['personid'],
-                                                        'handle_user_list' => implode(',', $uids)
-                                                    ]);
-                                                } else {
-                                                    //非库存品和采返商品,推给供应商负责人
-                                                    ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
-                                                        "order_type" => 'CKD',
-                                                        "order_code" => $v_outCode['outCode'],//出库单号
-                                                        "order_id" => $v_outCode['id'],
-                                                        "order_status" => 1,
-                                                        "before_status" => 0,
-                                                        'wait_id' => $person['personid'] ?? 0,
-                                                        'wait_name' => $person['person'] ?? '',
-                                                        'holder_id' => $person['personid'] ?? 0,
-                                                    ]);
-                                                }
-
+                                                    "order_id" => $v_outCode['id'],
+                                                    "order_status" => 1,
+                                                    "before_status" => 0,
+//                                                    'wait_id' => $wait['personid'],
+//                                                    'wait_name' => $wait['person'],
+//                                                    'holder_id' => $wait['personid'],
+                                                    'handle_user_list' => implode(',', $uids)
+                                                ]);
+                                            } else {
+                                                //推给供应商负责人
+                                                $wait = $supplier_cgderid[$cgdinfo[$cgdNo]['supplierNo']];
+                                                ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [
+                                                    "order_type" => 'CKD',
+                                                    "order_code" => $v_outCode['outCode'],//出库单号
+                                                    "order_id" => $v_outCode['id'],
+                                                    "order_status" => 1,
+                                                    "before_status" => 0,
+                                                    'wait_id' => $wait['personid'],
+                                                    'wait_name' => $wait['person'],
+                                                    'holder_id' => $wait['personid'],
+                                                ]);
                                             }
-                                        }
-                                        $good1 = Db::name("good_stock")->where(["wsm_code" => $cgdinfo['wsm_code'], "spuCode" => $cgdinfo['spuCode'], "is_del" => 0])->find();
-                                        if ($good1 == false) throw new Exception('未找到对应商品库存');
-                                        $out_num = intval(array_sum(array_column($out, "send_num")));
-                                        if ($out_num > $good1['usable_stock']) throw new Exception('库存数量不足发货');
-                                        $good1['usable_stock'] -= $out_num;
-                                        $good1['wait_out_stock'] += $out_num;
-                                        $good1['total_stock'] = $good1['usable_stock'] + $good1['wait_out_stock'];
-                                        $good1['updatetime'] = $date;
-                                        $upd = Db::name("good_stock")->save($good1);
-                                        if ($upd == false) throw new Exception('库存数量更新失败');
-                                        $stockid = isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID();
-
-                                        $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => $stockid, "type" => 1, 'stock' => $item['send_num'], "stock_name" => "wait_out_stock"];
-                                        $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => $stockid, "type" => 1, 'stock' => $item['send_num'], "stock_name" => "usable_stock"];
-                                        GoodLog::LogAdd(['id' => $this->uid, 'nickname' => $this->uname], $good_data, 'RKD');
-                                        $sendp = Db::name("order_send")
-                                            ->where(["cgdNo" => $param['cgdNo'], "outCode" => $send, "status" => 1])
-                                            ->save(["status" => 2]);
-                                        if ($sendp == false) throw new Exception("库存发货失败");
 
+                                        }
                                     }
-                                }
+                                    $good1 = Db::name("good_stock")->where(["wsm_code" => $cgdinfo[$cgdNo]['wsm_code'], "spuCode" => $cgdinfo[$cgdNo]['spuCode'], "is_del" => 0])->find();
+                                    if ($good1 == false) throw new Exception('未找到对应商品库存');
+                                    $out_num = intval(array_sum(array_column($out, "send_num")));
+                                    if ($out_num > $good1['usable_stock']) throw new Exception('库存数量不足发货');
+
+                                    $good1['usable_stock'] -= $out_num;
+                                    $good1['wait_out_stock'] += $out_num;
+                                    $good1['total_stock'] = $good1['usable_stock'] + $good1['wait_out_stock'];
+                                    $good1['updatetime'] = date("Y-m-d H:i:s");
+                                    $upd = Db::name("good_stock")->save($good1);
+                                    if ($upd == false) throw new Exception('库存数量更新失败');
 
-                                //商品表里的'可用总库存数'增加
-                                Db::name('good_zixun')
-                                    ->where(['is_del' => 0, 'spuCode' => $cgdinfo['spuCode']])
-                                    ->inc('usable_stock', $item['send_num'])
-                                    ->update(['updatetime' => $date]);
+                                    $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $send_num, "stock_name" => "wait_out_stock"];
+                                    $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $send_num, "stock_name" => "usable_stock"];
+                                    GoodLog::LogAdd(['id' => $uid, 'nickname' => $nickname], $good_data, 'RKD');
+                                    $sendp = Db::name("order_send")->where(["cgdNo" => $cgdNo, "outCode" => $send, "status" => 1])->save(["status" => 2]);
+                                    if ($sendp == false) throw new Exception('库存发货失败');
+
+                                }
                             }
+                        }
+                        ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], $order, "CGD", $cgdinfo[$cgdNo]['status'], $cgdinfo[$cgdNo]);
+                        $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo[$cgdNo]['id'], "order_status" => $cgdinfo[$cgdNo]['status'], "order_type" => 'CGD', "before_status" => $order['status'], 'holder_id' => isset($supplier_cgderid[$cgdinfo[$cgdNo]['supplierNo']]['personid']) ? $supplier_cgderid[$cgdinfo[$cgdNo]['supplierNo']]['personid'] : 0];
+                        ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], $process);
+//                        Db::commit();
+//                        return json_show(0, '商品入库成功', ["wsm_in_code" => $wsm_in_code]);
+                    } else throw new Exception('商品入库失败');
+                    //////////////////
 
-                            ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $order, "CGD", $cgdinfo['status'], $cgdinfo);
 
-//                        $personid = Db::name('supplier')
-//                            ->where('is_del',0)
-//                            ->where('code',$cgdinfo['supplierNo'])
-//                            ->value('personid');
-
-                            if ($cgdinfo['status'] == 1 || $cgdinfo['status'] == 2) {
+                } else throw new Exception('新建入库单失败');
+            }
 
-//                            $is_stock = Db::name('good_basic')
-//                                ->where(['is_del'=>0,'spuCode'=>$cgdinfo['spuCode']])
-//                                ->value('is_stock');
-//                            if($is_stock==1){
-//                                //库存品,推给31库管人员、41库管-张凯旋
-//                                $uid = Db::name('user_role')
-//                                    ->where([
-//                                        ['is_del', '=', 0],
-//                                        ['roleid', 'in', [31, 41]],
-//                                        ['status', '=', 1]
-//                                    ])->column('uid');
-//                                if(!in_array($this->uid,$uid)) throw new Exception('库存品订单只能由库管人员操作');
-////                                $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo['id'], "order_status" => $cgdinfo['status'], "order_type" => 'CGD', "before_status" => $order['status'], 'holder_id' => $personid,'handle_user_list'=>implode(',', $uid)];
-//
-//                            }else{
-//                            }
-                            }//else $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo['id'], "order_status" => $cgdinfo['status'], "order_type" => 'CGD', "before_status" => $order['status'], 'holder_id' => $personid];
+            //维护原有采购单信息
+            Db::name("purchease_order")
+                ->whereIn('id', array_column($cgdinfo, 'id'))
+                ->update([
+                    'wsend_num' => 0,
+                    'send_num' => Db::raw('good_num'),
+                    'send_status' => 3,
+                    'status' => 3,
+                    'updatetime' => date("Y-m-d H:i:s"),
+                ]);
 
-                            ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], ["order_code" => $param['cgdNo'], "order_id" => $cgdinfo['id'], "order_status" => $cgdinfo['status'], "order_type" => 'CGD', "before_status" => $order['status'], 'holder_id' => $person['personid'] ?? 0]);
-//                            Db::commit();
-//                            return app_show(0,'商品入库成功',["wsm_in_code"=>$wsm_in_code]);
-                        } else throw new Exception('商品入库失败');
-                    }
-//                    Db::commit();
-//                    return app_show(0,'商品入库成功',["wsm_in_code"=>$wsm_in_code]);
-                }
+            Db::commit();
+            return json_show(0, '新建入库单成功');
 
+//            $win = Db::name("purchease_in")->insert($orin, true);
+//            if ($win) {
+//                $sto = ["order_code" => $wsm_in_code, "status" => $status, "action_remark" => '', "action_type" => "edit"];
+//                ActionLog::logAdd($this->post['token'], $sto, "RKD", $status, $this->post);
+//                $process = ["order_code" => $wsm_in_code, "order_id" => $win, "order_status" => $status, "order_type" => 'RKD', "before_status" => $status];
+//                ProcessOrder::AddProcess($this->post['token'], $process);
+//                $order = ["order_code" => $cgdNo, "status" => $cgdinfo['status'], "action_remark" => '', "action_type" => "edit"];
 
-            }
+            //维护台账信息
+//                Db::execute("UPDATE `wsm_standing_book` SET `wsm_in_code`=CONCAT(IFNULL(`wsm_in_code`,''),',{$wsm_in_code}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `cgdNo`='{$cgdNo}'");
 
-            Db::commit();
-            return json_show(0, "商品入库成功");
+//                if ($status == 1) {
+//                    Db::commit();
+//                    return json_show(0, '新建成功', ["wsm_in_code" => $wsm_in_code]);
+//                }
+//                if ($status == 4) {
+//                    $cgdinfo['wsend_num'] -= $send_num;
+//                    $cgdinfo['send_num'] += $send_num;
+//                    $cgdinfo['send_status'] = $cgdinfo['wsend_num'] == 0 ? 3 : ($cgdinfo['send_num'] == 0 ? 1 : 2);
+//                    $cgdinfo['status'] = $cgdinfo['wsend_num'] == 0 ? 3 : ($cgdinfo['send_num'] == 0 ? 1 : 2);
+//                    $cgdinfo['updatetime'] = date("Y-m-d H:i:s");
+//                    $up = Db::name("purchease_order")->save($cgdinfo);
+//                    if ($up == false) {
+//                        Db::rollback();
+//                        return json_show(1004, "新建失败");
+//                    }
+//            $good = Db::name("good_stock")
+//                ->where(["wsm_code" => $cgdinfo['wsm_code'], "spuCode" => $cgdinfo['spuCode'], "is_del" => 0])
+//                ->lock(true)
+//                ->find();
+//            if (empty($good)) {
+//                $good = [
+//                    "spuCode" => $cgdinfo['spuCode'],
+//                    "wsm_code" => $cgdinfo['wsm_code'],
+//                    "usable_stock" => 0,
+//                    "wait_out_stock" => 0,
+//                    "wait_in_stock" => $send_num,
+//                    "total_stock" => 0,
+//                    "addtime" => date("Y-m-d H:i:s"),
+//                    "updatetime" => date("Y-m-d H:i:s"),
+//                ];
+//                //   $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'',
+//                // "action_type"=>"create"];
+//            } else {
+//                //   $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'',
+//                // "action_type"=>"edit"];
+//            }
+//            $good['wait_in_stock'] -= $send_num;
+//            if ($good['presale_stock'] > 0) {
+//                if ($good['presale_stock'] >= $send_num) {
+//                    $good['presale_stock'] -= $send_num;
+//                    $good['wait_out_stock'] += $send_num;
+//                } else {
+//                    $good['presale_stock'] = 0;
+//                    $good['usable_stock'] += $send_num - $good['presale_stock'];
+//                    $good['wait_out_stock'] += $good['presale_stock'];
+//                }
+//            } else {
+//                $good['usable_stock'] += $send_num;
+//            }
+//
+//            $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
+//            $good['updatetime'] = date("Y-m-d H:i:s");
+//            $upd = Db::name("good_stock")->save($good);
+//            //商品变动日志表,good_log_code字段存储采购单单号
+//            $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $send_num, "stock_name" => "usable_stock"];
+//            $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 2, 'stock' => $send_num, "stock_name" => "wait_in_stock"];
+//            if ($upd) {
+//                GoodLog::LogAdd($this->post['token'], $good_data, 'RKD');
+//                if ($cgdinfo['order_type'] == 1) {
+//                    $bk = Db::name("order_bk")->where(['cgdNo' => $cgdinfo['cgdNo']])->find();
+//                    if ($bk == false) {
+//                        $bk = [
+//                            "cgdNo" => $cgdinfo['cgdNo'],
+//                            "spuCode" => $cgdinfo['spuCode'],
+//                            "companyNo" => $cgdinfo['companyNo'],
+//                            "total_num" => $send_num,
+//                            "merge_num" => 0,
+//                            "balance_num" => $send_num,
+//                            "status" => 1,
+//                            "is_del" => 0,
+//                            'addtime' => date("Y-m-d H:i:s"),
+//                            "updatetime" => date("Y-m-d H:i:s")
+//                        ];
+//                        $upcgd = Db::name("order_bk")->save($bk);
+//                    } else {
+//                        $where = ['id' => $bk['id'], 'total_num' => $bk['total_num'], 'balance_num' => $bk['balance_num']];
+//                        $bk['balance_num'] += $send_num;
+//                        $bk['total_num'] += $send_num;
+//                        $bk['updatetime'] = date("Y-m-d H:i:s");
+//                        $upcgd = Db::name("order_bk")->where($where)->update($bk);
+//                    }
+//
+//                    if ($upcgd == false) {
+//                        Db::rollback();
+//                        return json_show(1004, "采购单数量更新失败");
+//                    }
+//                }
+//                if ($cgdinfo['send_status'] == 3 && $cgdinfo['order_type'] != 1) {
+//                    $send = Db::name("order_send")->where(["cgdNo" => $cgdNo, "status" => 1])->column("outCode");
+//                    if (!empty($send)) {
+//                        $out = Db::name("order_out")->where(["outCode" => $send, "status" => 0])->select()
+//                            ->toArray();
+//                        if (!empty($out)) {
+//                            $up = Db::name("order_out")->where(["outCode" => $send, "status" => 0])->update
+//                            (["status" => 1, 'wsm_code' => $cgdinfo['wsm_code'], "updatetime" => date('Y-m-d H:i:s')]);
+//                            if ($up == false) {
+//                                Db::rollback();
+//                                return json_show(1004, "出库单出库失败");
+//                            } else {
+//                                foreach ($out as $k => $v_outCode) {
+//                                    //修改状态,添加待办
+//                                    ActionLog::logAdd($this->post['token'], [
+//                                        "order_code" => $v_outCode['outCode'],//出库单号
+//                                        "status" => 0,//这里的status是之前的值
+//                                        "action_remark" => '',//备注
+//                                        "action_type" => "status"//新建create,编辑edit,更改状态status
+//                                    ], "CKD", 1, $this->post);
+//
+//                                    ProcessOrder::AddProcess($this->post['token'], [
+//                                        "order_type" => 'CKD',
+//                                        "order_code" => $v_outCode['outCode'],//出库单号
+//                                        "order_id" => $v_outCode['id'],
+//                                        "order_status" => 1, "before_status" => 0
+//                                    ]);
+//                                }
+//                            }
+//                            $good1 = Db::name("good_stock")->where(["wsm_code" => $cgdinfo['wsm_code'], "spuCode" => $cgdinfo['spuCode'], "is_del" => 0])->find();
+//                            if ($good1 == false) {
+//                                Db::rollback();
+//                                return json_show(1004, "未找到对应商品库存");
+//                            }
+//                            $out_num = intval(array_sum(array_column($out, "send_num")));
+//                            if ($out_num > $good1['usable_stock']) {
+//                                Db::rollback();
+//                                return json_show(1004, "库存数量不足发货");
+//                            }
+//                            $good1['usable_stock'] -= $out_num;
+//                            $good1['wait_out_stock'] += $out_num;
+//                            $good1['total_stock'] = $good1['usable_stock'] + $good1['wait_out_stock'];
+//                            $good1['updatetime'] = date("Y-m-d H:i:s");
+//                            $upd = Db::name("good_stock")->save($good1);
+//                            if ($upd == false) {
+//                                Db::rollback();
+//                                return json_show(1004, "库存数量更新失败");
+//                            }
+//                            $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $send_num, "stock_name" => "wait_out_stock"];
+//                            $good_data[] = ['good_log_code' => $wsm_in_code, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $send_num, "stock_name" => "usable_stock"];
+//                            GoodLog::LogAdd($this->post['token'], $good_data, 'RKD');
+//                            $sendp = Db::name("order_send")->where(["cgdNo" => $cgdNo, "outCode" => $send, "status" => 1])->save(["status" => 2]);
+//                            if ($sendp == false) {
+//                                Db::rollback();
+//                                return json_show(1004, "库存发货失败");
+//                            }
+//                        }
+//                    }
+//                }
+//                ActionLog::logAdd($this->post['token'], $order, "CGD", $cgdinfo['status'], $cgdinfo);
+//                $process = ["order_code" => $cgdNo, "order_id" => $cgdinfo['id'], "order_status" => $cgdinfo['status'], "order_type" => 'CGD', "before_status" => $order['status']];
+//                ProcessOrder::AddProcess($this->post['token'], $process);
+//                Db::commit();
+//                return json_show(0, '商品入库成功', ["wsm_in_code" => $wsm_in_code]);
+//            } else {
+//                Db::rollback();
+//                return json_show(1002, "商品入库失败");
+//            }
+//                }
+//                Db::commit();
+//                return json_show(0, '新建成功', ["wsm_in_code" => $wsm_in_code]);
+//            }
+//            Db::rollback();
+//            return json_show(1004, "新建失败");
         } catch (Exception $e) {
             Db::rollback();
             return json_show(1004, $e->getMessage());

+ 2 - 1
app/admin/controller/Sale.php

@@ -378,7 +378,8 @@ class Sale extends Base
                                 throw new Exception("发货地址添加创建失败");
 //                                return error_show(1002, "发货地址添加创建失败");
                             } else {
-                           if ($is_stock == 1)OrderOutChild::makeChild($outCode);
+                                if($is_stock==1) OrderOutChild::makeChild($outCode);//库存品拆单
+
                                 //修改状态,添加待办
                                 ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
                                     "order_code" => $outCode,//出库单号

+ 131 - 118
app/admin/model/OrderOutChild.php

@@ -1,134 +1,147 @@
 <?php
-declare (strict_types = 1);
+declare (strict_types=1);
 
 namespace app\admin\model;
 
-use app\admin\common\YouZan;use think\Exception;use think\Model;
+use app\admin\common\YouZan;
+use think\Exception;
+use think\Model;
 
 /**
  * @mixin \think\Model
  */
 class OrderOutChild extends Model
-{   /**
-	* @param string $outCode 发货单信息
-	* @throws \Exception
-	 */
-    static function makeChild(string $outCode=''){
-    	if($outCode=='')throw new \Exception("工单发货单单号不能为空");
-    	$out=self::name("order_out")->where(["outCode"=>$outCode,"is_del"=>0])->findOrEmpty();
-		if(empty($out)) throw new \Exception("发货单信息未找到");
-		if($out['send_status']!=0) throw new \Exception("发货单拆单状态有误");
-		$sale = self::name("sale")->where(["orderCode"=>$out['orderCode'],"is_del"=>0])->findOrEmpty();
-		if(empty($sale)) throw new \Exception("订单信息未找到");
-		if($sale['wsend_num']<$out['send_num']) throw new \Exception("订单待发货数量不足");
-		$num= $out['send_num'];
-		$wsmlist = self::name("good_stock")->alias("a")
-			->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code and b.wsm_type in (2,5)")
-			->field("a.id,a.usable_stock,a.wait_out_stock,b.wsm_code,b.supplierNo,b.supplierName")
-			->where(["spuCode"=>$sale['good_code'],"a.is_del"=>0,"b.companyNo"=>$sale['companyNo']])
-			->where(["a.usable_stock",">=",$num])
-			->order("a.usable_stock asc")
-			->findOrEmpty();
-		$child=[
-			"outChildCode"=>'',
-			"outCode"=>$outCode,
-			"orderCode"=>$sale['orderCode'],
-			"companyNo"=>$sale['supplierNo'],
-			"companyName"=>$sale['supplierName'],
-			"supplierNo"=>$sale['supNo'],
-			"supplierName"=>$sale['supName'],
-			"cutomer_code"=>$sale['cutomer_code'],
-			"spuCode"=>$sale['good_code'],
-			"skuCode"=>$sale['skuCode'],
-			"good_name"=>$sale['good_name'],
-			"order_type"=>$sale['order_type'],
-			"order_source"=>$sale['order_source'],
-			"num"=>$num,
-			"wsm_code"=>$wsmlist['wsm_code']??'',
-			"apply_id"=>$out['apply_id'],
-			"apply_name"=>$out['apply_name'],
-			"addrid"=>$out['addrid'],
-			"addtime"=>date("Y-m-d H:i:s"),
-			"updatetime"=>date("Y-m-d H:i:s")
-		];
-		if(empty($wsmlist)) self::BratchChild($child);
-		else self::SingleChild($child,$wsmlist['id']);
-		$outup=self::name("order_out")->where(["outCode"=>$outCode,"is_del"=>0])->update(["send_status"=>2,"status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
-		if($outup==false)throw new \Exception("发货单信息更新失败");
-		return true;
+{
+    /**
+     * @param string $outCode 发货单信息
+     * @throws \Exception
+     */
+    static function makeChild(string $outCode = '')
+    {
+        if ($outCode == '') throw new \Exception("工单发货单单号不能为空");
+        $out = self::name("order_out")->where(["outCode" => $outCode, "is_del" => 0])->findOrEmpty();
+        if ($out->isEmpty()) throw new \Exception("发货单信息未找到");
+        if ($out['send_status'] != 0) throw new \Exception("发货单拆单状态有误");
+        $sale = self::name("sale")->where(["orderCode" => $out['orderCode'], "is_del" => 0])->findOrEmpty();
+        if ($sale->isEmpty()) throw new \Exception("订单信息未找到");
+        if ($sale['wsend_num'] < $out['send_num']) throw new \Exception("订单待发货数量不足");
+        $num = $out['send_num'];
+        $wsmlist = self::name("good_stock")->alias("a")
+            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code and b.wsm_type in (2,5)")
+            ->field("a.id,a.usable_stock,a.wait_out_stock,b.wsm_code,b.supplierNo,b.supplierName")
+            ->where(["spuCode" => $sale['good_code'], "a.is_del" => 0, "b.companyNo" => $sale['companyNo']])
+            ->where("a.usable_stock", ">=", $num)
+            ->order("a.usable_stock asc")
+            ->findOrEmpty();
+        $child = [
+            "outChildCode" => '',
+            "outCode" => $outCode,
+            "orderCode" => $sale['orderCode'],
+            "companyNo" => $sale['supplierNo'],
+            "companyName" => $sale['supplierName'],
+            "supplierNo" => $sale['supNo'],
+            "supplierName" => $sale['supName'],
+            "cutomer_code" => $sale['cutomer_code'],
+            "spuCode" => $sale['good_code'],
+            "skuCode" => $sale['skuCode'],
+            "good_name" => $sale['good_name'],
+            "order_type" => $sale['order_type'],
+            "order_source" => $sale['order_source'],
+            "num" => $num,
+            "wsm_code" => $wsmlist['wsm_code'] ?? '',
+            "apply_id" => $out['apply_id'],
+            "apply_name" => $out['apply_name'],
+            "addrid" => $out['addrid'],
+            "addtime" => date("Y-m-d H:i:s"),
+            "updatetime" => date("Y-m-d H:i:s")
+        ];
+
+        if ($wsmlist->isEmpty()) self::BratchChild($child);
+        else self::SingleChild($child, $wsmlist['id']);
+        $outup = self::name("order_out")->where(["outCode" => $outCode, "is_del" => 0])->update(["send_status" => 2, "status" => 1, "updatetime" => date("Y-m-d H:i:s")]);
+        if ($outup == false) throw new \Exception("发货单信息更新失败");
+        return true;
     }
-	/**单工单创建
-	* @param array $child
-	* @param int $wsm_id
-	* @throws \think\Exception
-	 */
-    public static function SingleChild(array $child=[],int $wsm_id=0){
-		if(empty($child)) throw new Exception("发货工单信息不能为空");
-		$child['outChildCode'] = makeNo("TCD");
-		$childout=self::insert($child);
-		if($childout==false)throw new \Exception("发货工单生成失败");
-		$bnadd = GoodStockInfo::ChildAddBn($child['outChildCode'],$wsm_id);
-		if($bnadd==false)throw new \Exception("库存更新失败");
+
+    /**单工单创建
+     * @param array $child
+     * @param int $wsm_id
+     * @throws \think\Exception
+     */
+    public static function SingleChild(array $child = [], int $wsm_id = 0)
+    {
+        if (empty($child)) throw new Exception("发货工单信息不能为空");
+        $child['outChildCode'] = makeNo("TCD");
+        $childout = self::insert($child);
+        if ($childout == false) throw new \Exception("发货工单生成失败");
+        $bnadd = GoodStockInfo::ChildAddBn($child['outChildCode'], $wsm_id);
+        if ($bnadd == false) throw new \Exception("库存更新失败");
 
     }
-	/**多工单创建
-	* @param array $child
-	* @throws \think\Exception
-	 */
-    public static function BratchChild(array $child=[]){
-		if(empty($child)) throw new Exception("工单信息不能为空");
-		$stock = self::name("good_stock")->alias("a")
-			->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code and b.wsm_type in (2,5)")
-			->where(["spuCode"=>$child['good_code'],"a.is_del"=>0,"b.companyNo"=>$child['companyNo']])
-			->order("a.usable_stock desc")
-			->column("a.id,a.usable_stock,a.wait_out_stock,b.wsm_code,b.supplierNo,b.supplierName","a.id");
-		if(empty($stock)) throw new Exception("商品库存信息未找到");
-		$wsmArr =self::GetKeyBySum($stock,$child['num']);
-		if(empty($wsmArr)) throw new Exception("库存数不足生成工单");
-		$i=0;
-		foreach ($wsmArr as $key=>$val){
-			$i++;
-			$child['outChildCode'] = substr(makeNo("TCD"), 0, -3) . str_pad($i, 3, '0', STR_PAD_LEFT);
-			$child['num'] = $val['desc_num']??0;
-			$child['wsm_code'] = $val['wsm_code'];
-			$childout=self::insert($child);
-			if($childout==false)throw new \Exception("工单生成失败");
-			$bnadd = GoodStockInfo::ChildAddBn($child['outChildCode'],$val['id']);
-			if($bnadd==false)throw new \Exception("库存更新失败");
-		}
+
+    /**多工单创建
+     * @param array $child
+     * @throws \think\Exception
+     */
+    public static function BratchChild(array $child = [])
+    {
+
+        if (empty($child)) throw new Exception("工单信息不能为空");
+        $stock = self::name("good_stock")->alias("a")
+            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code and b.wsm_type in (2,5)")
+            ->where(["spuCode" => $child['spuCode'], "a.is_del" => 0, "b.companyNo" => $child['companyNo']])
+            ->order("a.usable_stock desc")
+            ->column("a.id,a.usable_stock,a.wait_out_stock,b.wsm_code,b.supplierNo,b.supplierName", "a.id");
+
+        if (empty($stock)) throw new Exception("商品库存信息未找到");
+        $wsmArr = self::GetKeyBySum($stock, intval($child['num']));
+        if (empty($wsmArr)) throw new Exception("库存数不足生成工单");
+        $i = 0;
+        foreach ($wsmArr as $key => $val) {
+            $i++;
+            $child['outChildCode'] = substr(makeNo("TCD"), 0, -3) . str_pad($i, 3, '0', STR_PAD_LEFT);
+            $child['num'] = $val['desc_num'] ?? 0;
+            $child['wsm_code'] = $val['wsm_code'];
+            $childout = self::insert($child);
+            if ($childout == false) throw new \Exception("工单生成失败");
+            $bnadd = GoodStockInfo::ChildAddBn($child['outChildCode'], intval($val['id']));
+            if ($bnadd == false) throw new \Exception("库存更新失败");
+        }
     }
-	/**仓库选择
-	* @param array $Arr
-	* @param int $num
-	* @return array
-	* @throws \Exception
-	*/
-    private static function GetKeyBySum( array $Arr=[],int $num=0){
-    	    $resp=[];
-    	    $keys = array_keys($Arr);
-    	    $stock =array_column($Arr,"usable_stock");
-    	    $newArr=array_combine($keys,$stock);
-    	    if(array_sum($stock)<$num) throw new \Exception("库存数不足生成工单");
-			foreach ($Arr as $key=>$value){
-				if($value['usable_stock']>=$num){
-						$value['desc_num'] = $num;
-						$num=0;
-				}else{
-					$value['desc_num'] = $value['usable_stock'];
-					$num-=$value['usable_stock'];
-				}
-				$resp[]=$value;
-				if($num==0)break;
-				unset($newArr[$key]);
-				$k=array_search($num,$newArr);
-				if($k===false) continue;
-				else{
-					$Arr[$k]['desc_num'] = $num;
-					$resp[]=$Arr[$k];
-					break;
-				}
-			}
-			return $resp;
+
+    /**仓库选择
+     * @param array $Arr
+     * @param int $num
+     * @return array
+     * @throws \Exception
+     */
+    private static function GetKeyBySum(array $Arr = [], int $num = 0)
+    {
+        $resp = [];
+        $keys = array_keys($Arr);
+        $stock = array_column($Arr, "usable_stock");
+        $newArr = array_combine($keys, $stock);
+        if (array_sum($stock) < $num) throw new \Exception("库存数不足生成工单");
+        foreach ($Arr as $key => $value) {
+            if ($value['usable_stock'] >= $num) {
+                $value['desc_num'] = $num;
+                $num = 0;
+            } else {
+                $value['desc_num'] = $value['usable_stock'];
+                $num -= $value['usable_stock'];
+            }
+            $resp[] = $value;
+            if ($num == 0) break;
+            unset($newArr[$key]);
+            $k = array_search($num, $newArr);
+            if ($k === false) continue;
+            else {
+                $Arr[$k]['desc_num'] = $num;
+                $resp[] = $Arr[$k];
+                break;
+            }
+        }
+        return $resp;
     }
 
 }

+ 2 - 0
app/admin/route/app.php

@@ -301,6 +301,8 @@ Route::rule('afterwsm', 'admin/After/GetWsm');
 Route::rule('aftercancel', 'admin/After/Cancel');
 Route::rule('createSaleAndCgdByAfter', 'admin/After/createSaleAndCgdByAfter');
 Route::rule('afterExport', 'admin/After/export');
+Route::rule('after_child_list', 'admin/AfterChild/getList');//退货工单列表
+Route::rule('set_order_return_child', 'admin/AfterChild/setOrderReturnChild');//设置退货工单
 //Route::rule('aftersetwsm','admin/After/setWsm');
 
 Route::rule('processolist', 'admin/Proorder/list');//我的已办