Selaa lähdekoodia

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

wufeng 2 vuotta sitten
vanhempi
commit
571919f19b
3 muutettua tiedostoa jossa 176 lisäystä ja 158 poistoa
  1. 169 152
      app/admin/controller/AfterChild.php
  2. 6 6
      app/admin/controller/Purchin.php
  3. 1 0
      app/admin/route/app.php

+ 169 - 152
app/admin/controller/AfterChild.php

@@ -2,7 +2,6 @@
 
 namespace app\admin\controller;
 
-use app\admin\model\GoodStockInfo;
 use think\Exception;
 use think\facade\Db;
 use think\facade\Validate;
@@ -195,129 +194,139 @@ class AfterChild extends Base
                     ]);
             }
 
-            $total = array_sum(array_column($param['list'],'can_sell_num'));
+            $total = array_sum(array_column($param['list'], 'can_sell_num'));
 
-            if($total>0){
+            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=='') {
+                        ->where(['old_spuCode' => $order_return['good_code'], 'old_order_type' => $order_return['order_type']])
+                        ->value('spuCode', '');
+                    if ($spuCode == '') {
                         //将非库存品转化为库存品
+                        $spuCode = makeNo('SKU');
                         if ($order_return['order_type'] == 2) {
                             $good = Db::name('good_basic')
-                                ->where('spuCode',$order_return['good_code'])
+                                ->where('spuCode', $order_return['good_code'])
                                 ->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([])
                                 ->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)) {
-                            $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,
+                                    'old_spuCode' => $order_return['good_code'],
+                                    'old_order_type' => $order_return['order_type'],
+                                    'spuCode' => $spuCode,
                                     'addtime' => $date,
                                     'updatetime' => $date,
                                 ]);
 
-                        }throw new Exception('未找到对应的商品数据');
+                        }
+                        throw new Exception('未找到对应的商品数据');
 
                     }
 
                     //新增bn记录,维护旧有bn记录
-                    $child_bns=Db::name('child_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'])
+                        ->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'];
+                    $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;
+                            ->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) {
@@ -341,74 +350,71 @@ class AfterChild extends Base
 
                             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,
+                                    '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{
+                } 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');
+                    $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){
+                    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']]])
+                        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)){
+                            if (empty($good_stock_info)) {
                                 //从child_bn查询bn号并维护,新建到good_stock_info中
-                                $child_bns=Db::name('child_bn')
+                                $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'])
+                                    ->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){
+                                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]);
+                                        ->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,
+                                            '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;
+                                    $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
+                                    if ($total == 0) break;
                                 }
-                            }else{
+                            } 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]);
+                                    ->where(['id' => $good_stock_info['id']])
+                                    ->inc('balance_num', $value['can_sell_num'])//可用数量增加
+                                    ->dec('used_num', $value['can_sell_num'])//已用数量减少
+                                    ->update(['updatetime' => $date]);
                             }
-                        }
-                        else{
+                        } else {
                             //新建good_stock和good_stock_info
-
                             $stockid = Db::name('good_stock')
                                 ->insertGetId([
                                     'project_code' => '',
@@ -426,33 +432,44 @@ class AfterChild extends Base
                                     '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,
-                                ]);
-
-
+                            //从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' => $stockid,
+                                        '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;
+                            }
 
                         }
-
-
-
                     }
 
                 }
             }
 
             Db::commit();
-            return json_show(0,'库管收货成功');
+            return json_show(0, '库管收货成功');
         } catch (Exception $exception) {
             Db::rollback();
             return json_show(1004, $exception->getMessage());

+ 6 - 6
app/admin/controller/Purchin.php

@@ -636,7 +636,7 @@ class Purchin extends Base
 
         $cgdinfo = Db::name("purchease_order")
             ->whereIn('cgdNo', $param['cgdNo'])
-            ->where(['is_del' => 0, 'supplierNo' => $this->request->user['supplierNo']])
+            ->where(['is_del' => 0])
             ->where('status', 'in', [1, 2])//1待入库,2部分入库
             ->column('id,wsm_code,good_num,good_price,spuCode,order_type,send_status,status,supplierNo', 'cgdNo');
 
@@ -649,8 +649,8 @@ class Purchin extends Base
             ->whereIn('wsm_code', $all_wsm_code)
             ->column('wsm_name', 'wsm_code');
 
-        $uid = $this->request->user['uid'];
-        $nickname = $this->request->user['nickname'];
+        $uid = $this->uid;
+        $nickname = $this->uname;
 
         Db::startTrans();
         try {
@@ -701,8 +701,8 @@ class Purchin extends Base
                     "post_code" => '',
                     "post_fee" => 0,//运费固定值:0
                     "sendtime" => $date,
-                    "apply_id" => $this->request->user['uid'],
-                    "apply_name" => $this->request->user['nickname'],
+                    "apply_id" => $uid,
+                    "apply_name" => $nickname,
                     "wait_num" => 0,
                     "wsm_num" => 0,
                     "sendtype" => 2,//发货方式,固定值,供应商包邮2
@@ -714,7 +714,7 @@ class Purchin extends Base
                 if ($win) {
                     $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']];
+                    $process = ["order_code" => $wsm_in_code, "order_id" => $win, "order_status" => $status, "order_type" => 'RKD', "before_status" => $status, 'holder_id' => $uid];
                     ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], $process);
                     $order = ["order_code" => $cgdNo, "status" => $cgdinfo[$cgdNo]['status'], "action_remark" => '', "action_type" => "edit"];
 

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

@@ -303,6 +303,7 @@ 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('delivery_order_return_child', 'admin/AfterChild/deliveryOrderReturnChild');//库管收货
 //Route::rule('aftersetwsm','admin/After/setWsm');
 
 Route::rule('processolist', 'admin/Proorder/list');//我的已办