Browse Source

Merge branch 'zzd'

# Conflicts:
#	app/Services/OrderPackageCommoditiesService.php
LD 5 years ago
parent
commit
d3164f3015

+ 3 - 0
app/Http/Controllers/RejectedBillItemController.php

@@ -72,6 +72,9 @@ class RejectedBillItemController extends Controller
             $rejectedBillItem=new RejectedBillItem($request->all());
             $rejectedBillItem->save();
         }
+
+        if (!$rejectedBillItem->rejectedBill || !$rejectedBillItem->rejectedBill->owner)return ['success'=>'false','failure_info'=>'退货单或货主不存在'];
+
         /** @var CommodityService $commodityService */
         $commodityService = app('commodityService');
         $commodity = $commodityService->ownerBarcodeSeekCommodityFirst(['name'=>$rejectedBillItem->rejectedBill->owner->name],$rejectedBillItem->barcode_goods);

+ 102 - 3
app/Http/Controllers/TestController.php

@@ -7,6 +7,7 @@ use App\Authority;
 use App\Batch;
 use App\City;
 use App\Commodity;
+use App\CommodityBarcode;
 use App\Events\CancelOrder;
 use App\Log;
 use App\Logistic;
@@ -412,9 +413,107 @@ class TestController extends Controller
         }
     }
 
-    public function test2(){
-        $commodity = app('commodityService')->ownerBarcodeSeekCommodityFirst(['id'=>8],"6971393121341");
-        dd($commodity);
+    private function cleanBarcode(){
+        $logCommodityBarcodes = CommodityBarcode::query()->where('code',"")->get();
+        if (count($logCommodityBarcodes) > 0)LogService::log(__METHOD__,"纠正商品-删除空条码",json_encode($logCommodityBarcodes,JSON_UNESCAPED_UNICODE));
+
+        CommodityBarcode::query()->where('code',"")->delete();
+        $barcodes = DB::select(DB::raw('select * from commodity_barcodes c
+where (c.code,c.commodity_id) in (select code,commodity_id from commodity_barcodes group by code,commodity_id having count(*) > 1) order by commodity_id'));
+        $barcodeMap = [];
+        $barcodeDelete = [];
+        foreach ($barcodes as $barcode){
+            if (isset($barcodeMap[$barcode->code.'_'.$barcode->commodity_id]))$barcodeDelete[] = $barcode->id;
+            else $barcodeMap[$barcode->code.'_'.$barcode->commodity_id] = $barcode->id;
+        }
+
+        $logCommodityBarcodes = CommodityBarcode::query()->whereIn('id',$barcodeDelete)->get();
+        if (count($logCommodityBarcodes) > 0)LogService::log(__METHOD__,"纠正商品-删除重复条码",json_encode($logCommodityBarcodes,JSON_UNESCAPED_UNICODE));
+
+        CommodityBarcode::destroy($barcodeDelete);
+    }
+    public function correctCommodity(){
+        //清理冗余条码
+        $this->cleanBarcode();
+
+        //获取重复条码
+        $commodities = DB::select(DB::raw('select commodities.name,commodities.sku,commodities.owner_id,commodity_barcodes.id as barcode_id,commodity_barcodes.code as barcode_code,commodity_barcodes.commodity_id from commodities LEFT JOIN commodity_barcodes on commodities.id = commodity_barcodes.commodity_id
+where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owner_id,commodity_barcodes.code from commodities LEFT JOIN commodity_barcodes on commodities.id = commodity_barcodes.commodity_id group by commodities.owner_id,commodity_barcodes.code having count(*) > 1) order by commodities.owner_id,commodity_barcodes.code'));
+
+        //对比map池
+        $commodityMap = [];
+        //需要删除项
+        $commodityDelete = [];
+        foreach ($commodities as $index => $commodity){
+            //货主+条码 为唯一key值 设想正常数据下同货主不应该有同条码
+            $key = $commodity->owner_id.'_'.$commodity->barcode_code;
+            //使用map池对比为重复数据
+            if(isset($commodityMap[$key])){
+                //获取下标指针指向的源数据
+                $c = $commodities[$commodityMap[$key]];
+                //源数据不符合规范,当前数据替换掉它
+                if (($c->sku == null || $c->sku == "") && ($commodity->sku != null && $commodity->sku != "")){
+                    $commodityDelete[] = $commodityMap[$key];
+                    $commodityMap[$key] = $index;
+                }else{
+                    //当前数据比源数据更符合预期,替换掉
+                    if (($c->sku == $commodity->sku) && (strlen($c->name) < strlen($commodity->name))){
+                        $commodityDelete[] = $commodityMap[$key];
+                        $commodityMap[$key] = $index;
+                    }else{
+                        //扔进处理池
+                        $commodityDelete[] = $index;
+                    }
+                }
+            //第一次出现的新数据,val为下标,当作指针指向源数据
+            }else $commodityMap[$key] = $index;
+        }
+        $createBarcodes = []; //批量生成条码
+        $deleteCommodities = []; //批量删除商品及商品条码
+
+        $updateCommodities = [];
+        foreach ($commodityDelete as $index){
+            //获取到被处理数据 与 目标数据
+            $del = $commodities[$index];
+            $target = $commodities[$commodityMap[$del->owner_id.'_'.$del->barcode_code]];
+
+            //记录ID删除商品与条码
+            $deleteCommodities[] = $del->commodity_id;
+
+            //有效条码合并
+            $barcodes = DB::select(DB::raw("select * from 
+            (select * from commodity_barcodes where commodity_id = ".$del->commodity_id.")a 
+            where (select count(1) as num from commodity_barcodes b 
+            where commodity_id = ".$target->commodity_id." and b.code = a.code) = 0"));
+            if (count($barcodes) > 0){
+                foreach ($barcodes as $barcode){
+                    $createBarcodes[] = ['code'=>$barcode->code, 'commodity_id'=>$target->commodity_id];
+                }
+            }
+            $updateCommodities[$del->commodity_id] = $target->commodity_id;
+        }
+        if (count($updateCommodities) > 0){
+            app('inventoryAccountMissionService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新库存盘点任务
+            app('inventoryCompareService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新库存对比
+            app('inventoryDailyLogService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新库存每日记录
+            app('processesContentService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新二次加工内容单
+            app('storeCheckingReceiveItemService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新入库盘收一体
+            app('orderPackageCommoditiesService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新订单商品
+        }
+
+        if (count($createBarcodes) > 0)LogService::log(__METHOD__,"纠正商品-录入合并条码",json_encode($createBarcodes,JSON_UNESCAPED_UNICODE));
+
+        CommodityBarcode::query()->insert($createBarcodes);
+
+        $logCommodityBarcodes = CommodityBarcode::query()->whereIn('commodity_id',$deleteCommodities)->get();
+        if (count($logCommodityBarcodes) > 0)LogService::log(__METHOD__,"纠正商品-删除无用商品条码",json_encode($logCommodityBarcodes,JSON_UNESCAPED_UNICODE));
+
+        CommodityBarcode::query()->whereIn('commodity_id',$deleteCommodities)->delete();
+
+        $logCommodities = Commodity::query()->whereIn('id',$deleteCommodities)->get();
+        if (count($logCommodities) > 0)LogService::log(__METHOD__,"纠正商品-删除无用商品",json_encode($logCommodities,JSON_UNESCAPED_UNICODE));
+
+        Commodity::destroy($deleteCommodities);
     }
 
     /*1*/

+ 14 - 11
app/Http/Controllers/api/thirdPart/flux/ProcessController.php

@@ -176,19 +176,22 @@ class ProcessController extends Controller
             array_push($commoditiesData,["owner_id"=>$owners[$oracleBasSkus[$i]->customerid],"name"=>$oracleBasSkus[$i]->descr_c,"sku"=>$oracleBasSkus[$i]->sku,"created_at"=>Carbon::now()]);
             array_push($commoditiesTem['sku'],$oracleBasSkus[$i]->sku);
             array_push($commoditiesTem['owner_id'],$owners[$oracleBasSkus[$i]->customerid]);
-            $commodityBarCodeData[$oracleBasSkus[$i]->sku."_".$owners[$oracleBasSkus[$i]->customerid]]=["code"=>$oracleBasSkus[$i]->alternate_sku1,"commodity_id"=>'','created_at'=>Carbon::now()];
+            if ($oracleBasSkus[$i]->alternate_sku1)$commodityBarCodeData[$oracleBasSkus[$i]->sku."_".$owners[$oracleBasSkus[$i]->customerid]]=["code"=>$oracleBasSkus[$i]->alternate_sku1,"commodity_id"=>'','created_at'=>Carbon::now()];
         }
-        DB::table('commodities')->insert($commoditiesData);
-        $this->log(__METHOD__, 'FLUX二次加工单接口录入商品__' . __FUNCTION__, json_encode($commoditiesData), Auth::user()['id']);
-        $commodities=Commodity::query()->whereIn('sku',$commoditiesTem['sku'])->whereIn('owner_id',$commoditiesTem['owner_id'])->get();
-        foreach ($commodities as $commodity){
-            $commodityBarCodeData[$commodity->sku."_".$commodity->owner_id]['commodity_id']=$commodity->id;
-        }
-        foreach ($commodityBarCodeData as $key=>$value){
-            array_push($commodityBarCodeTem,$value);
+        //TODO 保留:根据条码与货主批量二次查找商品
+        if (count($commoditiesData) > 0){
+            app('commodityService')->insert($commoditiesData);
+            $this->log(__METHOD__, 'FLUX二次加工单接口录入商品__' . __FUNCTION__, json_encode($commoditiesData), Auth::user()['id']);
+            $commodities=Commodity::query()->whereIn('sku',$commoditiesTem['sku'])->whereIn('owner_id',$commoditiesTem['owner_id'])->get();
+            foreach ($commodities as $commodity){
+                if (isset($commodityBarCodeData[$commodity->sku."_".$commodity->owner_id]))
+                    $commodityBarCodeData[$commodity->sku."_".$commodity->owner_id]['commodity_id']=$commodity->id;
+            }
+            if (count($commodityBarCodeTem) > 0){
+                app('commodityBarcodeService')->insert(array_values($commodityBarCodeData));
+                $this->log(__METHOD__, 'FLUX二次加工单接口录入商品条码__' . __FUNCTION__, json_encode($commodityBarCodeTem), Auth::user()['id']);
+            }
         }
-        DB::table('commodity_barcodes')->insert($commodityBarCodeTem);
-        $this->log(__METHOD__, 'FLUX二次加工单接口录入商品条码__' . __FUNCTION__, json_encode($commodityBarCodeTem), Auth::user()['id']);
     }
 
 

+ 1 - 1
app/Imports/CommodityImport.php

@@ -35,7 +35,7 @@ class CommodityImport implements ToCollection, WithHeadingRow
             $owner_id=Owner::where('name',$owner)->value('id');
             $commodity=Commodity::whereHas('barcodes', function (Builder $query)use($barcode){
                 $query->where('code',$barcode);
-            })->first();
+            })->where('owner_id',$owner_id)->first();
             if($commodity){
                 if($this->isOverride){
                     $name?$commodity['name']= $name:false;

+ 0 - 2
app/Imports/RejectedImport.php

@@ -2,7 +2,6 @@
 
 namespace App\Imports;
 
-use App\Commodity;
 use App\Http\Controllers\api\jianshang\RejectedController;
 use App\Http\Controllers\Controller;
 use App\Logistic;
@@ -11,7 +10,6 @@ use App\Rejected;
 use App\RejectedBill;
 use App\RejectedBillItem;
 use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Session;
 use Maatwebsite\Excel\Concerns\ToCollection;
 use Maatwebsite\Excel\Concerns\WithHeadingRow;

+ 6 - 1
app/Providers/AppServiceProvider.php

@@ -3,12 +3,14 @@
 namespace App\Providers;
 
 use App\Http\Controllers\Controller;
-use App\OrderIssueProcessLog;
+use App\InventoryAccountMission;
 use App\Services\CommodityService;
 use App\Services\common\BatchUpdateService;
 use App\Services\CommodityBarcodeService;
 use App\Services\common\DataHandlerService;
 use App\Services\DepositoryService;
+use App\Services\InventoryAccountMissionService;
+use App\Services\InventoryAccountService;
 use App\Services\InventoryCompareService;
 use App\Services\OracleBasSkuService;
 use App\Services\OracleDocAsnDetailService;
@@ -27,6 +29,7 @@ use App\Services\OrderPackageCommoditiesService;
 use App\Services\OrderTrackingService;
 use App\Services\OwnerService;
 use App\Services\PackageStatisticsService;
+use App\Services\ProcessesContentService;
 use App\Services\ProcessMethodService;
 use App\Services\ProcessService;
 use App\Services\ProcessStatisticService;
@@ -114,6 +117,8 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('commodityBarcodeService',CommodityBarcodeService::class);
         app()->singleton('oracleBasSkuService',OracleBasSkuService::class);
         app()->singleton('oracleDocAsnDetailService',OracleDocAsnDetailService::class);
+        app()->singleton('inventoryAccountMissionService',InventoryAccountMissionService::class);
+        app()->singleton('processesContentService',ProcessesContentService::class);
 
         $this->loadingOrderModuleService();
         $this->loadingBasedModuleService();

+ 0 - 2
app/RejectedBill.php

@@ -4,11 +4,9 @@ namespace App;
 
 use App\Http\Controllers\Controller;
 use App\Http\Controllers\LogisticNumberFeatureController;
-use App\Services\OrderPackageCommoditiesService;
 use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\SoftDeletes;
-use Illuminate\Support\Arr;
 use Illuminate\Support\Facades\Auth;
 use Overtrue\LaravelPinyin\Facades\Pinyin;
 

+ 2 - 2
app/RejectedBillItem.php

@@ -39,10 +39,10 @@ class RejectedBillItem extends Model
         if(!$this['name_goods'])return;
         $barcode=$this['barcode_goods'];
         $name=$this['name_goods'];
+        $owner=Owner::where('name',$this->rejectedBill->owner->name)->first();
         $commodity=Commodity::whereHas('barcodes', function (Builder $query)use($barcode){
             $query->where('code',$barcode);
-        })->first();
-        $owner=Owner::where('name',$this->rejectedBill->owner->name)->first();
+        })->where('owner_id',$owner ? $owner['id'] : null)->first();
         if($commodity){
             if($commodity['name']!=$name){
                 $commodity['name']=$name;

+ 14 - 0
app/Services/InventoryAccountMissionService.php

@@ -0,0 +1,14 @@
+<?php 
+
+namespace App\Services; 
+
+use App\Services\common\BatchUpdateService;
+
+Class InventoryAccountMissionService
+{
+
+    public function batchUpdateItself($column, array $params)
+    {
+        return app(BatchUpdateService::class)->batchUpdateItself('inventory_account_missions', $column, $params);
+    }
+}

+ 5 - 0
app/Services/InventoryCompareService.php

@@ -8,6 +8,7 @@ use App\Http\Controllers\Controller;
 use App\InventoryCompare;
 use App\OracleInvLotLocId;
 use App\Owner;
+use App\Services\common\BatchUpdateService;
 use App\Services\common\QueryService;
 use Carbon\Carbon;
 use Illuminate\Support\Facades\Cache;
@@ -250,4 +251,8 @@ class InventoryCompareService
 //        return $inventoryCompare;
 //    }
 //
+    public function batchUpdateItself($column, array $params)
+    {
+        return app(BatchUpdateService::class)->batchUpdateItself('inventory_compares', $column, $params);
+    }
 }

+ 6 - 0
app/Services/InventoryDailyLogService.php

@@ -4,6 +4,7 @@ namespace App\Services;
 
 use App\InventoryDailyLog;
 use App\InventoryDailyLoggingOwner;
+use App\Services\common\BatchUpdateService;
 use App\Services\common\QueryService;
 
 Class InventoryDailyLogService
@@ -55,4 +56,9 @@ Class InventoryDailyLogService
         return InventoryDailyLoggingOwner::query()->firstOrCreate($param);
     }
 
+    public function batchUpdateItself($column, array $params)
+    {
+        return app(BatchUpdateService::class)->batchUpdateItself('inventory_daily_logs', $column, $params);
+    }
+
 }

+ 5 - 0
app/Services/OrderPackageCommoditiesService.php

@@ -601,4 +601,9 @@ class OrderPackageCommoditiesService
             })->get();
     }
 
+
+    public function batchUpdateItself($column, array $params)
+    {
+        return app(BatchUpdateService::class)->batchUpdateItself('order_package_commodities', $column, $params);
+    }
 }

+ 14 - 0
app/Services/ProcessesContentService.php

@@ -0,0 +1,14 @@
+<?php 
+
+namespace App\Services; 
+
+use App\Services\common\BatchUpdateService;
+
+Class ProcessesContentService
+{
+
+    public function batchUpdateItself($column, array $params)
+    {
+        return app(BatchUpdateService::class)->batchUpdateItself('processes_contents', $column, $params);
+    }
+}

+ 4 - 0
app/Services/StoreCheckingReceiveItemService.php

@@ -39,5 +39,9 @@ Class StoreCheckingReceiveItemService
     public function destroy($id){
         return StoreCheckingReceiveItem::destroy($id);
     }
+    public function batchUpdateItself($column, array $params)
+    {
+        return app(BatchUpdateService::class)->batchUpdateItself('store_checking_receive_items', $column, $params);
+    }
 
 }

+ 1 - 0
app/Services/WaybillService.php

@@ -35,6 +35,7 @@ Class WaybillService
             'wms_bill_number' => ['like' => ''],
             'origination' => ['like' => ''],
             'destination' => ['like' => ''],
+            'source_bill' => ['like' => ''],
             'created_at_start' => ['alias' => 'created_at' , 'startDate' => ' 00:00:00'],
             'created_at_end' => ['alias' => 'created_at' , 'endDate' => ' 23:59:59'],
             'uriType' => ['alias' => 'type'],

+ 18 - 0
app/Services/common/BatchUpdateService.php

@@ -67,4 +67,22 @@ class BatchUpdateService
             return false;
         }
     }
+
+    public function batchUpdateItself($tableName, $column, array $params, $connection = 'mysql')
+    {
+        $sql = "UPDATE ".$tableName;
+        $sql .= " SET ".$column." = CASE".$column;
+        foreach ($params as $key => $value){
+            $sql .= " WHEN ".$key." THEN ".$value;
+        }
+        $sql .= "END WHERE ".$column." IN (".implode(',',array_keys($params)).")";
+        try {
+            $bool = DB::connection($connection)->update($sql);
+            LogService::log(__METHOD__, __FUNCTION__, '批量更新本身' .$sql);
+            return $bool;
+        }catch (\Exception $e){
+            LogService::log(__METHOD__, __FUNCTION__, '批量更新失败 SQL:(' . $sql .") 堆栈:". $e->getMessage() . $e->getTraceAsString());
+            return false;
+        }
+    }
 }

+ 3 - 2
resources/views/waybill/index.blade.php

@@ -366,9 +366,10 @@
                         {name:'owner_id',type:'select_multiple_select',tip:['输入关键词快速定位下拉列表,回车确定','选择要显示的客户'],
                             placeholder:['货主','定位或多选货主'],data:this.owners},
                         {name:'created_at_start',type:'dateTime',tip:'选择显示指定日期的起始时间'},
-                        {name:'origination',type:'input',tip:'始发地:可在侧增加百分号(%)进行模糊搜索',placeholder: '始发地'},
-                        {name:'carrier_bill',type:'input',tip:'承运商单号:可在侧增加百分号(%)进行模糊搜索',placeholder: '承运商单号'},
+                        {name:'origination',type:'input',tip:'始发地:可在侧增加百分号(%)进行模糊搜索',placeholder: '始发地'},
+                        {name:'carrier_bill',type:'input',tip:'承运商单号:可在侧增加百分号(%)进行模糊搜索',placeholder: '承运商单号'},
                         {name:'status',type:'select',placeholder: '运单状态',data:this.status},
+                        {name:'source_bill',type:'input',tip: '上游单号:可在左侧增加百分号(%)进行模糊搜索',placeholder: '上游单号'},
                     ],
                     [
                         {name:'wms_bill_number',type:'input',tip:'WMS单号:可在两侧增加百分号(%)进行模糊搜索',placeholder: 'WMS单号'},

+ 2 - 0
serves/excelExportGo/api/controller/rejectedController.go

@@ -80,6 +80,8 @@ func RejectedFormat(data []map[string]string) ([]interface{}, [][]interface{}, m
 					val = "待推单"
 				case "3":
 					val = "上传异常"
+                case "4":
+                    val = "交互异常"
 				}
 			}
 			line[value] = val