Browse Source

售前退货,非库存品转库存品

wufeng 2 years ago
parent
commit
3ccffe6e53
2 changed files with 168 additions and 2 deletions
  1. 1 1
      app/admin/controller/AfterChild.php
  2. 167 1
      app/admin/controller/ReorderChild.php

+ 1 - 1
app/admin/controller/AfterChild.php

@@ -256,7 +256,7 @@ class AfterChild extends Base
                             }
                         } else {
                             $good = Db::name('good_zixun')
-                                ->where([])
+                                ->where(['spuCode'=>$order_return['good_code']])
                                 ->findOrEmpty();
                             if (!empty($good)) {
                                 Db::name('good_basic')->insert([

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

@@ -211,7 +211,7 @@ class ReorderChild extends Base
 
         $info = Db::name('sale_return_child')
             ->alias('a')
-            ->field('a.id,a.num,a.status,a.returnCode,a.outChildCode,a.return_num,a.return_wsm_code,a.orderCode,a.outCode,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,6 +341,172 @@ 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,
+                                ]));
+                            }
+                        } 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,
+                            ]);
+                    }
+                }
             }
 
             //发货工单数量减少