Browse Source

Merge branch 'master' into zzd

dream 5 năm trước cách đây
mục cha
commit
9fbafeced9
53 tập tin đã thay đổi với 1136 bổ sung725 xóa
  1. 1 0
      .gitignore
  2. 1 1
      app/Http/Controllers/OrderTrackingController.php
  3. 85 0
      app/Http/Controllers/StationTypeBinMonitorController.php
  4. 18 15
      app/Http/Controllers/TestController.php
  5. 4 0
      app/Http/Controllers/api/thirdPart/haochuang/SortingController.php
  6. 35 96
      app/Services/CommodityService.php
  7. 18 10
      app/Services/LogisticService.php
  8. 24 0
      app/Services/OracleBasCustomerService.php
  9. 5 5
      app/Services/OrderService.php
  10. 18 35
      app/Services/OrderTrackingService.php
  11. 11 13
      app/Services/OwnerService.php
  12. 29 1
      app/Services/StationService.php
  13. 12 8
      app/Services/WarehouseService.php
  14. 10 0
      app/StationTypeBinMonitor.php
  15. 4 0
      database/factories/OracleBasSKUFactory.php
  16. 12 0
      database/factories/StationConfigFactory.php
  17. 12 0
      database/factories/StationTypeBinMonitorFactory.php
  18. 1 4
      database/migrations/2020_12_03_144334_add_monitor_default_station_and_station_hardware_id_column.php
  19. 1 1
      database/migrations/2020_12_04_175932_create_station_tasks_table.php
  20. 1 1
      database/migrations/2020_12_07_111922_add_column_handled_amount_of_station_task_commodities.php
  21. 53 0
      database/migrations/2020_12_07_114158_create_station_task_children.php
  22. 33 0
      database/migrations/2020_12_07_144724_add_column_bin_numbers_to_task_commodities.php
  23. 35 0
      database/migrations/2020_12_07_150608_create_station_type_bin_monitors_table.php
  24. 16 0
      database/seeds/StationConfigSeeder.php
  25. 16 0
      database/seeds/StationTypeBinMonitorSeeder.php
  26. 46 22
      resources/views/station/monitor/show.blade.php
  27. 1 0
      routes/api/thirdPart/haochuang.php
  28. 90 0
      tests/Services/CommodityService/GetCommodityByOwnerCodeAndSKUTest.php
  29. 53 0
      tests/Services/CommodityService/GetParamsByBasSKUTest.php
  30. 50 0
      tests/Services/LogisticService/GetLogisticByCodeTest.php
  31. 21 10
      tests/Services/LogisticService/GetLogisticByCodesTest.php
  32. 16 5
      tests/Services/OrderService/CreateOrFindOrderInfoTest.php
  33. 17 44
      tests/Services/OrderService/CreateOrFindOrderTest.php
  34. 27 22
      tests/Services/OrderService/FindOrCreateByClientCodeTest.php
  35. 34 24
      tests/Services/OrderService/GetCreateOrderModelByWMSOrderHeadersTest.php
  36. 0 77
      tests/Services/OrderService/GetOrderByLogisticNumberTest.php
  37. 0 1
      tests/Services/OrderService/GetOrderSyncAtTest.php
  38. 47 7
      tests/Services/OrderService/GetParamByOrderHeaderTest.php
  39. 21 6
      tests/Services/OrderService/GetUpdateModelByWmsOrderHeadersTest.php
  40. 0 39
      tests/Services/OrderService/LogisticNumberFirstOrCreateOrderTest.php
  41. 13 5
      tests/Services/OrderService/PushOrderCreatedCacheTest.php
  42. 8 4
      tests/Services/OrderService/PushOrderUpdateCacheTest.php
  43. 16 11
      tests/Services/OrderService/SetOrderSyncAtTest.php
  44. 0 96
      tests/Services/OrderService/SyncOrderByWMSOrderHeaderTest.php
  45. 0 59
      tests/Services/OrderService/SyncOrderTest.php
  46. 74 0
      tests/Services/OwnerService/GetOwnerByCodeTest.php
  47. 55 15
      tests/Services/OwnerService/GetOwnerByCodesTest.php
  48. 0 39
      tests/Services/WarehouseService/GetByWmsOrderTest.php
  49. 24 17
      tests/Services/WarehouseService/GetWareHouseByCodeTest.php
  50. 64 0
      tests/Services/WarehouseService/GetWareHouseByCodesTest.php
  51. 0 32
      tests/Services/WarehouseService/SyncWmsWareHouseTest.php
  52. 0 0
      tests/webApi/thirdPart/haochuang/process.http
  53. 4 0
      tests/webApi/thirdPart/haochuang/scanCommodity.http

+ 1 - 0
.gitignore

@@ -9,6 +9,7 @@
 /public/mix-manifest.json
 /public/js/app.js
 /public/css/app.csscd
+/public/css/app.css
 /storage/*.key
 /vendor
 .env

+ 1 - 1
app/Http/Controllers/OrderTrackingController.php

@@ -202,7 +202,7 @@ class OrderTrackingController extends Controller
                 $order_client_code,
                 $web_order_number,
                 $pick_up_at=='0000-00-00'?'':$pick_up_at,
-                $orderTracking->sala,
+                $orderTracking->sale,
                 $orderTracking->client,
                 $orderTracking->commodities->commodity->sku ?? '',
                 $orderTracking->commodities->commodity->name ?? '',

+ 85 - 0
app/Http/Controllers/StationTypeBinMonitorController.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\StationTypeBinMonitor;
+use Illuminate\Http\Request;
+
+class StationTypeBinMonitorController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\StationTypeBinMonitor  $stationTypeBinMonitor
+     * @return \Illuminate\Http\Response
+     */
+    public function show(StationTypeBinMonitor $stationTypeBinMonitor)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\StationTypeBinMonitor  $stationTypeBinMonitor
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(StationTypeBinMonitor $stationTypeBinMonitor)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\StationTypeBinMonitor  $stationTypeBinMonitor
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, StationTypeBinMonitor $stationTypeBinMonitor)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\StationTypeBinMonitor  $stationTypeBinMonitor
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(StationTypeBinMonitor $stationTypeBinMonitor)
+    {
+        //
+    }
+}

+ 18 - 15
app/Http/Controllers/TestController.php

@@ -785,21 +785,7 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
     }
 
 
-    public function test3()
-    {
-        /** @var OrderTrackingService $orderTrackingService */
-        $orderTrackingService = app('OrderTrackingService');
-        /** @var OrderService $orderService */
-        $orderService = app(OrderService::class);
-        $owners = app(OrderTrackingOwnerService::class)->getTrackingOrderOwner();
-        $startDate = \Illuminate\Support\Carbon::parse('2020-10-28 00:00:00')->toDateTimeString();
-        $orderHeaders = OracleDOCOrderHeader::query()->with(['oracleDOCOrderDetails', 'actAllocationDetails', 'oracleBASCode'])
-            ->where('addTime', '>=', $startDate)
-            ->whereIn('customerID', data_get($owners, '*.code'))
-            ->get();
-        $orderService->updateByWmsOrders($orderHeaders);
-        $orderTrackingService->updateByWmsOrderHeaders($orderHeaders);
-    }
+
 
     public function test11()
     {
@@ -1152,4 +1138,21 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
         $tack->handle();
         dump(11);
     }
+
+    public function syncOrderTracking()
+    {
+        /** @var OrderTrackingService $orderTrackingService */
+        $orderTrackingService = app('OrderTrackingService');
+        /** @var OrderService $orderService */
+        $orderService = app(OrderService::class);
+        /*$owners = app(OrderTrackingOwnerService::class)->getTrackingOrderOwner();*/
+        /*$startDate = \Illuminate\Support\Carbon::parse('2020-10-28 00:00:00')->toDateTimeString();*/
+        $orderNos = ['SO201205001735','SO201204003891','SO201204003706','SO201204002877','SO201203003771'];
+        $orderHeaders = OracleDOCOrderHeader::query()->with(['oracleDOCOrderDetails', 'actAllocationDetails', 'oracleBASCode'])
+            ->whereIn('orderno',$orderNos)
+            ->get();
+        $orderService->updateByWmsOrders($orderHeaders);
+        $orderTrackingService->createByWmsOrderHeader($orderHeaders);
+    }
+
 }

+ 4 - 0
app/Http/Controllers/api/thirdPart/haochuang/SortingController.php

@@ -50,6 +50,10 @@ class SortingController extends Controller
         ]);
     }
 
+    function scanCommodity(Request $request){
+        return ['result'=>'success','data'=>json_encode($request->all())];
+    }
+
     function process(Request $request){
         $token = trim($request->input('token'));
         $station_id = $request->input('station_id');

+ 35 - 96
app/Services/CommodityService.php

@@ -16,10 +16,16 @@ use Illuminate\Support\Facades\Cache;
 
 Class CommodityService
 {
-    /** @var CacheService $cacheService */
+
+    /**
+     * @var CacheService $cacheService
+     * @var OwnerService $ownerService
+     */
     private $cacheService;
+    private $ownerService;
     function __construct(){
         $this->cacheService=app('CacheService');
+        $this->ownerService=app('OwnerService');
     }
 
     public function firstOrCreate($param,$column = null):Commodity{
@@ -343,107 +349,40 @@ Class CommodityService
 
     public function getCommoditiesByMap($map)
     {
-        /**
-         * @var OwnerService $ownerService
-         * @var OracleBasSkuService $oracleBasSkuService
-         */
-        $ownerService = app('OwnerService');
-        $oracleBasSkuService = app('OracleBasSkuService');
-
-        $commodities_map = (function()use($map){
-            $commodities_map = [];
-            if(count($map)==0)return $commodities_map;
-            Commodity::query()->with("owner")->whereIn('sku',array_unique(data_get($map,'*.sku')))->whereHas('owner',function($query)use($map){
-                $query->whereIn('code',array_unique(data_get($map,'*.owner_code')));
-            })->get()->each(function($commodity)use(&$commodities_map){
-                $commodities_map[json_encode(['owner_code' => $commodity['owner']['code'], 'sku' => $commodity['sku']])] = $commodity;
-            });
-            return $commodities_map;
-        })();
-
-        $owner_codes = (function()use($map){
-            $owner_codes = [];
-            if(count($map) == 0)return $owner_codes;
-            foreach ($map as $item) {
-                $owner_codes[$item['owner_code']] = $item['owner_code'];
-            }
-            return $owner_codes;
-        })();
-
-        $owner_map = (function()use($ownerService,$owner_codes){
-            $owners = $ownerService->getOwnerByCodes($owner_codes);
-            $map = [];
-            $owners->each(function ($owner)use(&$map){
-                $map[$owner['code']] = $owner['id'];
-            });
-            return $map;
-        })();
-
         $collect = collect();
-        if(count($map) == 0) return $collect;
-        $unexists = [];$sku = [];$owner_code = [];
-
+        if(count($map)==0)return $collect;
         foreach ($map as $item) {
-            $owner = Cache::get("owner_code_{$item['owner_code']}_sku_{$item['sku']}");
-            if($owner){
-                $collect->push($owner);
-                continue;
-            }
-            $key = json_encode( ['owner_code' => $item['owner_code'], 'sku' => $item['sku']]);
-            if(!empty($commodities_map[json_encode($key)])){
-                 $commodities_map[$key];
-                continue;
-            }
-            $unexists[json_encode($key)] = true;
-            $sku[] = $item['sku'];
-            $owner_code[] = $item['owner_code'];
+            $commodity = $this->getCommodityByOwnerCodeAndSKU($item['owner_code'],$item['sku']);
+            $collect->push($commodity);
         }
+        return $collect;
+    }
 
-        if(count($unexists) == 0)return $collect;
-        $BasSKUs = $oracleBasSkuService->get( ['SKU'=>$sku,'CustomerID'=>$owner_code]);
-        $BasSKUs = $BasSKUs->filter(function($bas_sku)use($unexists,$commodities_map){
-            $arr = [
-                'owner_code' => $bas_sku['customerid'],
-                'sku' => $bas_sku['sku']
-            ];
-            $key = json_encode($arr);
-            if(!empty($commodities_map($key)))return false;
-            return $unexists[json_encode($arr)] ?? false;
+    public function getCommodityByOwnerCodeAndSKU($ownerCode,$sku){
+        $commodity_key = "owner_code_{$ownerCode}_sku_{$sku}";
+        return Cache::remember($commodity_key,300,function()use($ownerCode,$sku){
+            $commodity = Commodity::query()->where('sku',$sku)->whereHas('owner',function($query)use($ownerCode){
+                $query->where('code',$ownerCode);
+            })->first();
+            if(isset($commodity))return $commodity;
+            $basSKu =  app('OracleBasSkuService')->first(['sku'=>$sku,'customerid'=>$ownerCode]);
+            return Commodity::query()->create($this->getParamsByBasSku($basSKu));
         });
-        $inner_params = (function()use($BasSKUs,$owner_map){
-            $map = [];
-            $date = Carbon::now();
-            $BasSKUs->each(function($basSku)use(&$map,$owner_map,$date){
-                $map[] = [
-                    'owner_id' => $owner_map[$basSku['customerid']] ?? '',
-                    'sku' => $basSku->sku,
-                    'name' =>$basSku->descr_c,
-                    'length' =>$basSku->skulength,
-                    'width' => $basSku->skuwidth,
-                    'height' => $basSku->skuhigh,
-                    'volumn' => $basSku->cube,
-                    'created_at' => $date,
-                    'updated_at' => $date,
-                ];
-            });
-            return $map;
-        })();
-        if(count($inner_params)==0)return $collect;
-        foreach (array_chunk($inner_params,4000) as $item) {
-            try {
-                $bool = Commodity::query()->insert($item);
-                if($bool){
-                    app('LogService')->log(__METHOD__,__FUNCTION__,"批量添加 Commodity Success ".count($inner_params).' || '.json_encode($inner_params));
-                    $commodities = Commodity::query()->with('owner')->whereIn('owner_id',data_get($item,'*.owner_id'))->whereIn('sku',data_get($item,'*.sku'))->get();
-                    $this->pushToCache($commodities);
-                    $collect = $collect->concat($commodities);
-                }
-                else app('LogService')->log(__METHOD__,__FUNCTION__,"批量添加 Commodity FAILED ".' || '.json_encode($inner_params));
-            } catch (\Exception $e) {
-                app('LogService')->log(__METHOD__,__FUNCTION__,"批量添加 Commodity ERROR ".' || '.json_encode($inner_params).' || '.json_encode($e->getMessage()).' || '.json_encode($e->getTraceAsString()));
-            }
+    }
+
+    public function getParamsByBasSku($basSku,$owner = null){
+        if(empty($owner)){
+            $owner = app('OwnerService')->getOwnerByCode($basSku['customerid']);
         }
-        return $collect;
+        return  [
+            'owner_id' => $owner['id'] ?? '',
+            'sku' => $basSku['sku'],
+            'name' =>$basSku['descr_c'],
+            'length' =>$basSku['skulength'],
+            'width' => $basSku['skuwidth'],
+            'height' => $basSku['skuhigh'],
+            'volumn' => $basSku['cube']
+        ];
     }
 
     private function pushToCache($commodities)

+ 18 - 10
app/Services/LogisticService.php

@@ -95,18 +95,26 @@ Class LogisticService
         $collect = collect();
         if(count($codes) == 0) return $collect;
         foreach ($codes as $code) {
-            $collect->push(Cache::remember("getLogisticByCodes_{$code}", config('database.cache.expirations.rand'), function()use($code){
-                $logistic = Logistic::query()->where('code',$code)->first();
-                if($logistic)return $logistic;
-                $baseCustomers = OracleBasCustomer::query()
-                    ->selectRaw('Customer_Type,CustomerID,Descr_C')
-                    ->where('Customer_Type','CA')
-                    ->where('CustomerID',$code)->first();
-                if(!$baseCustomers)return null;
-                return Logistic::query()->create(['name' => $baseCustomers['descr_c'], 'code' => $baseCustomers['customerid']]);
-            }));
+            $collect->push($this->getLogisticByCode($code));
         }
         return $collect;
     }
 
+    public function getLogisticByCode($code){
+        return Cache::remember("getLogisticByCode_{$code}", config('database.cache.expirations.logistic'), function()use($code){
+            $logistic = Logistic::query()->where('code',$code)->first();
+            if($logistic)return $logistic;
+            $baseCustomers = app('OracleBasCustomerService')->first(['Customer_Type'=>'CA','CustomerID'=>'$code']);
+            if(!$baseCustomers)return null;
+            try {
+                $logistic = Logistic::query()->create(['name' => $baseCustomers['descr_c'], 'code' => $baseCustomers['customerid']]);
+                app('LogService')->log(__METHOD__, __FUNCTION__,'创建Logistic SUCCESS'." || ". json_encode($logistic));
+                return $logistic;
+            } catch (\Exception $e) {
+                app('LogService')->log(__METHOD__, __FUNCTION__,'创建Logistic ERROR'." || ". json_encode($logistic)." || ".json_encode($e->getMessage())." || ".json_encode($e->getTraceAsString()));
+                return null;
+            }
+        });
+    }
+
 }

+ 24 - 0
app/Services/OracleBasCustomerService.php

@@ -8,9 +8,33 @@ Class OracleBasCustomerService
 {
     /** @var CacheService $cacheService */
     private $cacheService;
+
     function __construct(){
         $this->cacheService=app('CacheService');
     }
+
+    public function get(array $params){
+        $query = $this->query($params);
+        return $query->get();
+    }
+    public function first(array $params){
+        return $this->query($params)->first();
+    }
+
+    public function count(array $params){
+        $query = $this->query($params);
+        return $query->count();
+    }
+
+    private function query(array $params){
+        $query = OracleBasCustomer::query();
+        foreach ($params as $column => $value){
+            if (is_array($value))$query->whereIn($column,$value);
+            else $query->where($column,$value);
+        }
+        return $query;
+    }
+
     public function getWareHouse($customerIDs = null)
     {
         if(!$customerIDs){

+ 5 - 5
app/Services/OrderService.php

@@ -337,7 +337,7 @@ class OrderService
         $orderPackageService = app('OrderPackageService');
         $order = Order::query()->where('client_code', $clientCode)->first();
 
-        $orderHeader = OracleDOCOrderHeader::query()->where('SOReference1', $clientCode)->first();
+        $orderHeader = app('OracleDocOrderHeaderService')->first(['SOReference1'=> $clientCode]);
 
         if ($orderHeader == null) {
             return null;
@@ -820,7 +820,7 @@ class OrderService
         $owners = $ownerService->getOwnerByCodes($owner_codes);
         $logistics = $logisticService->getLogisticByCodes($logistic_codes);
         $shops = $shopService->getShopByCodeMap($shop_names);
-        $warehouses = $warehouseService->getWareHouseByCode($warehouse_codes);
+        $warehouses = $warehouseService->getWareHouseByCodes($warehouse_codes);
 
         $orders = $this->getByWmsOrders($orderHeaders);
 
@@ -1035,7 +1035,7 @@ class OrderService
     public function pushOrderCache($orderHeaders,$prefixKey,$hasKey,$list_key){
         $list = [];
         try {
-            Redis::LLEN($list_key);
+            Cache::get($hasKey);
             collect($orderHeaders)->each(function($item)use(&$list,$prefixKey){
                 $list[] =$item->orderno;
                 Cache::put($prefixKey.$item->orderno,true);
@@ -1057,7 +1057,7 @@ class OrderService
         if(!$orderHeaders)return $orderHeaders;
         if(!$key)return $orderHeaders;
         try {
-            Redis::LLEN($key);
+            Cache::get($key);
             return array_filter($orderHeaders,function($item)use($key){
                 $bool = Cache::get($key.$item->orderno);
                 return !$bool;
@@ -1070,7 +1070,7 @@ class OrderService
     public function cancelOrderCache($key,string $prefix)
     {
         try {
-            Redis::LLEN($key);
+            Cache::get($prefix);
             $list = Cache::get($key);
             collect($list)->each(function ($item)use($prefix) {
                 Cache::forget($prefix.$item);

+ 18 - 35
app/Services/OrderTrackingService.php

@@ -258,17 +258,7 @@ class OrderTrackingService
             $order_header = $order_headers_map[$order->code];
             if(!$order_header){continue ;}
             if($order_header->sostatus == 90){continue;}
-            $client = null;
-            $order_remark = null;
-            if ($order_header['notes'] ?? false) {
-                $notes = $order_header->notes;
-                if (strpos($notes, '[')) {
-                    $strings = [];
-                    preg_match_all('/^(.*?)(\\[)(.*?)(\\])(.*?)$/u',$notes,$strings);
-                    $client = $strings[1][0];
-                    $order_remark = $strings[3][0];
-                }
-            }
+
             $web_order_number = null;
             if(preg_match('/^O[\d]/',$order_header['soreference1'] ?? '') > 0){
                 $web_order_number = $order_header['soreference1'];
@@ -282,9 +272,10 @@ class OrderTrackingService
                 'order_package_commodity_id' => $item->id,
                 'owner_id' => $order->owner_id,
                 'order_client_code' =>$order->client_code,
-                'client' => $client,
+                'sale' => $param['sale'],
+                'client' => $param['client'],
                 'created_at' => $order->created_at,
-                'order_remark' => $order_remark,
+                'order_remark' => $param['order_remark'],
                 'pick_up_at' => $order_header->lastshipmenttime, // 提货时间,
                 'web_order_number' => $web_order_number,
                 'gross_weight'=> $gross_weight,
@@ -293,7 +284,6 @@ class OrderTrackingService
                 'planning_sent_at' => $param['planning_sent_at'] ?? ''
             ];
         }
-
         try {
             if (count($params) > 0) {
                 $this->insert($params);
@@ -310,12 +300,14 @@ class OrderTrackingService
         /** @var DataHandlerService $dataService */
         $dataService = app(DataHandlerService::class);
         $order_nos = data_get($orderHeaders,'*.orderno');
-        $order_package_commodities = OrderPackageCommodities::query()
-            ->with('package.order')
+
+        $order_package_commodities = OrderPackageCommodities::query()->with('package.order')
             ->whereHas('package.order',function($query) use ($order_nos){
                 $query->whereIn('code',$order_nos);
             })->get();
+
         $orderTrackings = OrderTracking::query()->whereIn('order_package_commodity_id',data_get($order_package_commodities,'*.id'))->get();
+
         $order_tracking_id_map = [];
         foreach ($orderTrackings as $orderTracking) {
             $order_tracking_id_map[$orderTracking->order_package_commodity_id] = $orderTracking;
@@ -386,12 +378,12 @@ class OrderTrackingService
                     $basSkU = $dataService->getKeyValue(['customerid'=>$orderHeader->customerid,'sku'=>$item->commodity->sku],$BasSKUs_code_sku_map);
                     $gross_weight = round($basSkU->grossweight * $item->amount, 2);
                     $bulk = round($basSkU->cube * $item->amount, 2);
-                    $pararm = $this->getParamsByOrderHeaderAndOrder($orderHeader,$order);
-                    $pararm['order_package_commodity_id'] =$item->id;
-                    $pararm['order_client_code'] = $order->client_code;
-                    $pararm['gross_weight'] = $gross_weight;
-                    $pararm['bulk'] = $bulk;
-                    $insert_params[] =$pararm;
+                    $param = $this->getParamsByOrderHeaderAndOrder($orderHeader,$order);
+                    $param['order_package_commodity_id'] =$item->id;
+                    $param['order_client_code'] = $order->client_code;
+                    $param['gross_weight'] = $gross_weight;
+                    $param['bulk'] = $bulk;
+                    $insert_params[] =$param;
                 }
             }
         }
@@ -415,16 +407,6 @@ class OrderTrackingService
     {
         $client = null;
         $order_remark = null;
-        if ($orderHeader['notes'] ?? false) {
-            $notes = $orderHeader->notes;
-            if (strpos($notes, '[')) {
-                $index = strpos($notes, '[');
-                $client = substr($notes,0,$index);
-                $order_remark = substr($notes,$index);
-                $order_remark = ltrim($order_remark,'[');
-                $order_remark = rtrim($order_remark,']');
-            }
-        }
         $web_order_number = null;
         if(preg_match('/^O[\d]/',$orderHeader['soreference1'] ?? '') > 0){
             $web_order_number = $orderHeader['soreference1'];
@@ -439,10 +421,11 @@ class OrderTrackingService
         }
         return [
             'owner_id' => $order->owner_id,
-            'client' => $client,
+            'client' => $orderHeader['c_contact'] ?? '',
+            'sale' => $orderHeader['issuepartyname'] ?? '',
             'created_at' => $order->created_at,
-            'order_remark' => $order_remark,
-            'pick_up_at' => $orderHeader->lastshipmenttime, // 提货时间
+            'order_remark' => $orderHeader['notes'] ?? '',
+            'pick_up_at' => $orderHeader['lastshipmenttime'] ?? '', // 提货时间
             'web_order_number' =>$web_order_number,
             'is_on_duty_shift'=>$planning_sent_at?'是':null,
             'planning_sent_at' => (string)$planning_sent_at

+ 11 - 13
app/Services/OwnerService.php

@@ -218,25 +218,23 @@ Class OwnerService
         return $builder;
     }
 
-    public function codeGetOwner($code)
-    {
-        return app(CacheService::class)->getOrExecute("owner_".$code,function ()use($code){
-            return Owner::query()->firstOrCreate(["code"=>$code],["code"=>$code,"name"=>$code]);
-        });
-    }
     public function getOwnerByCodes($codes)
     {
         $collect = collect();
         if(count($codes) == 0)return $collect;
         foreach ($codes as $code) {
-            $collect->push(Cache::remember("getOwnerByCodes_{$code}", config('database.cache.expirations.rand'), function ()use($code){
-                $owner = Owner::query()->where('code',$code)->first();
-                if($owner) return $owner;
-                $basCustomer = OracleBasCustomer::query()->where('Customer_Type','OW')->where('CustomerID', $code)->first();
-                if(!$basCustomer)return null;
-                return Owner::query()->create(['name'=>$basCustomer['descr_c'],'code'=>$basCustomer['customerid']]);
-            }));
+            $collect->push($this->getOwnerByCode($code));
         }
         return $collect;
     }
+
+    public function getOwnerByCode($code){
+        return Cache::remember("getOwnerByCode_{$code}", config('database.cache.expirations.owner'), function ()use($code){
+            $owner = Owner::query()->where('code',$code)->first();
+            if($owner) return $owner;
+            $basCustomer = app('OracleBasCustomerService')->first(['Customer_Type'=>'OW','CustomerID'=>$code]);
+            if(!$basCustomer)return null;
+            return Owner::query()->create(['name'=>$basCustomer['descr_c'],'code'=>$basCustomer['customerid']]);
+        });
+    }
 }

+ 29 - 1
app/Services/StationService.php

@@ -5,6 +5,8 @@ namespace App\Services;
 
 
 use App\Station;
+use App\StationTask;
+use App\StationTaskCommodity;
 use App\StationType;
 use Exception;
 use Illuminate\Support\Facades\Cache;
@@ -31,8 +33,34 @@ class StationService
         //event(new BroadcastToStation($station_id,$json_data))
     }
 
-    function broadcastBinMonitor($station_id, ){
+    function broadcastBinMonitor($station_id, StationTask $stationTask, int $currentStationTaskCommodity_id){
         //...
+        //$stationTask->stationTaskBatch
+        //$stationTask->stationTaskMaterialBox
+        //$stationTask->stationTaskCommodities   //'待处理',   '处理中' blue,'完成',green
+        //$batch= $stationTask->stationTaskBatch->batch
+        //$orders= $batch->....
+        //.....
+        //$json_data=['batch','stationCommodities','stationMaterialBin','$currentStationTaskCommodity']
+        //$this->broadcast($station_id, $json_data)
+    }
+
+    function broadcastBinChange($station_id, StationTask $stationTask, int $currentStationTaskCommodity_id){
+        //...
+        //$stationTask->stationTaskBatch
+        //$stationTask->stationTaskMaterialBox
+        //$stationTask->stationTaskCommodities   //'待处理',   '处理中' blue,'完成',green
+        //$batch= $stationTask->stationTaskBatch->batch
+        //$orders= $batch->....
+        //.....
+        //$json_data=['batch','stationCommodities','stationMaterialBin','$currentStationTaskCommodity']
+        //$this->broadcast($station_id, $json_data)
+    }
+
+    function broadcastBinMonitorWarning($warnText, $station_id, StationTask $stationTask){
+        //...
+        //...
+        //$json_data=['warn']
         //$this->broadcast($station_id, $json_data)
     }
 

+ 12 - 8
app/Services/WarehouseService.php

@@ -105,20 +105,24 @@ Class WarehouseService
         return Warehouse::query()->insert($fillables);
     }
 
-    public function getWareHouseByCode($codes)
+    public function getWareHouseByCodes($codes)
     {
         $collect = collect();
         if(count($codes)==0)return $collect;
         foreach ($codes as $code) {
-            $collect->push(Cache::remember("WareHouse_{$code}",config('database.cache.expirations.rand'),function()use($code){
-                $wareHouse =  Warehouse::query()->where('code',$code)->first();
-                if($wareHouse)return $wareHouse;
-                $bas_customer = OracleBasCustomer::query()->selectRaw('Customer_Type,CustomerId,Descr_C')->where('CustomerId',$code)->where('Customer_Type','WH')->first();
-                if(!$bas_customer) return null;
-                return Warehouse::query()->create(['name'=>$bas_customer['descr_c'],'code'=>$bas_customer['customerid']]);
-            }));
+            $collect->push($this->getWareHouseByCode($code));
         }
         return $collect;
     }
+
+    public function getWareHouseByCode($code){
+        return Cache::remember("WareHouse_{$code}",config('database.cache.expirations.warehouse'),function()use($code){
+            $wareHouse =  Warehouse::query()->where('code',$code)->first();
+            if($wareHouse)return $wareHouse;
+            $bas_customer = app('OracleBasCustomerService')->first(['CustomerId'=>$code,'Customer_Type'=>'WH']);
+            if(!$bas_customer) return null;
+            return Warehouse::query()->create(['name'=>$bas_customer['descr_c'],'code'=>$bas_customer['customerid']]);
+        });
+    }
 }
 

+ 10 - 0
app/StationTypeBinMonitor.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class StationTypeBinMonitor extends Model
+{
+    protected $fillable=['station_id','bin_row_length','bin_column_length','bin_wall_amount'];
+}

+ 4 - 0
database/factories/OracleBasSKUFactory.php

@@ -11,5 +11,9 @@ $factory->define(OracleBasSKU::class, function (Faker $faker) {
         'sku' =>$faker->name,
         'descr_c' =>$faker->title(20),
         'packid'=>$faker->name,
+        'skulength' =>$faker->numberBetween(1,100),
+        'skuwidth'=>$faker->numberBetween(1,100),
+        'skuhigh'=>$faker->numberBetween(1,100),
+        'cube'=>$faker->numberBetween(1,100),
     ];
 });

+ 12 - 0
database/factories/StationConfigFactory.php

@@ -0,0 +1,12 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\StationConfig;
+use Faker\Generator as Faker;
+
+$factory->define(StationConfig::class, function (Faker $faker) {
+    return [
+        //
+    ];
+});

+ 12 - 0
database/factories/StationTypeBinMonitorFactory.php

@@ -0,0 +1,12 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\StationTypeBinMonitor;
+use Faker\Generator as Faker;
+
+$factory->define(StationTypeBinMonitor::class, function (Faker $faker) {
+    return [
+        //
+    ];
+});

+ 1 - 4
database/migrations/2020_12_03_144334_add_monitor_default_station_and_station_hardware_id_column.php

@@ -19,10 +19,7 @@ class AddMonitorDefaultStationAndStationHardwareIdColumn extends Migration
             $table->string('remark')->nullable();
         });
         $stationType= StationType::query()->firstOrCreate(['name'=>'料箱监视器']);
-        $station= Station::query()->firstOrCreate(['name'=>'料箱监视器01']);
-        $station['sequence']=1;
-        $station['station_type_id']=$stationType['id'];
-        $station->save();
+        Station::query()->firstOrCreate(['name'=>'料箱监视器01','sequence'=>1,'station_type_id'=>$stationType['id']]);
     }
     /**
      * Reverse the migrations.

+ 1 - 1
database/migrations/2020_12_04_175932_create_station_tasks_table.php

@@ -18,7 +18,7 @@ class CreateStationTasksTable extends Migration
             $table->integer('station_id');
             $table->integer('station_type_id')->nullable()->index();
             $table->enum('status',['待处理','挂起','处理中','完成','异常','取消'])->index();
-            $table->index('station_id','station_type_id','status');
+            $table->index(['station_id','station_type_id','status']);
             $table->timestamps();
         });
     }

+ 1 - 1
database/migrations/2020_12_07_111922_add_column_handled_amount_of_station_task_commodities.php

@@ -14,7 +14,7 @@ class AddColumnHandledAmountOfStationTaskCommodities extends Migration
     public function up()
     {
         Schema::table('station_task_commodities', function (Blueprint $table) {
-            $table->integer('handled_amount')->default(0);
+            $table->integer('handled_amount')->default(0)->after('amount');
         });
     }
 

+ 53 - 0
database/migrations/2020_12_07_114158_create_station_task_children.php

@@ -0,0 +1,53 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateStationTaskChildren extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('station_task_children', function (Blueprint $table) {
+            $table->id();
+            $table->bigInteger('station_task_id')->index();
+            $table->string('station_task_table_type');
+            $table->bigInteger('station_task_table_id');
+            $table->index('station_task_table_id','station_task_table_type');
+            $table->timestamps();
+        });
+        Schema::table('station_task_batches', function (Blueprint $table) {
+            $table->dropColumn('station_id');
+        });
+        Schema::table('station_task_commodities', function (Blueprint $table) {
+            $table->dropColumn('station_id');
+        });
+        Schema::table('station_task_material_boxes', function (Blueprint $table) {
+            $table->dropColumn('station_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('station_task_batches', function (Blueprint $table) {
+            $table->integer('station_id')->index();
+        });
+        Schema::table('station_task_commodities', function (Blueprint $table) {
+            $table->integer('station_id')->index();
+        });
+        Schema::table('station_task_material_boxes', function (Blueprint $table) {
+            $table->integer('station_id')->index();
+        });
+        Schema::dropIfExists('station_task_children');
+    }
+}

+ 33 - 0
database/migrations/2020_12_07_144724_add_column_bin_numbers_to_task_commodities.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddColumnBinNumbersToTaskCommodities extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('station_task_commodities', function (Blueprint $table) {
+            $table->integer('bin_number')->after('handled_amount');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('station_task_commodities', function (Blueprint $table) {
+            $table->dropColumn('bin_number');
+            //
+        });
+    }
+}

+ 35 - 0
database/migrations/2020_12_07_150608_create_station_type_bin_monitors_table.php

@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateStationTypeBinMonitorsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('station_type_bin_monitors', function (Blueprint $table) {
+            $table->id();
+            $table->integer('station_id')->index();
+            $table->integer('bin_row_length')->default(4);
+            $table->integer('bin_column_length')->default(5);
+            $table->integer('bin_wall_amount')->default(2);
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('station_type_bin_monitors');
+    }
+}

+ 16 - 0
database/seeds/StationConfigSeeder.php

@@ -0,0 +1,16 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class StationConfigSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        //
+    }
+}

+ 16 - 0
database/seeds/StationTypeBinMonitorSeeder.php

@@ -0,0 +1,16 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class StationTypeBinMonitorSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        //
+    }
+}

+ 46 - 22
resources/views/station/monitor/show.blade.php

@@ -19,10 +19,10 @@
                     <div class="col text-center  h3 py-2 text-muted">智能分拣</div>
                 </div>
                 <div class="row pt-3">
-                    <div class="col-4 text-center">
+                    <div class="col-4">
                         <div class="row">
                             <div class="col py-3 h4">
-                                波次号:
+                                波次号:nnnnnnnnnnn
                             </div>
                             <div class="col py-3 h4">
 
@@ -37,17 +37,7 @@
                         </div>
                         <div class="row">
                             <div class="col py-3 h4">
-                                料箱号:
-                            </div>
-                            <div class="col py-3 h4">
-
-                            </div>
-                        </div>
-                        <div class="row">
-                            <div class="col py-3 h4">
-                            </div>
-                            <div class="col py-3 h4 text-muted">
-                                {条码}
+                                料箱号:nnnnnnnnnnn
                             </div>
                         </div>
                         <div class="row pt-5">
@@ -56,8 +46,42 @@
                     </div>
                     <div class="col text-center">
                         <div class="row">
-                            <div class="col py-3 h4">订单号:</div>
-                            <div class="col py-3 h4">N</div>
+                            <div class="col py-3 h4">
+                                <table class="table border">
+                                    <tr>
+                                        <td class="border p-0"><span style="opacity:0.25">6</span></td>
+                                        <td class="bg-info border p-0"><span style="opacity:0.25">7</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">8</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">9</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">10</span></td>
+                                    </tr>
+                                    <tr>
+                                        <td class="border p-0"><span style="opacity:0.25">1</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">2</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">3</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">4</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">5</span></td>
+                                    </tr>
+                                </table>
+                            </div>
+                            <div class="col py-3 h4">
+                                <table class="table border">
+                                    <tr>
+                                        <td class="border p-0"><span style="opacity:0.25">6</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">7</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">8</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">9</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">10</span></td>
+                                    </tr>
+                                    <tr>
+                                        <td class="border p-0"><span style="opacity:0.25">1</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">2</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">3</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">4</span></td>
+                                        <td class="border p-0"><span style="opacity:0.25">5</span></td>
+                                    </tr>
+                                </table>
+                            </div>
                         </div>
                         <div class="row">
                             <div class="col py-1">数量</div>
@@ -68,28 +92,28 @@
                         <div class="row">
                             <div class="col py-1">
                                 <table class="table table-striped border">
-                                    <tr>
+                                    <tr class="text-muted">
                                         <th class="py-2">序号</th>
                                         <th class="py-2">商品</th>
                                         <th class="py-2">数量</th>
                                         <th class="py-2">条码</th>
                                     </tr>
-                                    <tr>
-                                        <td></td>
+                                    <tr class="text-muted">
                                         <td></td>
                                         <td></td>
+                                        <td>0/0</td>
                                         <td></td>
                                     </tr>
-                                    <tr>
-                                        <td></td>
+                                    <tr class="text-muted">
                                         <td></td>
                                         <td></td>
+                                        <td>0/0</td>
                                         <td></td>
                                     </tr>
-                                    <tr>
-                                        <td></td>
+                                    <tr class="text-muted">
                                         <td></td>
                                         <td></td>
+                                        <td>0/0</td>
                                         <td></td>
                                     </tr>
                                 </table>

+ 1 - 0
routes/api/thirdPart/haochuang.php

@@ -13,5 +13,6 @@ use Illuminate\Http\Request;
 Route::prefix('sorting')->group(function(){
     Route::post('login', "SortingController@login");
     Route::post('process', "SortingController@process");
+    Route::post('scanCommodity', "SortingController@scanCommodity");
     Route::post('done', "SortingController@done");
 });

+ 90 - 0
tests/Services/CommodityService/GetCommodityByOwnerCodeAndSKUTest.php

@@ -0,0 +1,90 @@
+<?php
+
+namespace Tests\Feature\Services\CommodityService;
+
+use App\Commodity;
+use App\OracleBasSKU;
+use App\Owner;
+use App\Services\CommodityService;
+use App\Services\OracleBasSkuService;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Tests\TestCase;
+
+class GetCommodityByOwnerCodeAndSKUTest extends TestCase
+{
+    use RefreshDatabase;
+
+    /**
+     * @var CommodityService $service
+     */
+    private $service;
+    private $data = [];
+
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->service = app('CommodityService');
+        $owner =  factory(Owner::class)->create();
+        $basSKU = factory(OracleBasSKU::class)->make(['customerid'=>$owner->code]);
+        $this->data['owner'] = $owner;
+        $this->data['basSKU'] = $basSKU;
+        $this->data['commodity1'] = factory(Commodity::class)->create([
+            'owner_id' => $this->data['owner']['id'] ?? '',
+            'sku' => $this->data['basSKU']['sku'],
+            'name' =>$this->data['basSKU']['descr_c'],
+            'length' =>$this->data['basSKU']['skulength'],
+            'width' => $this->data['basSKU']['skuwidth'],
+            'height' => $this->data['basSKU']['skuhigh'],
+            'volumn' => $this->data['basSKU']['cube']
+        ]);
+        $this->mock(OracleBasSkuService::class,function($mock)use($basSKU){
+            $mock->shouldReceive('first')->andReturn($basSKU);
+        });
+
+    }
+
+    /**
+     * @test
+     */
+    public function getCommodityByOwnerCodeAndSKU()
+    {
+        $owner_code = $this->data['owner']['code'];
+        $sku = $this->data['basSKU']['sku'];
+        $commodity = $this->service->getCommodityByOwnerCodeAndSKU($owner_code,$sku);
+        $this->data['commodity'] = $commodity;
+        $this->assertEquals($commodity['owner_id'],$this->data['owner']['id']);
+        $this->assertEquals($commodity['sku'],$this->data['basSKU']['sku']);
+        $this->assertEquals($commodity['name'],$this->data['basSKU']['descr_c']);
+        $this->assertEquals($commodity['length'],$this->data['basSKU']['skulength']);
+        $this->assertEquals($commodity['width'],$this->data['basSKU']['skuwidth']);
+        $this->assertEquals($commodity['height'],$this->data['basSKU']['skuhigh']);
+        $this->assertEquals($commodity['volumn'],$this->data['basSKU']['cube']);
+    }
+
+    /**
+     * @test
+     */
+    public function commodityIsNotExist()
+    {
+        $this->data['commodity1']->delete();
+        $owner_code = $this->data['owner']['code'];
+        $sku = $this->data['basSKU']['sku'];
+        $commodity = $this->service->getCommodityByOwnerCodeAndSKU($owner_code,$sku);
+        $this->assertNotNull($commodity->owner_id);
+        $this->assertEquals($commodity['owner_id'],$this->data['owner']['id']);
+        $this->assertEquals($commodity['sku'],$this->data['basSKU']['sku']);
+        $this->assertEquals($commodity['name'],$this->data['basSKU']['descr_c']);
+        $this->assertEquals($commodity['length'],$this->data['basSKU']['skulength']);
+        $this->assertEquals($commodity['width'],$this->data['basSKU']['skuwidth']);
+        $this->assertEquals($commodity['height'],$this->data['basSKU']['skuhigh']);
+        $this->assertEquals($commodity['volumn'],$this->data['basSKU']['cube']);
+    }
+
+    public function tearDown(): void
+    {
+        $this->data['owner']->delete();
+        $this->data['commodity1']->delete();
+        if(isset($this->data['commodity1']))$this->data['commodity1']->delete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 53 - 0
tests/Services/CommodityService/GetParamsByBasSKUTest.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace Tests\Services\CommodityService;
+
+use App\Commodity;
+use App\OracleBasSKU;
+use App\Owner;
+use App\Services\CommodityService;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Illuminate\Foundation\Testing\WithFaker;
+use Tests\TestCase;
+
+class GetParamsByBasSKUTest extends TestCase
+{
+    use RefreshDatabase;
+    /** @var CommodityService $service */
+    private $service;
+    private $data = [];
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        cache()->flush();
+        $this->service = app('CommodityService');
+        $owner =  factory(Owner::class)->create();
+        $basSKU = factory(OracleBasSKU::class)->make(['customerid'=>$owner->code]);
+        $this->data['owner'] = $owner;
+        $this->data['basSKU'] = $basSKU;
+    }
+
+    /**
+     * @test
+     */
+    public function getParamsByBasSKU()
+    {
+        $created_param = $this->service->getParamsByBasSku($this->data['basSKU']);
+        $this->assertNotNull($created_param['owner_id']);
+        $this->assertEquals($created_param['owner_id'],$this->data['owner']['id']);
+        $this->assertEquals($created_param['sku'],$this->data['basSKU']['sku']);
+        $this->assertEquals($created_param['name'],$this->data['basSKU']['descr_c']);
+        $this->assertEquals($created_param['length'],$this->data['basSKU']['skulength']);
+        $this->assertEquals($created_param['width'],$this->data['basSKU']['skuwidth']);
+        $this->assertEquals($created_param['height'],$this->data['basSKU']['skuhigh']);
+        $this->assertEquals($created_param['volumn'],$this->data['basSKU']['cube']);
+    }
+
+
+
+    public function tearDown(): void
+    {
+        $this->data['owner']->delete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 50 - 0
tests/Services/LogisticService/GetLogisticByCodeTest.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace Tests\Services\LogisticService;
+
+use App\Logistic;
+use App\OracleBasCustomer;
+use App\Services\LogisticService;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Tests\TestCase;
+
+class GetLogisticByCodeTest extends TestCase
+{
+    use RefreshDatabase;
+
+    /** @var LogisticService $service */
+    private $service;
+    private $data = [];
+
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->service = app('LogisticService');
+        $logistic = factory(Logistic::class)->create(['code'=>'AABBCCDD1']);
+
+        $basCustomer = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>$logistic->code]);
+        $this->data['basCustomers'] = $basCustomer;
+        $this->data['logistic'] = $logistic;
+        $this->mock('OracleBasCustomerService',function ($mock)use($basCustomer){
+            $mock->shouldReceive('first')->andReturn($basCustomer);
+        });
+    }
+
+    /**
+     * @test
+     */
+    public function getLogisticByCode()
+    {
+        $logistic = $this->service->getLogisticByCode($this->data['logistic']['code']);
+        $this->assertEquals($logistic->id,$this->data['logistic']['id']);
+        $this->assertEquals($logistic->code,$this->data['logistic']['code']);
+        $this->assertEquals($logistic->name,$this->data['logistic']['name']);
+    }
+
+    public function tearDown(): void
+    {
+        cache()->forget('getLogisticByCode_'.$this->data['logistic']['code']);
+        $this->data['logistic']->delete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 21 - 10
tests/Services/LogisticService/GetLogisticByCodesTest.php

@@ -2,8 +2,10 @@
 
 namespace Tests\Services\LogisticService;
 
+use App\Logistic;
 use App\OracleBasCustomer;
 use App\Services\LogisticService;
+use App\Services\OracleBasCustomerService;
 use Illuminate\Foundation\Testing\RefreshDatabase;
 use Tests\TestCase;
 
@@ -19,15 +21,19 @@ class GetLogisticByCodesTest extends TestCase
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $this->service  = app('LogisticService');
-        $baseCustomers = OracleBasCustomer::query()
-            ->selectRaw('Customer_Type,CustomerID,Descr_C')
-            ->where('Customer_Type','CA')
-            ->get();
-
-        $this->data['baseCustomers'] = $baseCustomers;
-        $this->data['codes'] = $baseCustomers->map(function($baseCustomer){
-            return $baseCustomer->customerid;
+        $logistic1 =  factory(Logistic::class)->create();
+        $logistic2 =  factory(Logistic::class)->create();
+        $OracleBasCustomer1 = factory(OracleBasCustomer::class)->make(['customer_type' => 'CA','customerid'=>$logistic1->code,'descr_c' =>$logistic1->name ]);
+        $OracleBasCustomer2 = factory(OracleBasCustomer::class)->make(['customer_type' => 'CA','customerid'=>$logistic2->code,'descr_c' =>$logistic2->name ]);
+        $OracleBasCustomers = collect([$OracleBasCustomer1,$OracleBasCustomer2]);
+        $this->data['baseCustomers'] = $OracleBasCustomers;
+        $this->mock(OracleBasCustomerService::class,function ($mock)use($OracleBasCustomer1,$OracleBasCustomer2){
+            $mock->shouldReceive('first')->with(["Customer_Type"=>'CA',"CustomerID"=>$OracleBasCustomer1['customerid']])->andReturn($OracleBasCustomer1);
+            $mock->shouldReceive('first')->with(["Customer_Type"=>'CA',"CustomerID"=>$OracleBasCustomer2['customerid']])->andReturn($OracleBasCustomer2);
         });
+
+        $this->data['baseCustomers'] = $OracleBasCustomers;
+        $this->data['logistics'] = collect([$logistic1,$logistic2]);
     }
 
     /**
@@ -35,7 +41,7 @@ class GetLogisticByCodesTest extends TestCase
      */
     public function getLogisticByCodes()
     {
-        $logistics = $this->service->getLogisticByCodes($this->data['codes']);
+        $logistics = $this->service->getLogisticByCodes(data_get($this->data['logistics'],'*.code'));
         $this->assertNotEmpty($logistics);
         foreach ($logistics as $logistic) {
             $baseCustomer = $this->data['baseCustomers']->where('customerid',$logistic->code)->where('descr_c',$logistic->name);
@@ -51,7 +57,12 @@ class GetLogisticByCodesTest extends TestCase
 
     public function tearDown(): void
     {
-        cache()->flush();
+        foreach ($this->data['baseCustomers'] as $baseCustomer) {
+            cache()->forget('getLogisticByCode_'.$baseCustomer['customerid']);
+        }
+        foreach ( $this->data['logistics'] as $item) {
+            $item->delete();
+        }
         parent::tearDown(); // TODO: Change the autogenerated stub
     }
 }

+ 16 - 5
tests/Services/OrderService/CreateOrFindOrderInfoTest.php

@@ -6,7 +6,6 @@ use App\Commodity;
 use App\Logistic;
 use App\OracleActAllocationDetails;
 use App\OracleBasCode;
-use App\OracleBasCustomer;
 use App\OracleBasSKU;
 use App\OracleDOCOrderDetail;
 use App\OracleDOCOrderHeader;
@@ -14,6 +13,7 @@ use App\Order;
 use App\OrderPackage;
 use App\OrderPackageCommodities;
 use App\Owner;
+use App\Services\OracleBasSkuService;
 use App\Services\OrderService;
 use App\Shop;
 use App\Warehouse;
@@ -49,7 +49,7 @@ class CreateOrFindOrderInfoTest extends TestCase
         $basSku1 = factory(OracleBasSKU::class)->make(['customerid' => 'TEST_OW']);
         $basSku2 = factory(OracleBasSKU::class)->make(['customerid' => 'TEST_OW']);
         $basSku3 = factory(OracleBasSKU::class)->make(['customerid' => 'TEST_OW']);
-
+        $basSKU = collect([$basSku1,$basSku2,$basSku3]);
         $this->data['sku'] = [];
         $this->data['sku'][] = factory(Commodity::class)->create(['owner_id'=>$this->data['owner']['id'],'sku'=>$basSku1['sku']]);
         $this->data['sku'][] = factory(Commodity::class)->create(['owner_id'=>$this->data['owner']['id'],'sku'=>$basSku2['sku']]);
@@ -70,6 +70,11 @@ class CreateOrFindOrderInfoTest extends TestCase
         $wmsOrderHeader->setRelation('orderType',$orderType);
         $wmsOrderHeader->setRelation('oracleBASCode',$code_BasCode);
         $this->data['orderHeader'] = $wmsOrderHeader;
+
+        $this->mock(OracleBasSkuService::class,function($mock)use($basSKU){
+            $mock->shouldReceive('get')->andReturn($basSKU);
+        });
+
     }
 
     /**
@@ -83,21 +88,27 @@ class CreateOrFindOrderInfoTest extends TestCase
         $this->assertEquals($order->code,$this->data['orderHeader']['orderno']);
         $orderPackages  = OrderPackage::query()->where('order_id',$order['id'])->get();
         $orderPackagesCommodities = OrderPackageCommodities::query()->whereIn('order_package_id',data_get($orderPackages,'*.id'))->get();
-
         $this->assertNotEmpty($orderPackages);
         $this->assertNotEmpty($orderPackagesCommodities);
     }
 
     public function tearDown(): void
     {
-        cache()->flush();
+        foreach ($this->data['sku'] as $datum) {
+            cache()->forget("owner_code_{$this->data['owner']['code']}_sku_{$datum['sku']}");
+        }
+        cache()->forget("getLogisticByCode_{$this->data['logistic']}");
+        cache()->forget("getOwnerByCode_{$this->data['owner']}");
+        cache()->forget("getShopByCodeMap_{$this->data['shop']}");
+        cache()->forget("WareHouse_{$this->data['warehouse']}");
+
         Commodity::query()->whereIn('id',data_get($this->data['sku'],'*.id'))->delete();
         $order = Order::query()->where('code',$this->data['orderHeader']['orderno'])->first();
         $order->delete();
         $this->data['logistic']->delete();
         $this->data['owner']->delete();
-        $this->data['logistic']->delete();
         $this->data['shop']->delete();
+        $this->data['warehouse']->delete();
         parent::tearDown(); // TODO: Change the autogenerated stub
     }
 }

+ 17 - 44
tests/Services/OrderService/CreateOrFindOrderTest.php

@@ -29,49 +29,20 @@ class CreateOrFindOrderTest extends TestCase
     {
         parent::setUp();
         $this->orderService = app('OrderService');
-        $this->data['orderno'] = md5('订单编号'.((string)Carbon::now()));
-        $this->data['warehouse_code'] = 'test';
-        $this->data['userdefine1'] ='测试物流';
-        $this->data['customerid'] = '测试货主';
-        $this->data['issuepartyname'] = '测试商铺';
-        $this->data['orderType'] = '测试';
-
-        $orderHeader = new OracleDOCOrderHeader();
-        $orderHeader->fillable([
-            'orderno' ,'c_contact','c_tel2','c_province','c_city','addtime','edittime',
-            'c_district','c_address1','soreference1','userdefine1','sostatus',
-            'warehouseid','customerid','issuepartyname','orderType']);
-        $orderHeader->fill([
-            'orderno' =>$this->data['orderno'],
-            'c_contact' =>'承运商',
-            'c_tel2' =>'承运商',
-            'c_province' =>'shou',
-            'c_city' =>'shou',
-            'c_district' =>'shou',
-            'c_address1' =>md5('客户订单号'),
-            'soreference1' => Str::uuid(),
-            'userdefine1' =>$this->data['userdefine1'],
-            'warehouseid' =>$this->data['warehouse_code'],
-            'customerid' =>$this->data['customerid'],
-            'issuepartyname' =>$this->data['issuepartyname'],
-            'orderType' =>'sysy',
-            'sostatus' =>'99',
-            'addtime' => Carbon::now(),
-            'addtime' =>Carbon::now(),
+        $wmsOrderHeader = factory(OracleDOCOrderHeader::class)->make([
+            'customerid'=>'TEST_OW','sostatus'=>99,'userdefine1'=>'TEST_CA','warehouseid'=>'WH_TEST'
         ]);
+        $this->data['orderHeader'] =   $wmsOrderHeader;
 
-        $orderType = new OracleBasCode();
-        $orderType->fillable(['code','codeid','codename_c']);
-        $orderType->fill([
-            'code'=>'sysy', 'codeid'=>'SO_TYP', 'codename_c'=>'测试'
-        ]);
-        $orderHeader->setRelation('orderType',$orderType);
+        $orderType = factory(OracleBasCode::class)->make(['code'=>'sysy', 'codeid'=>'SO_TYP', 'codename_c'=>'测试状态']);
+        $wmsOrderHeader->setRelation('orderType',$orderType);
 
-        $this->data['orderHeader'] =$orderHeader;
-        $this->data['logistic'] =  Logistic::query()->firstOrCreate(['code'=>$this->data['userdefine1'],'name'=>'测试物流']);
-        $this->data['owner'] = Owner::query()->firstOrCreate(['code'=>$this->data['customerid'],'name'=>'测试货主']);
-        $this->data['shop'] =Shop::query()->firstOrCreate(['name'=>$this->data['issuepartyname'],'owner_id'=>$this->data['owner']->id]);
-        $this->data['warehouse'] = Warehouse::query()->firstOrCreate(["code"=>$this->data['warehouse_code'],"name"=>'测试仓库']);
+        $code_BasCode  = factory(OracleBasCode::class)->make(['codeid'=>'OW','code'=>'99','descr_c'=>'订单完成']);
+        $wmsOrderHeader->setRelation('oracleBASCode',$code_BasCode);
+        $this->data['warehouse']    = factory(Warehouse::class)->create(['code'=>'WH_TEST']);
+        $this->data['logistic']     = factory(Logistic::class)->create(['code'=>'TEST_CA','name'=>'测试承运商']);
+        $this->data['owner']        = factory(Owner::class)->create(['code'=>'TEST_OW','name'=>'测试货主']);
+        $this->data['shop']         = factory(Shop::class)->create(['owner_id'=>$this->data['owner']['id']]);
     }
     /**
      * @test
@@ -84,17 +55,19 @@ class CreateOrFindOrderTest extends TestCase
         $this->assertNotNull($order);
         $this->assertEquals($order->code,$this->data['orderHeader']['orderno']);
         $this->assertEquals($order->client_code,$this->data['orderHeader']['soreference1']);
-        $this->assertEquals((string)$order->created_at,(string)$this->data['orderHeader']['addtime']);
-        $this->assertEquals((string)$order->wms_edittime,(string)$this->data['orderHeader']['edittime']);
     }
 
     public function tearDown(): void
     {
-        cache()->flush();
+        cache()->forget("getLogisticByCode_{$this->data['logistic']}");
+        cache()->forget("getOwnerByCode_{$this->data['owner']}");
+        cache()->forget("getShopByCodeMap_{$this->data['shop']}");
+        cache()->forget("WareHouse_{$this->data['warehouse']}");
+
+        $this->data['warehouse']->delete();
         $this->data['logistic']->delete();
         $this->data['owner']->delete();
         $this->data['shop']->delete();
-        $this->data['warehouse']->delete();
         Order::query()->where('code',$this->data['orderHeader']['orderno'])->delete();
         parent::tearDown(); // TODO: Change the autogenerated stub
     }

+ 27 - 22
tests/Services/OrderService/FindOrCreateByClientCodeTest.php

@@ -3,14 +3,17 @@
 namespace Tests\Services\OrderService\FindOrCreateByClientCodeTest;
 
 use App\Logistic;
+use App\OracleBasCode;
 use App\OracleDOCOrderHeader;
 use App\Order;
 use App\Owner;
+use App\Services\OracleDOCOrderHeaderService;
 use App\Services\OrderService;
 use App\Shop;
 use App\Warehouse;
 use Illuminate\Foundation\Testing\RefreshDatabase;
 use Illuminate\Foundation\Testing\WithFaker;
+use Illuminate\Support\Str;
 use Tests\TestCase;
 
 class FindOrCreateByClientCodeTest extends TestCase
@@ -25,26 +28,24 @@ class FindOrCreateByClientCodeTest extends TestCase
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $this->service=app('OrderService');
+        $wmsOrderHeader = factory(OracleDOCOrderHeader::class)->make([
+            'customerid'=>'TEST_OW','sostatus'=>99,'userdefine1'=>'TEST_CA','warehouseid'=>'WH_TEST'
+        ]);
 
-        $orderHeader = new OracleDOCOrderHeader();
-        $orderHeader->orderno = md5('订单编号');
-        $orderHeader->c_contact= '京东旗舰店';
-        $orderHeader->c_tel2 = md5('承运商');
-        $orderHeader->c_province = md5('收货人');
-        $orderHeader->c_city = md5('shou');
-        $orderHeader->c_district = md5('shou');
-        $orderHeader->c_address1 = md5('shou');
-        $orderHeader->soreference1 = md5('客户订单号');
-        $orderHeader->userdefine1 = $this->data['userdefine1'];
-        $orderHeader->warehouseid = $this->data['warehouse_code'];
-        $orderHeader->customerid = $this->data['customerid'];
-        $orderHeader->issuepartyname =$this->data['issuepartyname'];
-        $orderHeader->setAppends(['orderType'=>['codename_c'=>$this->data['orderType']]]);
-        $this->data['orderHeader'] = $orderHeader;
-        $this->data['logistic'] =  Logistic::query()->firstOrCreate(['code'=>$this->data['userdefine1'],'name'=>'测试物流']);
-        $this->data['owner'] = Owner::query()->firstOrCreate(['code'=>$this->data['customerid'],'name'=>'测试货主']);
-        $this->data['shop'] =Shop::query()->firstOrCreate(['name'=>$this->data['issuepartyname'],'owner_id'=>$this->data['owner']->id]);
-        $this->data['warehouse'] = Warehouse::query()->firstOrCreate(["code"=>$this->data['warehouse_code'],"name"=>'测试仓库']);
+        $orderType = factory(OracleBasCode::class)->make(['code'=>'sysy', 'codeid'=>'SO_TYP', 'codename_c'=>'测试状态']);
+        $wmsOrderHeader->setRelation('orderType',$orderType);
+
+        $code_BasCode  = factory(OracleBasCode::class)->make(['codeid'=>'OW','code'=>'99','descr_c'=>'订单完成']);
+        $wmsOrderHeader->setRelation('oracleBASCode',$code_BasCode);
+        $this->data['orderHeader'] = $wmsOrderHeader;
+        $this->data['warehouse']    = factory(Warehouse::class)->create(['code'=>'WH_TEST']);
+        $this->data['logistic']     = factory(Logistic::class)->create(['code'=>'TEST_CA','name'=>'测试承运商']);
+        $this->data['owner']        = factory(Owner::class)->create(['code'=>'TEST_OW','name'=>'测试货主']);
+        $this->data['shop']         = factory(Shop::class)->create(['owner_id'=>$this->data['owner']['id']]);
+
+        $this->mock(OracleDOCOrderHeaderService::class,function($mock)use($wmsOrderHeader){
+            $mock->shouldReceive('first')->andReturn($wmsOrderHeader);
+        });
     }
 
     /**
@@ -53,7 +54,7 @@ class FindOrCreateByClientCodeTest extends TestCase
     public function findOrCreateByClientCode()
     {
 
-        $order =  $this->service->findOrCreateByClientCode($this->data['orderHeader']->soreference1);
+        $order =  $this->service->findOrCreateByClientCode($this->data['orderHeader']['soreference1']);
         $this->assertNotEmpty($this->data['orderHeader']['soreference1']);
         $this->assertNotEmpty($order);
         $this->assertNotNull($order->client_code);
@@ -62,11 +63,15 @@ class FindOrCreateByClientCodeTest extends TestCase
 
     public function tearDown(): void
     {
-        cache()->flush();
+        cache()->forget("getLogisticByCode_{$this->data['logistic']}");
+        cache()->forget("getOwnerByCode_{$this->data['owner']}");
+        cache()->forget("getShopByCodeMap_{$this->data['shop']}");
+        cache()->forget("WareHouse_{$this->data['warehouse']}");
+
+        $this->data['warehouse']->delete();
         $this->data['logistic']->delete();
         $this->data['owner']->delete();
         $this->data['shop']->delete();
-        $this->data['warehouse']->delete();
         Order::query()->where('code',$this->data['orderHeader']['orderno'])->delete();
         parent::tearDown(); // TODO: Change the autogenerated stub
     }

+ 34 - 24
tests/Services/OrderService/GetCreateOrderModelByWMSOrderHeadersTest.php

@@ -2,12 +2,18 @@
 
 namespace Tests\Services\OrderService\GetCreateOrderModelByWMSOrderHeadersTest;
 
+use App\Commodity;
 use App\Logistic;
+use App\OracleActAllocationDetails;
+use App\OracleBasCode;
+use App\OracleBasSKU;
+use App\OracleDOCOrderDetail;
 use App\OracleDOCOrderHeader;
 use App\Order;
 use App\Owner;
 use App\Services\common\DataHandlerService;
 use App\Services\LogisticService;
+use App\Services\OracleBasSkuService;
 use App\Services\OracleDOCOrderHeaderService;
 use App\Services\OrderService;
 use App\Services\OwnerService;
@@ -41,6 +47,7 @@ class GetCreateOrderModelByWMSOrderHeadersTest extends TestCase
     public $logisticService;
     public $shopService;
     public $warehouseService;
+    private $data = [];
 
     public function setUp(): void
     {
@@ -52,6 +59,23 @@ class GetCreateOrderModelByWMSOrderHeadersTest extends TestCase
         $this->logisticService=app('LogisticService');
         $this->shopService=app('ShopService');
         $this->warehouseService=app('WarehouseService');
+
+        $wmsOrderHeader = factory(OracleDOCOrderHeader::class)->make([
+            'customerid'=>'TEST_OW','sostatus'=>99,'userdefine1'=>'TEST_CA','warehouseid'=>'WH_TEST'
+        ]);
+        $this->data['warehouse']    = factory(Warehouse::class)->create(['code'=>'WH_TEST']);
+        $this->data['logistic']     = factory(Logistic::class)->create(['code'=>'TEST_CA','name'=>'测试承运商']);
+        $this->data['owner']        = factory(Owner::class)->create(['code'=>'TEST_OW','name'=>'测试货主']);
+        $this->data['shop']         = factory(Shop::class)->create(['owner_id'=>$this->data['owner']['id']]);
+
+        $code_BasCode  = factory(OracleBasCode::class)->make(['codeid'=>'OW','code'=>'99','descr_c'=>'订单完成']);
+        $orderType = factory(OracleBasCode::class)->make(['code'=>'sysy', 'codeid'=>'SO_TYP', 'codename_c'=>'测试状态']);
+
+        $wmsOrderHeader->setRelation('orderType',$orderType);
+        $wmsOrderHeader->setRelation('oracleBASCode',$code_BasCode);
+        $this->data['orderHeader'] = $wmsOrderHeader;
+
+
     }
 
     /**
@@ -60,12 +84,7 @@ class GetCreateOrderModelByWMSOrderHeadersTest extends TestCase
     public function getCreateOrderModelByWMSOrderHeaders()
     {
 
-        $orderHeader = OracleDOCOrderHeader::query()->where('sostatus',99)->orderByDesc('addtime')->first();
-        $orderHeaders = OracleDOCOrderHeader::query()
-            ->where('sostatus',99)
-            ->where('addtime','>=',$orderHeader->addtime)
-            ->get();
-
+        $orderHeaders = collect([$this->data['orderHeader']]);
         $warehouses = $this->getWareHouses($orderHeaders);
         $owners = $this->getOwners($orderHeaders);
         $logistics = $this->getLogistics($orderHeaders);
@@ -105,7 +124,7 @@ class GetCreateOrderModelByWMSOrderHeadersTest extends TestCase
             $this->assertEquals($order->client_code ,$orderHeader->soreference1);
             $this->assertEquals($order->wms_edittime ,(string)$orderHeader->edittime);
             $this->assertEquals($order->wms_status ,$orderHeader->oracleBASCode_codename_c);
-            $this->assertEquals((string)$order->created_at ,(string)$orderHeader->addtime);
+//            $this->assertEquals((string)$order->created_at ,(string)$orderHeader->addtime);
         }
     }
 
@@ -128,24 +147,15 @@ class GetCreateOrderModelByWMSOrderHeadersTest extends TestCase
 
     public function tearDown(): void
     {
+        cache()->forget("getLogisticByCode_{$this->data['logistic']}");
+        cache()->forget("getOwnerByCode_{$this->data['owner']}");
+        cache()->forget("getShopByCodeMap_{$this->data['shop']}");
+        cache()->forget("WareHouse_{$this->data['warehouse']}");
+        $this->data['warehouse']->delte();
+        $this->data['logistic']->delte();
+        $this->data['owner']->delte();
+        $this->data['shop']->delte();
         parent::tearDown(); // TODO: Change the autogenerated stub
     }
 
-    public function getOrderHeader($userdefine1,$warehouse_code,$customerid,$issuepartyname,$orderType){
-        $orderHeader = new OracleDOCOrderHeader();
-        $orderHeader->orderno = '订单编号';
-        $orderHeader->c_contact= '京东旗舰店';
-        $orderHeader->c_tel2 = '承运商';
-        $orderHeader->c_province = '收货人';
-        $orderHeader->c_city = 'shou';
-        $orderHeader->c_district = 'shou';
-        $orderHeader->c_address1 = 'shou';
-        $orderHeader->soreference1 = '客户订单号';
-        $orderHeader->userdefine1 = $userdefine1;
-        $orderHeader->warehouseid = $warehouse_code;
-        $orderHeader->customerid = $customerid;
-        $orderHeader->issuepartyname = $issuepartyname;
-        $orderHeader->setAppends(['orderType'=>['codename_c'=>$orderType]]);
-        return $orderHeader;
-    }
 }

+ 0 - 77
tests/Services/OrderService/GetOrderByLogisticNumberTest.php

@@ -1,77 +0,0 @@
-<?php
-
-namespace Tests\Services\OrderService\GetOrderByLogisticNumberTest;
-
-use App\Logistic;
-use App\OracleDOCOrderHeader;
-use App\Order;
-use App\OrderPackage;
-use App\Owner;
-use App\Services\OrderService;
-use App\Shop;
-use App\Warehouse;
-use Illuminate\Foundation\Testing\RefreshDatabase;
-use Illuminate\Foundation\Testing\WithFaker;
-use Tests\TestCase;
-
-class GetOrderByLogisticNumberTest extends TestCase
-{
-    use RefreshDatabase;
-
-    /** @var OrderService $service */
-    public $service;
-    public function setUp(): void
-    {
-        parent::setUp();
-        $this->service = app('OrderService');
-    }
-
-    public function testGetOrderByLogisticNumber()
-    {
-
-        $orderHeader = OracleDOCOrderHeader::query()
-            ->with('actAllocationDetails')
-            ->where('sostatus',99)
-            ->orderByDesc('AddTime')->first();
-
-        $orderHeaders = collect();
-        $orderHeaders->push($orderHeader);
-        $this->service->syncOrder($orderHeaders);
-        $order_package = OrderPackage::query()->orderByDesc('id')->first();
-
-        $logistic_number = $order_package->logistic_number;
-
-        $order = $this->service->getOrderByLogisticNumber($logistic_number);
-        $this->assertEquals((string)$orderHeader->addtime,(string)$order->created_at);
-        $this->assertEquals($orderHeader->orderno,$order->code);
-
-        $shop = Shop::query()->where('name',$orderHeader->issuepartyname)->first();
-        if($shop)$this->assertEquals($shop->id,$order->shop_id);
-
-        $owner = Owner::query()->where('code',$orderHeader->customerid)->first();
-        if($owner)$this->assertEquals($owner->id, $order->owner_id);
-        $this->assertEquals($orderHeader->soreference1,$order->client_code);
-
-        $logistic = Logistic::query()->where('code',$orderHeader->userdefine1)->first();
-        if($logistic)$this->assertEquals($logistic->id,$order->logistic_id);
-        $this->assertEquals($orderHeader->c_contact,$order->consignee_name);
-
-        $consignee_phone = empty($orderHeader->c_tel2)?$orderHeader->c_tel1:$orderHeader->c_tel2;
-        $this->assertEquals($consignee_phone,$order->consignee_phone);
-
-        $this->assertEquals($orderHeader->c_province,$order->province);
-        $this->assertEquals($orderHeader->c_city,$order->city);
-        $this->assertEquals($orderHeader->c_district,$order->district);
-        $this->assertEquals($orderHeader->c_address1,$order->address);
-        $this->assertEquals($orderHeader->oracleBASCode_codename_c,$order->wms_status);
-
-        $warehouse = Warehouse::query()->where('code',$orderHeader->warehouseid)->first();
-        if($warehouse)$this->assertEquals($warehouse->id,$order->warehouse_id);
-        $this->assertEquals($orderHeader->edittime,$order->wms_edittime);
-    }
-    public function tearDown(): void
-    {
-        cache()->flush();
-        parent::tearDown(); // TODO: Change the autogenerated stub
-    }
-}

+ 0 - 1
tests/Services/OrderService/GetOrderSyncAtTest.php

@@ -42,7 +42,6 @@ class GetOrderSyncAtTest extends TestCase
 
     public function tearDown(): void
     {
-        cache()->flush();
         parent::tearDown(); // TODO: Change the autogenerated stub
     }
 }

+ 47 - 7
tests/Services/OrderService/GetParamByOrderHeaderTest.php

@@ -2,13 +2,21 @@
 
 namespace Tests\Services\OrderService\GetParamByOrderHeaderTest;
 
+use App\Commodity;
+use App\Logistic;
+use App\OracleBasCode;
 use App\OracleDOCOrderHeader;
+use App\Order;
+use App\Owner;
 use App\Services\LogisticService;
+use App\Services\OracleDOCOrderHeaderService;
 use App\Services\OrderIssueService;
 use App\Services\OrderService;
 use App\Services\OwnerService;
 use App\Services\ShopService;
 use App\Services\WarehouseService;
+use App\Shop;
+use App\Warehouse;
 use Illuminate\Foundation\Testing\RefreshDatabase;
 use Illuminate\Foundation\Testing\WithFaker;
 use Tests\TestCase;
@@ -18,11 +26,30 @@ class GetParamByOrderHeaderTest extends TestCase
     use RefreshDatabase;
 
     /** @var OrderService $service */
-    public $service;
+    private $service;
+    private $data = [];
     public function setUp(): void
     {
         parent::setUp();
         $this->service = app(OrderService::class);
+        $wmsOrderHeader = factory(OracleDOCOrderHeader::class)->make([
+            'customerid'=>'TEST_OW','sostatus'=>99,'userdefine1'=>'TEST_CA','warehouseid'=>'WH_TEST'
+        ]);
+
+        $orderType = factory(OracleBasCode::class)->make(['code'=>'sysy', 'codeid'=>'SO_TYP', 'codename_c'=>'测试状态']);
+        $wmsOrderHeader->setRelation('orderType',$orderType);
+
+        $code_BasCode  = factory(OracleBasCode::class)->make(['codeid'=>'OW','code'=>'99','descr_c'=>'订单完成']);
+        $wmsOrderHeader->setRelation('oracleBASCode',$code_BasCode);
+        $this->data['orderHeader'] = $wmsOrderHeader;
+        $this->data['warehouse']    = factory(Warehouse::class)->create(['code'=>'WH_TEST']);
+        $this->data['logistic']     = factory(Logistic::class)->create(['code'=>'TEST_CA','name'=>'测试承运商']);
+        $this->data['owner']        = factory(Owner::class)->create(['code'=>'TEST_OW','name'=>'测试货主']);
+        $this->data['shop']         = factory(Shop::class)->create(['owner_id'=>$this->data['owner']['id']]);
+
+        $this->mock(OracleDOCOrderHeaderService::class,function($mock)use($wmsOrderHeader){
+            $mock->shouldReceive('first')->andReturn($wmsOrderHeader);
+        });
     }
 
     /**
@@ -30,16 +57,13 @@ class GetParamByOrderHeaderTest extends TestCase
      */
     public function testGetParamByOrderHeader()
     {
-        $orderHeader = OracleDOCOrderHeader::query()->where('sostatus',99)->orderByDesc('addtime')->first();
-        $orderHeaders = OracleDOCOrderHeader::query()
-            ->where('sostatus',99)
-            ->where('addtime','>=',$orderHeader->addtime)
-            ->get();
-
+        $orderHeader = $this->data['orderHeader'] ;
+        $orderHeaders = collect([$orderHeader]);
         app(ShopService::class)->getByWmsOrders($orderHeaders);
         app(OwnerService::class)->getByWmsOrders($orderHeaders);
         app(LogisticService::class)->getByWmsOrders($orderHeaders);
         app(WarehouseService::class)->getByWmsOrders($orderHeaders);
+
         $param = $this->service->getParamByOrderHeader($orderHeader);
         $this->assertNotNull($param);
         $this->assertNotEmpty($param['code']);
@@ -58,4 +82,20 @@ class GetParamByOrderHeaderTest extends TestCase
         $this->assertNotEmpty($param['created_at']);
         $this->assertNotEmpty($param['warehouse_id']);
     }
+
+    public function tearDown(): void
+    {
+        cache()->forget("getLogisticByCode_{$this->data['logistic']['code']}");
+        cache()->forget("getOwnerByCode_{$this->data['owner']['code']}");
+        cache()->forget("getShopByCodeMap_{$this->data['shop']['code']}");
+        cache()->forget("WareHouse_{$this->data['warehouse']['code']}");
+
+//        $order = Order::query()->where('code',$this->data['orderHeader']['orderno'])->first();
+//        $order->delete();
+        $this->data['logistic']->delete();
+        $this->data['owner']->delete();
+        $this->data['shop']->delete();
+        $this->data['warehouse']->delete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
 }

+ 21 - 6
tests/Services/OrderService/GetUpdateModelByWmsOrderHeadersTest.php

@@ -3,6 +3,7 @@
 namespace Tests\Services\OrderService\GetUpdateOrderModelByWMSOrderHeadersTest;
 
 use App\Logistic;
+use App\OracleBasCode;
 use App\OracleDOCOrderHeader;
 use App\Order;
 use App\Owner;
@@ -29,12 +30,30 @@ class GetUpdateModelByWmsOrderHeadersTest extends TestCase
      */
     public $service;
     public $orderHeaderService;
+    private $data = [];
 
     public function setUp(): void
     {
         parent::setUp();
         $this->service = app('OrderService');
         $this->orderHeaderService = app('OracleDocOrderHeaderService');
+
+        $wmsOrderHeader = factory(OracleDOCOrderHeader::class)->make([
+            'customerid'=>'TEST_OW','sostatus'=>99,'userdefine1'=>'TEST_CA','warehouseid'=>'WH_TEST'
+        ]);
+
+        $orderType = factory(OracleBasCode::class)->make(['code'=>'sysy', 'codeid'=>'SO_TYP', 'codename_c'=>'测试状态']);
+        $wmsOrderHeader->setRelation('orderType',$orderType);
+
+        $code_BasCode  = factory(OracleBasCode::class)->make(['codeid'=>'OW','code'=>'99','descr_c'=>'订单完成']);
+        $wmsOrderHeader->setRelation('oracleBASCode',$code_BasCode);
+
+        $this->data['warehouse']    = factory(Warehouse::class)->create(['code'=>'WH_TEST']);
+        $this->data['logistic']     = factory(Logistic::class)->create(['code'=>'TEST_CA','name'=>'测试承运商']);
+        $this->data['owner']        = factory(Owner::class)->create(['code'=>'TEST_OW','name'=>'测试货主']);
+        $this->data['shop']         = factory(Shop::class)->create(['owner_id'=>$this->data['owner']['id']]);
+
+        $this->data['orderHeader'] = $wmsOrderHeader;
     }
 
     /**
@@ -43,11 +62,7 @@ class GetUpdateModelByWmsOrderHeadersTest extends TestCase
     public function getUpdateOrderModelByWMSOrderHeaders()
     {
 
-        $orderHeader = OracleDOCOrderHeader::query()->where('sostatus',99)->orderByDesc('addtime')->first();
-        $orderHeaders = OracleDOCOrderHeader::query()
-            ->where('sostatus',99)
-            ->where('addtime','>=',$orderHeader->addtime)
-            ->get();
+        $orderHeaders = collect([$this->data['orderHeader']]);
         /**
          * @var OwnerService $ownerService
          * @var LogisticService $logisticService
@@ -112,7 +127,7 @@ class GetUpdateModelByWmsOrderHeadersTest extends TestCase
             $this->assertEquals($order->client_code ,$orderHeader->soreference1);
             $this->assertEquals($order->wms_edittime ,(string)$orderHeader->edittime);
             $this->assertEquals($order->wms_status ,$orderHeader->oracleBASCode_codename_c);
-            $this->assertEquals((string)$order->created_at ,(string)$orderHeader->addtime);
+//            $this->assertEquals((string)$order->created_at ,(string)$orderHeader->addtime);
         }
     }
 }

+ 0 - 39
tests/Services/OrderService/LogisticNumberFirstOrCreateOrderTest.php

@@ -1,39 +0,0 @@
-<?php
-
-namespace Tests\Services\OrderService\LogisticNumberFirstOrCreateOrderTest;
-
-use App\OracleActAllocationDetails;
-use App\OrderPackage;
-use App\Services\OrderService;
-use Illuminate\Foundation\Testing\RefreshDatabase;
-use Illuminate\Foundation\Testing\WithFaker;
-use Tests\TestCase;
-
-class LogisticNumberFirstOrCreateOrderTest extends TestCase
-{
-    use RefreshDatabase;
-    /** @var OrderService $service */
-    public $service;
-
-    public function setUp(): void
-    {
-        parent::setUp(); // TODO: Change the autogenerated stub
-        $this->service=app(OrderService::class);
-    }
-
-    /**
-     * @test
-     */
-    public function logisticNumberFirstOrCreateOrder()
-    {
-        $logistic_number = OracleActAllocationDetails::query()->orderByDesc('addtime')->whereNotNull('picktotraceid')->first()->picktotraceid;
-        $order = $this->service->logisticNumberFirstOrCreateOrder($logistic_number);
-        $this->assertNotEmpty($order);
-    }
-
-    public function tearDown(): void
-    {
-        cache()->flush();
-        parent::tearDown(); // TODO: Change the autogenerated stub
-    }
-}

+ 13 - 5
tests/Services/OrderService/PushOrderCreatedCacheTest.php

@@ -15,7 +15,7 @@ class PushOrderCreatedCacheTest extends TestCase
     use RefreshDatabase;
     /** @var OrderService $service */
     public $service;
-    public $data;
+    public $data = [];
     public function setUp(): void
     {
         parent::setUp(); // TODO: Change the autogenerated stub
@@ -28,15 +28,18 @@ class PushOrderCreatedCacheTest extends TestCase
             $list[] = $orderHeader;
         }
         $this->data['OrderHeader'] = $list;
+        $this->data['renewal_list'] = 'renewal_list->test';
+        $this->data['hasKey'] = 'renewal_has->test';
+        $this->data['prefixKey'] = 'renewal->test';
     }
     /**
      * @test
      */
     public function pushOrderCreatedCache()
     {
-        $renewal_list   = config('sync.order_sync.cache_prefix.renewal_list');
-        $hasKey         = config('sync.order_sync.cache_prefix.renewal_has');
-        $prefixKey      = config('sync.order_sync.cache_prefix.renewal');
+        $renewal_list   = $this->data['renewal_list'];
+        $hasKey         = $this->data['hasKey'];
+        $prefixKey      = $this->data['prefixKey'];
 
         $this->service->pushOrderCache($this->data['OrderHeader'],$prefixKey,$hasKey,$renewal_list);
         try {
@@ -53,7 +56,12 @@ class PushOrderCreatedCacheTest extends TestCase
 
     public function tearDown(): void
     {
-        cache()->flush();
+
+        foreach ($this->data['OrderHeader'] as $datum) {
+            Cache::forget($this->data['prefixKey'].$datum->orderno);
+        }
+        Cache::forget($this->data['renewal_list']);
+        Cache::forget($this->data['prefixKey']);
         parent::tearDown(); // TODO: Change the autogenerated stub
     }
 }

+ 8 - 4
tests/Services/OrderService/PushOrderUpdateCacheTest.php

@@ -31,9 +31,9 @@ class PushOrderUpdateCacheTest extends TestCase
             $list[] = $orderHeader;
         }
         $this->data['OrderHeader'] = $list;
-        $this->renewal_list   = config('sync.order_sync.cache_prefix.renewal_list');
-        $this->hasKey         = config('sync.order_sync.cache_prefix.renewal_has');
-        $this->prefixKey      = config('sync.order_sync.cache_prefix.renewal');
+        $this->renewal_list   = 'renewal_list->test';
+        $this->hasKey         = 'renewal_has->test';
+        $this->prefixKey      = 'renewal->test';
     }
 
     /**
@@ -57,7 +57,11 @@ class PushOrderUpdateCacheTest extends TestCase
 
     public function tearDown(): void
     {
-        cache()->flush();
+        foreach ($this->data['OrderHeader'] as $datum) {
+            Cache::forget($this->prefixKey.$datum->orderno);
+        }
+        Cache::forget($this->renewal_list);
+        Cache::forget($this->hasKey);
         parent::tearDown(); // TODO: Change the autogenerated stub
     }
 }

+ 16 - 11
tests/Services/OrderService/SetOrderSyncAtTest.php

@@ -16,10 +16,15 @@ class SetOrderSyncAtTest extends TestCase
 
     /** @var OrderService $service */
     private $service;
+    private $data = [];
     public function setUp(): void
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $this->service = app('OrderService');
+        $this->data['key1']= Str::uuid();
+        $this->data['key2']= Str::uuid();
+        $this->data['data1'] = Carbon::now();
+        $this->data['data2'] = Carbon::now();
     }
 
     /**
@@ -29,26 +34,26 @@ class SetOrderSyncAtTest extends TestCase
     {
         /** @var Carbon $time */
 
-        $key= Str::uuid();
-        $data = Carbon::now();
-        ValueStore::query()->create(['name'=>$key]);
 
-        $this->service->setOrderSyncAt($key,$data,true);
-        $item = ValueStore::query()->where('name',$key)->first();
-        $this->assertEquals((string)$data->subSeconds(1),(string)$item->value);
+        ValueStore::query()->create(['name'=>$this->data['key1']]);
+
+        $this->service->setOrderSyncAt($this->data['key1'],$this->data['data1'],true);
+        $item = ValueStore::query()->where('name',$this->data['key1'])->first();
+        $this->assertEquals((string)($this->data['data1']->subSeconds(1)),(string)$item->value);
+
 
-        $key= Str::uuid();
         $data = Carbon::now();
-        ValueStore::query()->create(['name'=>$key]);
+        ValueStore::query()->create(['name'=>$this->data['key2']]);
 
-        $this->service->setOrderSyncAt($key,$data,false);
-        $item = ValueStore::query()->where('name',$key)->first();
+        $this->service->setOrderSyncAt($this->data['key2'],$this->data['data2'],false);
+        $item = ValueStore::query()->where('name',$this->data['key2'])->first();
         $this->assertEquals((string)$data,(string)$item->value);
     }
 
     public function tearDown(): void
     {
-        cache()->flush();
+        ValueStore::query()->where('name',$this->data['key2'])->delete();
+        ValueStore::query()->where('name',$this->data['key1'])->delete();
         parent::tearDown(); // TODO: Change the autogenerated stub
     }
 }

+ 0 - 96
tests/Services/OrderService/SyncOrderByWMSOrderHeaderTest.php

@@ -1,96 +0,0 @@
-<?php
-
-namespace Tests\Services\OrderService\SyncOrderByWMSOrderHeaderTest;
-
-use App\Logistic;
-use App\OracleDOCOrderHeader;
-use App\Order;
-use App\Owner;
-use App\Services\common\DataHandlerService;
-use App\Services\LogisticService;
-use App\Services\OracleDOCOrderHeaderService;
-use App\Services\OrderService;
-use App\Services\OwnerService;
-use App\Services\ShopService;
-use App\Services\WarehouseService;
-use App\Shop;
-use App\Warehouse;
-use Carbon\Carbon;
-use Illuminate\Foundation\Testing\RefreshDatabase;
-use Illuminate\Foundation\Testing\WithFaker;
-use Tests\TestCase;
-
-class SyncOrderByWMSOrderHeaderTest extends TestCase
-{
-    use RefreshDatabase;
-    /**
-     * @var OrderService $service
-     * @var OracleDOCOrderHeaderService $orderHeaderService
-     * @var DataHandlerService $dataHandlerService
-     * @var OwnerService $ownerService
-     * @var LogisticService $logisticService
-     * @var ShopService $shopService
-     * @var WarehouseService $warehouseService
-     */
-    public $service;
-    public $orderHeaderService;
-    public $dataHandlerService;
-    public $ownerService;
-    public $logisticService;
-    public $shopService;
-    public $warehouseService;
-    public function setUp(): void
-    {
-        parent::setUp();
-        $this->service=app(OrderService::class);
-        $this->orderHeaderService=app(OracleDOCOrderHeaderService::class);
-    }
-    public function testCreateOrUpdateOrderByWMSOrderHeaders()
-    {
-        $orderHeader = OracleDOCOrderHeader::query()->where('sostatus',99)->orderByDesc('addtime')->first();
-        $orderHeaders = OracleDOCOrderHeader::query()
-            ->where('sostatus',99)
-            ->where('addtime','>=',$orderHeader->addtime)
-            ->get();
-
-        $this->service->syncOrderByWMSOrderHeaders($orderHeaders);
-        $orders = Order::query()->whereIn('code',data_get($orderHeaders,'*.orderno'))->get();
-        foreach ($orderHeaders as $orderHeader) {
-            $code = $orderHeader->orderno;
-            $order = $orders->where('code',$code)->first();
-            $this->assertNotNull($order);
-
-            $warehouse = Warehouse::query()->where('code',$orderHeader->warehouseid)->first();
-            if($orderHeader->warehouseid ?? false)
-                $this->assertEquals($warehouse->id ?? '',$order->warehouse_id ?? '');
-
-            $owner = Owner::query()->where('code',$orderHeader->customerid)->first();
-            if($orderHeader->customerid ?? false)
-                $this->assertEquals($order->owner_id ?? '',$owner->id??'');
-
-            $logistic = Logistic::query()->where('code',$orderHeader->userdefine1??'')->first();
-            if($orderHeader->userdefine1 ?? false)
-                $this->assertEquals($logistic->id ?? '',$logistic->id ?? '');
-
-            $shop = Shop::query()->where('name',$orderHeader->issuepartyname)->where('owner_id',$owner->id)->first();
-            if($orderHeader->issuepartyname ?? false)
-                $this->assertEquals($shop->name,$orderHeader->issuepartyname);
-
-            $this->assertEquals($order->consignee_name ,$orderHeader->c_contact);
-            $this->assertEquals($order->consignee_phone ,empty($orderHeader->c_tel2)?$orderHeader->c_tel1:$orderHeader->c_tel2);
-            $this->assertEquals($order->province ,$orderHeader->c_province);
-            $this->assertEquals($order->city ,$orderHeader->c_city);
-            $this->assertEquals($order->district ,$orderHeader->c_district);
-            $this->assertEquals($order->client_code ,$orderHeader->soreference1);
-            $this->assertEquals($order->wms_edittime ,(string)$orderHeader->edittime);
-            $this->assertEquals($order->wms_status ,$orderHeader->oracleBASCode_codename_c);
-            $this->assertEquals((string)$order->created_at ,(string)$orderHeader->addtime);
-        }
-    }
-
-    public function tearDown(): void
-    {
-        cache()->flush();
-        parent::tearDown(); // TODO: Change the autogenerated stub
-    }
-}

+ 0 - 59
tests/Services/OrderService/SyncOrderTest.php

@@ -1,59 +0,0 @@
-<?php
-
-namespace Tests\Services\OrderService\SyncOrderTest;
-
-use App\Logistic;
-use App\Owner;
-use App\Services\common\DataHandlerService;
-use App\Services\LogisticService;
-use App\OracleDOCOrderHeader;
-use App\Services\OracleDOCOrderHeaderService;
-use App\Services\OrderService;
-use App\Services\OwnerService;
-use App\Services\ShopService;
-use App\Services\WarehouseService;
-use App\Shop;
-use App\Warehouse;
-use Carbon\Carbon;
-use Illuminate\Foundation\Testing\RefreshDatabase;
-use Illuminate\Foundation\Testing\WithFaker;
-use Tests\TestCase;
-
-class SyncOrderTest extends TestCase
-{
-    use RefreshDatabase;
-
-    /**
-     * @var OrderService $service
-     */
-    public $service;
-
-    public function setUp(): void
-    {
-        parent::setUp();
-        $this->service=app(OrderService::class);
-    }
-
-    /**
-     * @test
-     */
-    public function createOrUpdateOrderInfo()
-    {
-        $orderHeader = OracleDOCOrderHeader::query()->where('sostatus',99)->orderByDesc('addtime')->first();
-        $orderHeaders = OracleDOCOrderHeader::query()
-            ->where('sostatus',99)
-            ->where('addtime','>=',$orderHeader->addtime)
-            ->get();
-        $this->service->syncOrder($orderHeaders);
-        $orders = $this->service->getByWmsOrders($orderHeaders);
-        $this->assertNotNull($orders);
-        $this->assertNotNull($orderHeader);
-        $this->assertEquals(count($orderHeaders),count($orders));
-    }
-
-    public function tearDown(): void
-    {
-        cache()->flush();
-        parent::tearDown(); // TODO: Change the autogenerated stub
-    }
-}

+ 74 - 0
tests/Services/OwnerService/GetOwnerByCodeTest.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace Tests\Services\OwnerService;
+
+use App\OracleBasCustomer;
+use App\Owner;
+use App\Services\OwnerService;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Illuminate\Foundation\Testing\WithFaker;
+use Tests\TestCase;
+
+class GetOwnerByCodeTest extends TestCase
+{
+    use RefreshDatabase;
+
+    /** @var OwnerService $service */
+    private $service;
+    private $data = [];
+
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        cache()->flush();
+        $this->service = app('OwnerService');
+
+        $owner  = factory(Owner::class)->create();
+        $basCustomer = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>$owner->code]);
+
+        $this->data['basCustomer'] = $basCustomer;
+        $this->data['owner'] = $owner;
+
+        $this->mock('OracleBasCustomerService',function ($mock)use($basCustomer){
+            $mock->shouldReceive('first')->andReturn($basCustomer);
+        });
+    }
+
+    /**
+     * @test
+     */
+    public function getOwnerByCode()
+    {
+        $owner = $this->service->getOwnerByCode($this->data['owner']['code']);
+
+        $this->assertEquals($owner->id,$this->data['owner']['id']);
+        $this->assertEquals($owner->name,$this->data['owner']['name']);
+        $this->assertEquals($owner->code,$this->data['owner']['code']);
+
+    }
+
+    /**
+     * @test
+     */
+    public function ownerIsNotExist()
+    {
+        $this->data['owner']->delete();
+        cache()->forget('getOwnerByCode_'.$this->data['owner']['code']);
+
+        $owner = $this->service->getOwnerByCode($this->data['owner']['code']);
+
+        $this->data['owner'] = $owner;
+        $this->assertEquals($owner->id,$this->data['owner']['id']);
+        $this->assertEquals($owner->code,$this->data['owner']['code']);
+        $this->assertEquals($owner->name,$this->data['owner']['name']);
+
+        $this->data['owner']= $owner;
+    }
+
+    public function tearDown(): void
+    {
+        cache()->forget('getOwnerByCode_'.$this->data['owner']['code']);
+        $this->data['owner']->delete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 55 - 15
tests/Services/OwnerService/GetOwnerByCodesTest.php

@@ -3,6 +3,7 @@
 namespace Tests\Services\OwnerService;
 
 use App\OracleBasCustomer;
+use App\Owner;
 use App\Services\OwnerService;
 use Illuminate\Foundation\Testing\RefreshDatabase;
 use Illuminate\Foundation\Testing\WithFaker;
@@ -20,32 +21,71 @@ class GetOwnerByCodesTest extends TestCase
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $this->service = app('OwnerService');
-        $basCustomers = OracleBasCustomer::query()->selectRaw('customerid')->where('Customer_Type','OW')->get();
-        $this->data = $basCustomers->map(function($basCustomer){
-            return $basCustomer->customerid;
+
+        $owner1 = factory(Owner::class)->create(['code'=>'AABBCC1']);
+        $owner2 = factory(Owner::class)->create(['code'=>'AABBCC2']);
+        $owner3 = factory(Owner::class)->create(['code'=>'AABBCC3']);
+
+        $this->data['owner'] = [$owner1,$owner2,$owner3];
+        $this->service = app('OwnerService');
+
+        $basCustomer1 = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>'AABBCC1']);
+        $basCustomer2 = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>'AABBCC2']);
+        $basCustomer3 = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>'AABBCC3']);
+        $basCustomers = collect([$basCustomer1,$basCustomer2,$basCustomer3]);
+
+        $this->mock('OracleBasCustomerService',function ($mock)use($basCustomers,$owner1, $owner2, $owner3){
+            $mock->shouldReceive('first')->with(["Customer_Type"=>'OW',"CustomerID"=>$owner1->code])->andReturn($basCustomers->where('customerid',$owner1->code)->first());
+            $mock->shouldReceive('first')->with(["Customer_Type"=>'OW',"CustomerID"=>$owner2->code])->andReturn($basCustomers->where('customerid',$owner2->code)->first());
+            $mock->shouldReceive('first')->with(["Customer_Type"=>'OW',"CustomerID"=>$owner3->code])->andReturn($basCustomers->where('customerid',$owner3->code)->first());
         });
     }
 
     /**
      * @test
      */
-    public function getOwnerByCodesNormal(){
-        $owners = $this->service->getOwnerByCodes($this->data);
-        if(empty($owners)){
-            $this->assertEmpty($owners);
-            $this->assertEmpty($this->data);
-            return;
-        };
-        $this->assertEquals($owners->count(),$this->data->count());
-        foreach ($this->data as $datum) {
-            $owner = $owners->where('code',$datum);
-            $this->assertNotNull($owner);
+    public function getOwnerByCodesNormal()
+    {
+        $owners = $this->service->getOwnerByCodes(data_get($this->data['owner'],'*.code'));
+        $this->assertNotNull($owners);
+        $this->assertNotEquals(count($owners),0);
+        $this->assertNotEquals(count($owners),1);
+        $this->assertEquals(count($owners),count($this->data['owner']));
+        foreach ($this->data['owner'] as $item) {
+            $owner = $owners->where('code',$item['code'])->first();
+            $this->assertEquals($owner->id,$item['id']);
+            $this->assertEquals($owner->name,$item['name']);
+            $this->assertEquals($owner->code,$item['code']);
+        }
+    }
+
+    /**
+     * @test
+     */
+    public function ownerIsNotExist()
+    {
+        foreach ($this->data['owner'] as $owner)
+            $owner->delete();
+        $owners = $this->service->getOwnerByCodes(data_get($this->data['owner'],'*.code'));
+        $this->assertNotNull($owners);
+        $this->assertNotEquals(count($owners),0);
+        $this->assertNotEquals(count($owners),1);
+        $this->assertEquals(count($owners),count($this->data['owner']));
+
+        foreach ($this->data['owner'] as $item) {
+            $owner = $owners->where('code',$item['code'])->first();
+            $this->assertEquals($owner->code,$item['code']);
         }
+
+        $this->data['owner'] = $owners;
     }
 
     public function tearDown(): void
     {
-        cache()->flush();
+        foreach ($this->data['owner'] as $owner) {
+            cache()->forget("getOwnerByCode_{$owner['code']}");
+            $owner->delete();
+        }
         parent::tearDown(); // TODO: Change the autogenerated stub
     }
 }

+ 0 - 39
tests/Services/WarehouseService/GetByWmsOrderTest.php

@@ -1,39 +0,0 @@
-<?php
-
-namespace Tests\Services\WarehouseService\GetByWmsOrdersTest;
-
-use App\OracleBasCustomer;
-use App\OracleDOCOrderHeader;
-use App\Services\WarehouseService;
-use App\Warehouse;
-use Carbon\Carbon;
-use Illuminate\Foundation\Testing\RefreshDatabase;
-use Tests\TestCase;
-
-class GetByWmsOrderTest extends TestCase
-{
-    use RefreshDatabase;
-
-    /** @var WarehouseService $service */
-    public $service;
-    public $data = [];
-
-    public function setUp(): void
-    {
-        parent::setUp();
-        $this->service = app(WarehouseService::class);
-        $basCustomers = OracleBasCustomer::query()->selectRaw('Customer_Type,CustomerId,Descr_C')->where('Customer_Type','WH')->get();
-        Warehouse::query()->whereNull('id')->delete();
-        foreach ($basCustomers as $basCustomer) {
-            $this->data['data'][]['warehouseid'] =  $basCustomer->customerid;
-        }
-    }
-
-    public function testGetByWmsOrder()
-    {
-        $warehouses =  $this->service->getByWmsOrders($this->data['data']);
-        $warehouse_ids = data_get($this->data['data'],'*.warehouseid');
-        $warehouse_s = Warehouse::query()->whereIn('code',$warehouse_ids)->get();
-        $this->assertEquals($warehouses->count(),$warehouse_s->count());
-    }
-}

+ 24 - 17
tests/Services/WarehouseService/GetWareHouseByCodeTest.php

@@ -3,11 +3,10 @@
 namespace Tests\Services\WarehouseService;
 
 use App\OracleBasCustomer;
-use App\Services\OwnerService;
+use App\Services\OracleBasCustomerService;
 use App\Services\WarehouseService;
 use App\Warehouse;
 use Illuminate\Foundation\Testing\RefreshDatabase;
-use Illuminate\Foundation\Testing\WithFaker;
 use Tests\TestCase;
 
 class GetWareHouseByCodeTest extends TestCase
@@ -22,10 +21,13 @@ class GetWareHouseByCodeTest extends TestCase
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $this->service = app('WarehouseService');
-        $basCustomers = OracleBasCustomer::query()->selectRaw('CustomerId,Descr_C')->where('Customer_Type','WH')->get();
-        $this->data['basCustomers'] = $basCustomers;
-        $this->data['codes'] = $basCustomers->map(function ($basCustomer){
-            return $basCustomer->customerid;
+        $warehouse = factory(Warehouse::class)->create();
+        $basCustomer = factory(OracleBasCustomer::class)->make(['customerid'=>$warehouse->code,'descr_c'=>$warehouse->name,'customer_type'=>'OW']);
+        $this->data['warehouse'] = $warehouse;
+        $this->data['code'] = $warehouse->code;
+        $this->data['basCustomer'] = $basCustomer;
+        $this->mock(OracleBasCustomerService::class,function($mock)use($basCustomer){
+            $mock->shouldReceive('first')->andReturn($basCustomer);
         });
     }
 
@@ -34,21 +36,26 @@ class GetWareHouseByCodeTest extends TestCase
      */
     public function getWareHouseByCodeTest()
     {
-        $wareHouses =  $this->service->getWareHouseByCode($this->data['codes']);
-        $this->assertNotEmpty($wareHouses);
-        foreach ($wareHouses as $wareHouse) {
-            $basCustomer = $this->data['basCustomers']->where('customerid',$wareHouse->code)->where('descr_c',$wareHouse->name);
-            $this->assertNotEmpty($basCustomer);
-        }
-        foreach ($this->data['basCustomers'] as $basCustomer) {
-            $wareHouse = $wareHouses->where('name',$basCustomer['descr_c'])->where('code',$basCustomer['customerid']);
-            $this->assertNotEmpty($wareHouse);
-        }
+        $warehouse = $this->service->getWareHouseByCode($this->data['code']);
+        $this->assertEquals($warehouse->toArray(),$this->data['warehouse']->toArray());
+    }
+
+    /**
+     * @test
+     */
+    public function warehouseIsNotExist(){
+        $this->data['warehouse']->delete();
+        cache()->forget('WareHouse_'.$this->data['warehouse']->code);
+        $warehouse = $this->service->getWareHouseByCode($this->data['code']);
+        $this->data['warehouse'] = $warehouse;
+        $this->assertEquals($warehouse['name'],$this->data['basCustomer']['descr_c']);
+        $this->assertEquals($warehouse['code'],$this->data['basCustomer']['customerid']);
     }
 
     public function tearDown(): void
     {
-        cache()->flush();
+        $this->data['warehouse']->delete();
+        cache()->forget('WareHouse_'.$this->data['warehouse']->code);
         parent::tearDown(); // TODO: Change the autogenerated stub
     }
 }

+ 64 - 0
tests/Services/WarehouseService/GetWareHouseByCodesTest.php

@@ -0,0 +1,64 @@
+<?php
+
+
+namespace Tests\Services\WarehouseService;
+
+
+use App\OracleBasCustomer;
+use App\Services\OracleBasCustomerService;
+use App\Services\WarehouseService;
+use App\Warehouse;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Tests\TestCase;
+
+class GetWareHouseByCodesTest extends TestCase
+{
+    use RefreshDatabase;
+    /** @var WarehouseService $service */
+    private $service;
+    private $data = [];
+
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->service = app('WarehouseService');
+        $warehouse1 = factory(Warehouse::class)->create();
+        $warehouse2 = factory(Warehouse::class)->create();
+        $basCustomer1 = factory(OracleBasCustomer::class)->make(['customerid'=>$warehouse1->code,'descr_c'=>$warehouse1->name,'customer_type'=>'OW']);
+        $basCustomer2 = factory(OracleBasCustomer::class)->make(['customerid'=>$warehouse2->code,'descr_c'=>$warehouse2->name,'customer_type'=>'OW']);
+        $basCustomers = collect([$basCustomer1,$basCustomer2]);
+        $this->data['warehouses'] = collect([$warehouse1,$warehouse2]);
+        $this->data['basCustomers'] = $basCustomers;
+        $this->data['codes']  = [$warehouse1->code,$warehouse2->code];
+        $this->mock(OracleBasCustomerService::class,function($mock)use($basCustomers){
+            foreach ( $basCustomers as $basCustomer) {
+                $mock->shouldReceive('first')->with(['CustomerId'=>$basCustomer['customerid'],'Customer_Type'=>'WH'])->andReturn($basCustomer);
+            }
+        });
+    }
+
+    /**
+     * @test
+     */
+    public function getWareHouseCodes()
+    {
+        $wareHouses = $this->service->getWareHouseByCodes($this->data['codes']);
+        foreach ($this->data['basCustomers'] as $datum) {
+            $wareHouse = $wareHouses->where('code',$datum['customerid'])->first();
+            $this->assertNotNull($wareHouse);
+            $this->assertEquals($wareHouse->name,$datum['descr_c']);
+            $this->assertEquals($wareHouse->code,$datum['customerid']);
+        }
+    }
+
+    public function tearDown(): void
+    {
+        foreach ($this->data['warehouses'] as $datum) {
+            $datum->delete();
+            cache()->forget("WareHouse_{$datum['code']}");
+        }
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+
+
+}

+ 0 - 32
tests/Services/WarehouseService/SyncWmsWareHouseTest.php

@@ -1,32 +0,0 @@
-<?php
-
-namespace Tests\Services\WarehouseService\SyncWmsWareHouseTest;
-
-use App\OracleDOCOrderHeader;
-use App\Services\WarehouseService;
-use Carbon\Carbon;
-use Illuminate\Foundation\Testing\RefreshDatabase;
-use Illuminate\Foundation\Testing\WithFaker;
-use Tests\TestCase;
-
-class SyncWmsWareHouseTest extends TestCase
-{
-    /** @var WarehouseService $service */
-    public $service;
-
-
-    public function setUp(): void
-    {
-        $this->service = app(WarehouseService::class);
-        parent::setUp();
-    }
-
-    public function testSyncWmsWareHouse()
-    {
-        $carbon = Carbon::now()->subMinutes(10);
-        $orders = OracleDOCOrderHeader::query()->where('addtime',">=",$carbon)->get();
-        $warehouse_ids = data_get($orders,'*.warehouseid');
-        $collet = $this->service->syncWmsWareHouse($warehouse_ids);
-
-    }
-}

+ 0 - 0
tests/webApi/sortingHaochuangProcess.http → tests/webApi/thirdPart/haochuang/process.http


+ 4 - 0
tests/webApi/thirdPart/haochuang/scanCommodity.http

@@ -0,0 +1,4 @@
+POST http://bswas/api/thirdPart/haochuang/sorting/scanCommodity
+Content-Type: application/json
+
+{"barcode":"W201023000096k"}