Kaynağa Gözat

Merge branch 'master-new' into master-new-wgg

wugg 2 yıl önce
ebeveyn
işleme
64cb188024

+ 35 - 4
app/admin/controller/After.php

@@ -392,8 +392,16 @@ class After extends Base
 
         $addcode = '';
         if ($info['addr_code'] != "") {
-            list($a, $b, $c) = explode(",", $info['addr_code']);
-            $addcode = json_encode(["provice_code" => $a, "city_code" => $b, "area_code" => $c]);
+
+            $temp=json_decode($info['addr_code'],true);
+            if($temp) $addcode = $info['addr_code'];
+            else {
+                $temp = explode(',',$info['addr_code']);
+                $addcode = json_encode(["provice_code" => $temp[0], "city_code" => $temp[1], "area_code" => $temp[2]]);
+            }
+
+//            list($a, $b, $c) = explode(",", $info['addr_code']);
+//            $addcode = json_encode(["provice_code" => $a, "city_code" => $b, "area_code" => $c]);
         }
         $info["addr_cn"] = GetAddr($addcode);
         //  $info["addr_code"]=json_decode($addcode,true);
@@ -590,8 +598,31 @@ class After extends Base
                 if ($param['status'] == 10) $info['loop_total'] += 1;//只要走到节点10(业务公司修改,待供应商确认),就增加次数
 
                 //判断 退回供应商 or 退回业务公司
-                if ($info['status'] == 2 && $param['status'] == 11) $info['return_tag'] = 2;
-                else $info['return_tag'] = 1;
+                if ($info['status'] == 2 && $param['status'] == 11) {
+                    $info['return_tag'] = 2;
+
+                    //退入次品仓,维护
+                    $wsm = Db::name('warehouse_info')->where(['is_del' => 0, 'wsm_code' => $param['wsm_code']])->findOrEmpty();
+                    if (empty($wsm)) throw new Exception('返回仓库不存在');
+                    if ($wsm['wsm_type'] != 4) throw new Exception('不是次品仓');
+
+//                    if ($wsm['wsm_type'] == 4) {
+                    Db::name('order_returninfo')->insert([
+                        'returnCode' => $param['returnCode'],
+                        'return_wsm' => $param['wsm_code'],
+                        'contactor' => $wsm['contactor_name'],
+                        'mobile' => $wsm['mobile'],
+                        'addr' => $wsm['addr'],
+                        'addr_code' => $wsm['addrs_code'],
+                        'post_code' => '',
+                        'post_company' => '',
+                        'post_fee' => 0,
+                        'gys_remark' => '',
+                        'addtime' => $date,
+                    ]);
+//                    }
+
+                } else $info['return_tag'] = 1;
 
                 $var = $info['status'];
                 $info['status'] = $param['status'];

+ 44 - 7
app/admin/controller/AfterChild.php

@@ -15,7 +15,7 @@ class AfterChild extends Base
     public function getList()
     {
 
-        $param = $this->request->only(['page' => 1, 'size' => 10, 'returnCode' => '', 'status' => '', 'orderCode' => '', 'outCode' => '', 'order_type' => '', 'supplierNo' => '', 'is_authority' => 0], 'post', 'trim');
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'returnCode' => '', 'status' => '', 'orderCode' => '', 'outCode' => '', 'order_type' => '', 'supplierNo' => '', 'is_authority' => 0,'type'=>''], 'post', 'trim');
 
         $db = Db::name('order_return_child')
             ->alias('a')
@@ -30,6 +30,7 @@ class AfterChild extends Base
         if ($param['outCode'] != '') $db->whereLike('a.outCode', '%' . $param['outCode'] . '%');
         if ($param['order_type'] !== '') $db->where('d.order_type', $param['order_type']);
         if ($param['supplierNo'] != '') $db->whereLike('d.supplierNo', '%' . $param['supplierNo'] . '%');
+        if ($param['type'] !== '') $db->where('a.type', $param['type']);
 
         if ($param['is_authority'] == '0' && $param['returnCode'] == '' && $param['orderCode'] == '' && $param['outCode'] == '') return json_show('请选择筛选条件');
 
@@ -62,7 +63,7 @@ class AfterChild extends Base
             ->count('a.id');
 
         $list = $db
-            ->field('a.id,a.returnCode,a.orderCode,a.outCode,a.order_out_child_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,d.companyNo,d.companyName,d.customer_code,d.customer_name,d.order_type,d.apply_id,d.apply_name')
+            ->field('a.id,a.returnCode,a.orderCode,a.outCode,a.order_out_child_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,d.companyNo,d.companyName,d.customer_code,d.customer_name,d.order_type,d.apply_id,d.apply_name,a.type,a.can_sell_num,a.defective_num,a.loss_num,a.return_num_total')
             ->order(['a.addtime' => 'desc', 'a.id' => 'desc'])
             ->page($param['page'], $param['size'])
             ->select()
@@ -99,7 +100,7 @@ class AfterChild extends Base
 
         $val_child = Validate::rule([
             'outChildCode|发货工单号' => 'require',
-            'return_num|退货数量' => 'require|number|gt:0|max:999999999999',
+            'return_num|退货数量' => 'require|number|egt:0|max:999999999999',
             'return_wsm_code|退货仓库编码' => 'require'
         ]);
 
@@ -126,6 +127,7 @@ class AfterChild extends Base
                 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'] . '退货仓库不存在');
 
+                if ($value['return_num'] <= 0) continue;//数量为0的不再处理
                 $insert[] = [
                     'returnCode' => $param['returnCode'],
                     'orderCode' => $order_out['orderCode'],
@@ -146,6 +148,8 @@ class AfterChild extends Base
                     'remark' => '',
                     'addtime' => $date,
                     'updatetime' => $date,
+                    'type' => 1,
+                    'return_num_total' => 0
                 ];
 
             }
@@ -191,8 +195,9 @@ class AfterChild extends Base
         $info = Db::name('order_return_child')
             ->alias('a')
             ->leftJoin('order_out_child b', 'b.outChildCode=a.outChildCode')
+            ->leftJoin('warehouse_info c', 'c.wsm_code=a.return_wsm_code')
             ->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.return_num', 'a.id');
+            ->column('a.*,b.wsm_code,c.addr,c.addrs_code,c.mobile,c.contactor_name', 'a.id');
         if (empty($info)) return json_show(1004, '退货工单不存在');
 
         $val_child = Validate::rule([
@@ -207,6 +212,8 @@ class AfterChild extends Base
         try {
 
             $date = date('Y-m-d H:i:s');
+
+            $insert = [];
             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'] . '退货工单不存在');
@@ -221,7 +228,8 @@ class AfterChild extends Base
                         'loss_num' => $value['loss_num'],
                         'remark' => $value['remark'] ?? '',
                         'updatetime' => $date,
-                        'status' => 2
+                        'status' => 2,
+                        'return_num_total' => $value['can_sell_num']
                     ]);
 
                 //发货工单数量减少
@@ -229,8 +237,35 @@ class AfterChild extends Base
                     ->where(['is_del' => 0, 'outChildCode' => $info[$value['id']]['outChildCode']])
                     ->dec('num', $info[$value['id']]['return_num'])
                     ->update(['updatetime' => $date]);
+
+                //如果次品仓入库数量大于0,另生成退货工单,以类型区分
+                if ($value['defective_num'] > 0) {
+                    $temp = $info[$value['id']];
+                    unset($temp['wsm_code']);
+                    unset($temp['addr']);
+                    unset($temp['addrs_code']);
+                    unset($temp['mobile']);
+                    unset($temp['contactor_name']);
+
+                    $insert[] = array_merge($temp, [
+                        'id' => null,
+                        'addtime' => $date,
+                        'updatetime' => $date,
+                        'return_wsm_code' => Db::name('order_returninfo')->where('returnCode', $param['returnCode'])->value('return_wsm', ''),//取之前次品仓的编码
+                        'type' => 2,
+                        'return_num_total' => $value['defective_num'],
+                        'can_sell_num' => $value['can_sell_num'],
+                        'defective_num' => $value['defective_num'],
+                        'loss_num' => $value['loss_num'],
+                        'remark' => $value['remark'] ?? '',
+                        'status' => 2,
+                    ]);
+                }
+
             }
 
+            if ($insert) Db::name('order_return_child')->insertAll($insert);
+
             $total = array_sum(array_column($param['list'], 'can_sell_num'));
 
             if ($total > 0) {
@@ -249,14 +284,16 @@ class AfterChild extends Base
                             if (!empty($good)) {
                                 Db::name('good_basic')->insert(array_merge($good, [
                                     'id' => null,
+                                    'is_stock' => 1,
                                     'spuCode' => $spuCode,
                                     'addtime' => $date,
                                     'updatetime' => $date,
+                                    'status' => 0
                                 ]));
                             }
                         } else {
                             $good = Db::name('good_zixun')
-                                ->where([])
+                                ->where(['spuCode' => $order_return['good_code']])
                                 ->findOrEmpty();
                             if (!empty($good)) {
                                 Db::name('good_basic')->insert([
@@ -504,7 +541,7 @@ class AfterChild extends Base
                     //维护商品层面的库存数
                     Db::name('good')
                         ->where(['is_del' => 0, 'spuCode' => $order_return['good_code']])
-                        ->inc('usable_stock', array_sum(array_column($info, 'return_num')) - array_sum(array_column($param['list'], 'loss_num')))
+                        ->inc('usable_stock', array_sum(array_column($param['list'], 'can_sell_num')))
                         ->update(['updatetime' => $date]);
 
                 }

+ 68 - 48
app/admin/controller/Reorder.php

@@ -751,7 +751,7 @@ class Reorder extends Base
 
         //校验是否开通了供应商账号
         $supp_account = checkHasAccountBySupplierNos([$info['supplierNo']]);
-        $info['has_account']=(int)isset($supp_account[$info['supplierNo']]);
+        $info['has_account'] = (int)isset($supp_account[$info['supplierNo']]);
 
         return json_show(0, "获取成功", $info);
     }
@@ -863,16 +863,16 @@ class Reorder extends Base
         $orderinfo = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->findOrEmpty();
         if (empty($orderinfo)) return json_show(1004, "未找到订单数据");
 
-//        if ($status == 4) {
-//            if ($info['is_addr'] == 1) {
-//                $addr = Db::name("sale_returnaddr")
-//                    ->where(['returnCode' => $info['returnCode'], "is_del" => 0])
-//                    ->select()
-//                    ->toArray();
-//                if (empty($addr)) return json_show(1004, "未找到发货单地址数据");
-//
-//            }
-//        }
+        if ($status == 4) {
+            if ($info['is_addr'] == 1) {
+                $addr = Db::name("sale_returnaddr")
+                    ->where(['returnCode' => $info['returnCode'], "is_del" => 0])
+                    ->select()
+                    ->toArray();
+                if (empty($addr)) return json_show(1004, "未找到发货单地址数据");
+
+            }
+        }
 //        if($status==3){
 //            $is_th =isset($this->post['is_th'])&&$this->post['is_th']!=="" ? intval($this->post['is_th']):"";
 //            if($is_th===""){
@@ -892,7 +892,7 @@ class Reorder extends Base
 //            $info['is_th'] =$is_th ;
 //        }
 
-        if ( in_array($info['status'],[9,10]) && $param['status'] == 4) $info['is_th'] = 1;//除了8-11-12-4之外,其余9-4和10-4都属于供应商同意退货
+        if (in_array($info['status'], [9, 10]) && $param['status'] == 4) $info['is_th'] = 1;//除了8-11-12-4之外,其余9-4和10-4都属于供应商同意退货
 
         Db::startTrans();
         try {
@@ -917,40 +917,54 @@ class Reorder extends Base
                 $ste = ["order_code" => $code, "status" => $temp, "action_remark" => '', "action_type" => "status"];
                 ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $ste, "XSTHD", $status, $info);
                 if ($status == 4) {
-//                    if ($info['is_addr'] == 1) {
-//                        if (isset($addr) && !empty($addr)) {
-//                            foreach ($addr as $value) {
-//                                $addrinfo = Db::name("order_addr")
-//                                    ->where(['id' => $value['addrid'], "is_del" => 0])
-//                                    ->findOrEmpty();
-//                                if (empty($addrinfo)) throw new Exception("地址数据未找到");
-//
-//                                if ($addrinfo['receipt_quantity'] < $value['return_num']) throw new Exception("地址发货数量不足");
-//
-//                                $addrinfo['receipt_quantity'] -= $value['return_num'];
-//                                $addrinfo['is_del'] = $addrinfo['receipt_quantity'] <= 0 ? 1 : 0;
-//                                $addrinfo['updatetime'] = $date;
-//                                $addrup = Db::name("order_addr")->save($addrinfo);
-//                                if ($addrup == false) throw new Exception('地址发货数量更新失败');
-//
-//                                if ($value['outCode'] != "") {
-//                                    $out = Db::name("order_out")->where(["outCode" => $value['outCode']])->findOrEmpty();
-//                                    if (empty($out)) throw new Exception('地址发货单数据未找到');
-//
-//                                    if ($out['status'] >= 2) throw new Exception('地址发货单已发货');
-//
-//                                    if ($out['send_num'] < $value['return_num']) throw new Exception('地址发货单发货数量不足');
-//
-//                                    $out['send_num'] -= $value['return_num'];
-//                                    $out['is_del'] = $out['send_num'] <= 0 ? 1 : 0;
-//                                    $out['updatetime'] = $date;
-//                                    $outup = Db::name("order_out")->save($out);
-//                                    if ($outup == false) throw new Exception('地址发货单更新失败');
-//
-//                                }
-//                            }
-//                        }
-//                    }
+                    if ($info['is_addr'] == 1) {
+                        if (isset($addr) && !empty($addr)) {
+                            foreach ($addr as $value) {
+                                $addrinfo = Db::name("order_addr")
+                                    ->where(['id' => $value['addrid'], "is_del" => 0])
+                                    ->findOrEmpty();
+                                if (empty($addrinfo)) throw new Exception("地址数据未找到");
+
+                                if ($addrinfo['receipt_quantity'] < $value['return_num']) throw new Exception("地址发货数量不足");
+
+                                $addrinfo['receipt_quantity'] -= $value['return_num'];
+                                $addrinfo['is_del'] = $addrinfo['receipt_quantity'] <= 0 ? 1 : 0;
+                                $addrinfo['updatetime'] = $date;
+                                $addrup = Db::name("order_addr")->save($addrinfo);
+                                if ($addrup == false) throw new Exception('地址发货数量更新失败');
+
+                                if ($value['outCode'] != "") {
+                                    $out = Db::name("order_out")->where(["outCode" => $value['outCode']])->findOrEmpty();
+                                    if (empty($out)) throw new Exception('地址发货单数据未找到');
+
+                                    if ($out['status'] >= 2) throw new Exception('地址发货单已发货');
+
+                                    if ($out['send_num'] < $value['return_num']) throw new Exception('地址发货单发货数量不足');
+
+                                    $out['send_num'] -= $value['return_num'];
+                                    $out['is_del'] = $out['send_num'] <= 0 ? 1 : 0;
+                                    $out['updatetime'] = $date;
+                                    $outup = Db::name("order_out")->save($out);
+                                    if ($outup == false) throw new Exception('地址发货单更新失败');
+
+                                    $tmp = Db::name('order_out_child')
+                                        ->where(['is_del' => 0, 'outCode' => $value['outCode']])
+                                        ->findOrEmpty();
+
+                                    $tmp['num'] -= $value['return_num'];
+                                    if ($tmp['num'] <= 0) {
+                                        $tmp['status'] = 4;
+                                        $tmp['is_del'] = 1;
+                                    }
+
+                                    //维护发货工单的数量
+                                    Db::name('order_out_child')
+                                        ->where(['id' => $tmp['id']])
+                                        ->update($tmp);
+                                }
+                            }
+                        }
+                    }
 
                     if ($orderinfo['wsend_num'] < $info['num']) throw new Exception('销售单未发货数量不足退货');
 
@@ -1886,18 +1900,24 @@ class Reorder extends Base
             ->field('a.id,a.outCode,a.send_num,a.return_num,a.is_sale_return_child,b.contactor,b.mobile,b.addr_code,b.addr,"" addr_code_cn')
             ->leftJoin('order_addr b', 'b.id=a.addrid and b.is_del=0')
             ->where($where)
-            ->order(['a.is_sale_return_child'=>'asc','a.addtime' => 'desc', 'a.id' => 'desc'])
+            ->order(['a.is_sale_return_child' => 'asc', 'a.addtime' => 'desc', 'a.id' => 'desc'])
             ->page($param['page'], $param['size'])
             ->select()
             ->toArray();
 
+        $is_sale_return_child_count = Db::name('sale_returnaddr')
+            ->alias('a')
+            ->where($where)
+            ->where('is_sale_return_child', 1)
+            ->count('a.id');
+
         foreach ($list as &$value) {
             if ($value['addr_code'] != '') {
                 $value['addr_code_cn'] = GetAddr($value['addr_code']);
             }
         }
 
-        return json_show(0, '获取列表成功', ['count' => $count, 'list' => $list]);
+        return json_show(0, '获取列表成功', ['count' => $count, 'list' => $list, 'is_sale_return_child_count' => $is_sale_return_child_count]);
 
     }
 

+ 197 - 8
app/admin/controller/ReorderChild.php

@@ -88,7 +88,7 @@ class ReorderChild extends Base
                     'returnCode' => $param['returnCode'],
                     'outCode' => $param['outCode'],
                     'outChildCode' => $value['outChildCode'] ?? '',
-                    'order_out_child_status' =>isset($value['outChildCode'])?($orderOutChild[$value['outChildCode']]['status'] ?? 0) :0,
+                    'order_out_child_status' => isset($value['outChildCode']) ? ($orderOutChild[$value['outChildCode']]['status'] ?? 0) : 0,
                     'saleReturnChildCode' => substr(makeNo('KCC'), 0, -2) . str_pad($i++, 2, '0', STR_PAD_LEFT),
 //                    'type' => $param['type'],
                     'companyNo' => $saleReturn['companyNo'],
@@ -101,8 +101,8 @@ class ReorderChild extends Base
                     'addtime' => $date,
                     'updatetime' => $date,
                     'record' => '',
-                    'send_wsm_code' =>  isset($value['outChildCode'])?($orderOutChild[$value['outChildCode']]['wsm_code'] ?? ''):"",
-                    'send_num' =>  isset($value['outChildCode'])?($orderOutChild[$value['outChildCode']]['num'] ?? 0):"",
+                    'send_wsm_code' => isset($value['outChildCode']) ? ($orderOutChild[$value['outChildCode']]['wsm_code'] ?? '') : "",
+                    'send_num' => isset($value['outChildCode']) ? ($orderOutChild[$value['outChildCode']]['num'] ?? 0) : "",
                     'return_num' => $value['return_num'],
                     'return_wsm_code' => $value['return_wsm_code'],
                     'good_receive_type' => 0,
@@ -207,11 +207,11 @@ class ReorderChild extends Base
             'remark|备注' => 'max:255'
         ]);
 
-        if ($val->check($param)==false) return json_show(1004, $val->getError());
+        if ($val->check($param) == false) return json_show(1004, $val->getError());
 
         $info = Db::name('sale_return_child')
             ->alias('a')
-            ->field('a.id,a.num,a.status,a.returnCode,a.outChildCode,a.return_num,a.return_wsm_code,a.orderCode,a.outCode,a.saleReturnChildCode,a.apply_id,b.good_code spuCode,c.status order_out_status,b.id saleid,d.num thnum,d.id sr_id,d.apply_id sr_apply_id')
+            ->field('a.id,a.num,a.status,a.returnCode,a.outChildCode,a.return_num,a.return_wsm_code,a.orderCode,a.outCode,a.saleReturnChildCode,a.apply_id,b.good_code spuCode,c.status order_out_status,b.id saleid,d.num thnum,d.id sr_id,d.apply_id sr_apply_id,b.is_stock,b.order_type')
             ->leftJoin('sale b', 'b.orderCode=a.orderCode')
             ->leftJoin('order_out_child c', 'c.outChildCode=a.outChildCode AND c.is_del=0')
             ->leftJoin('sale_return d', 'd.returnCode=a.returnCode')
@@ -341,13 +341,202 @@ class ReorderChild extends Base
                         "before_status" => $old_status
                     ]);
                 }
+
+
+                //非库存品转存为库存品
+                if ($info['is_stock'] != 1) {
+                    //根据转化表判断该非库存品是否转化为库存品
+                    $spuCode = Db::name('good_change_stock')
+                        ->where(['old_spuCode' => $info['spuCode'], 'old_order_type' => $info['order_type']])
+                        ->value('spuCode', '');
+                    if ($spuCode == '') {
+                        //将非库存品转化为库存品
+                        $spuCode = makeNo('SKU');
+                        if ($info['order_type'] == 2) {
+                            $good = Db::name('good_basic')
+                                ->where('spuCode', $info['spuCode'])
+                                ->findOrEmpty();
+                            if (!empty($good)) {
+                                Db::name('good_basic')->insert(array_merge($good, [
+                                    'id' => null,
+                                    'spuCode' => $spuCode,
+                                    'addtime' => $date,
+                                    'updatetime' => $date,
+                                    'status'=>0,
+                                    'is_stock' => 1,
+                                ]));
+                            }
+                        } else {
+                            $good = Db::name('good_zixun')
+                                ->where(['spuCode' => $info['spuCode']])
+                                ->findOrEmpty();
+                            if (!empty($good)) {
+                                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
+                                ]);
+                            }
+                        }
+
+                        if (!empty($good)) {
+                            //关联表增数据
+                            Db::name('good_change_stock')
+                                ->insert([
+                                    'old_spuCode' => $info['spuCode'],
+                                    'old_order_type' => $info['order_type'],
+                                    'spuCode' => $spuCode,
+                                    'addtime' => $date,
+                                    'updatetime' => $date,
+                                ]);
+
+                        } else throw new Exception('未找到对应的商品数据');
+
+                    }
+
+                    //新增bn记录,维护旧有bn记录
+                    $child_bns = Db::name('child_bn')
+                        ->field('id,num,origin_price')
+                        ->where(['orderCode' => $info['orderCode'], 'outCode' => $info['outCode']])
+                        ->order(['num' => 'desc', 'id' => 'asc'])
+                        ->cursor();
+
+                    $total = $info['return_num'];
+                    $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;
+                    }
+
+                    if (($info['return_num'] - $info['loss_num']) > 0) {
+                        $stockid = Db::name('good_stock')
+                            ->insertGetId([
+                                'project_code' => '',
+                                'spuCode' => $spuCode,
+                                'wsm_code' => $info['return_wsm_code'],
+                                'wait_in_stock' => 0,
+                                'wait_out_stock' => 0,
+                                'usable_stock' => $info['return_num'] - $info['loss_num'],
+                                'intra_stock' => 0,
+                                'total_stock' => $info['return_num'] - $info['loss_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' => $info['return_num'] - $info['loss_num'],
+                                'used_num' => 0,
+                                'balance_num' => $info['return_num'] - $info['loss_num'],
+                                'origin_price' => $origin_price,
+                                'addtime' => $date,
+                                'updatetime' => $date,
+                            ]);
+                    }
+                }
             }
 
             //发货工单数量减少
-            Db::name('order_out_child')
+            $tmp = Db::name('order_out_child')
                 ->where(['is_del' => 0, 'outChildCode' => $info['outChildCode']])
-                ->dec('num', $info['return_num'])
-                ->update(['updatetime' => $date]);
+                ->field('id,num')
+                ->findOrEmpty();
+            $tmp['num'] -= $info['return_num'];
+            $tmp['updatetime'] = $date;
+            if ($tmp['num'] <= 0) $tmp['is_del'] = 1;
+
+            Db::name('order_out_child')
+                ->where(['is_del' => 0, 'id' => $tmp['id']])
+                ->update($tmp);
+
+            //维护发货单
+            $temp = Db::name('order_out')
+                ->field('id,send_num')
+                ->where(['is_del' => 0, 'outCode' => $info['outCode']])
+                ->findOrEmpty();
+
+            $temp['send_num'] -= $info['return_num'];
+            $temp['updatetime'] = $date;
+            if ($temp['send_num'] <= 0) $temp['is_del'] = 1;
+
+            Db::name('order_out')
+                ->where('id', $temp['id'])
+                ->update($temp);
 
             //维护bn
             if ($info['order_out_status'] == 1) {