Forráskód Böngészése

统计修改完成 待浏览器测试

ANG YU 5 éve
szülő
commit
e9336f83dd

+ 35 - 5
app/Http/Controllers/ControlPanelController.php

@@ -4,11 +4,15 @@ namespace App\Http\Controllers;
 
 use App\Services\CheckActiveMenuService;
 use App\Services\LaborReportsCountingRecordService;
+use App\Services\NewOrderCountingRecordService;
 use App\Services\OrderCountingRecordService;
 use App\Services\RealtimePendingOrdersService;
+use App\Services\UserService;
+use App\User;
 use Carbon\Carbon;
 use DebugBar\DataFormatter\DataFormatter;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Cache;
 
 class ControlPanelController extends Controller
 {
@@ -24,20 +28,27 @@ class ControlPanelController extends Controller
 
     public function index()
     {
+        /**
+         * @var $orderCountingRecordService  NewOrderCountingRecordService
+         * @var $laborReportsCountingRecordService LaborReportsCountingRecordService
+         */
         $checkActiveMenuService = app(CheckActiveMenuService::class);
         $menus = $checkActiveMenuService->activeMenus();
         $realtimePendingOrdersService = app(RealtimePendingOrdersService::class);
         $warehousesOrders = $realtimePendingOrdersService->warehousesOrders();
-        $orderCountingRecordService = app(OrderCountingRecordService::class);
+        $orderCountingRecordService = app(NewOrderCountingRecordService::class);
         //默认查询一个月的数据
         $start = (new Carbon())->subMonth()->addDay()->toDateString();
         $end = (new Carbon())->toDateString();
-        $orderCountingRecords = $orderCountingRecordService->orderCountingRecords($start, $end);
-        $logisticsCountingRecords = $orderCountingRecordService->logisticsCountingRecords($start, $end);
-        $warehouseCountingRecords = $orderCountingRecordService->warehouseCountingRecords($start, $end);
+        $ownerIds = $this->getCountingOwnerIds(null);
+
+        $unit = '日';
+        $orderCountingRecords = $orderCountingRecordService->orderCountingRecords($start, $end, $unit, $ownerIds);
+        $logisticsCountingRecords = $orderCountingRecordService->logisticsCountingRecords($start, $end, $ownerIds);
+        $warehouseCountingRecords = $orderCountingRecordService->warehouseCountingRecords($start, $end, $ownerIds);
 
         $laborReportsCountingRecordService = app(LaborReportsCountingRecordService::class);
-        $laborReportsCountingRecords = $laborReportsCountingRecordService->get($start, $end, '日');
+        $laborReportsCountingRecords = $laborReportsCountingRecordService->get($start, $end, $unit);
         $laborReportsUserGroupsCount = $laborReportsCountingRecordService->userGroupsCount($start, $end);
         return view('control.panel', compact('menus', 'warehousesOrders', 'orderCountingRecords', 'logisticsCountingRecords', 'warehouseCountingRecords', 'laborReportsCountingRecords', 'laborReportsUserGroupsCount'));
     }
@@ -87,4 +98,23 @@ class ControlPanelController extends Controller
         $laborReportsUserGroupsCount = $laborReportsCountingRecordService->userGroupsCount($start, $end);
         return compact('laborReportsUserGroupsCount');
     }
+
+
+    public function getCountingOwnerIds($ownerIds)
+    {
+
+        $user = auth()->user();
+        /** @var UserService $userService */
+        $userService = app('UserService');
+        $permittingOwnerIds = $userService->getPermittingOwnerIds($user);
+        if (!$ownerIds) {
+            return $permittingOwnerIds;
+        }
+        return Cache::remember(
+            'PermittingOwnerIds' . '_' . auth()->user()->id . '_' . implode('_', $ownerIds),
+            600, function () use ($ownerIds, $permittingOwnerIds) {
+            /** @var User $user */
+            return array_intersect($ownerIds, $permittingOwnerIds);
+        });
+    }
 }

+ 7 - 0
app/Providers/AppServiceProvider.php

@@ -17,6 +17,7 @@ use App\Services\InventoryAccountMissionService;
 use App\Services\InventoryCompareService;
 use App\Services\LaborReportsCountingRecordService;
 use App\Services\LogService;
+use App\Services\NewOrderCountingRecordService;
 use App\Services\OracleBasCustomerService;
 use App\Services\OracleBasSkuService;
 use App\Services\OracleDocAsnDetailService;
@@ -171,6 +172,7 @@ class AppServiceProvider extends ServiceProvider
         $this->loadingCheckActiveMenuService();
         $this->loadingRealtimePendingOrdersService();
         $this->loadingOrderCountingRecordService();
+        $this->loadingNewOrderCountingRecordService();
         $this->loadingLaborReportsCountingRecordService();
     }
 
@@ -219,6 +221,11 @@ class AppServiceProvider extends ServiceProvider
     {
         app()->singleton('OrderCountingRecordService',OrderCountingRecordService::class);
     }
+
+    private function loadingNewOrderCountingRecordService()
+    {
+        app()->singleton('NewOrderCountingRecordService',NewOrderCountingRecordService::class);
+    }
     private function loadingLaborReportsCountingRecordService()
     {
         app()->singleton('LaborReportsCountingRecordService',LaborReportsCountingRecordService::class);

+ 104 - 28
app/Services/NewOrderCountingRecordService.php

@@ -4,11 +4,11 @@
 namespace App\Services;
 
 
+use App\Logistic;
 use App\Order;
 use App\OrderCountingRecord;
-use App\User;
+use App\Warehouse;
 use Carbon\Carbon;
-use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Cache;
 
 class NewOrderCountingRecordService
@@ -16,12 +16,100 @@ class NewOrderCountingRecordService
     public function orderCountingRecords($start, $end, $unit, $ownerIds)
     {
         $key = 'orderCountingRecords_' . $start . '_' . $end . '_' . $unit . '_' . json_encode($ownerIds);
-        $queryCondition = $this->transfersToCondition($start, $end, $unit, $ownerIds);
-        return cache()->remember($key, 600, function () use ($queryCondition) {
-            return $this->getOrderCountingRecords($queryCondition);
+        return Cache::remember($key, 60, function () use ($start, $end, $unit, $ownerIds) {
+            $orders = $this->get($start, $end, $unit, $ownerIds);
+            $dataList = collect();
+            $orders->groupBy('date_target')->each(function ($items) use (&$dataList, $unit) {
+                $counter = $items->reduce(function ($sum, $item) {
+                    return $sum + $item->amount;
+                }, 0);
+                $date_target = $items[0]->date_target;
+                $dataList->push([
+                    'counter' => $counter,
+                    'date_target' => $date_target,
+                ]);
+            });
+            return $dataList->sortBy("date_target");
+        });
+    }
+
+    public function logisticsCountingRecords($start, $end, $ownerIds)
+    {
+        $key = 'logisticsCountingRecords_' . $start . '_' . $end . '_' . json_encode($ownerIds);
+        return Cache::remember($key, 600, function () use ($start, $end, $ownerIds) {
+            $dataList = collect();
+            $resultOrders = $this->get($start, $end, '日', $ownerIds);
+            $resultOrders->groupBy('logistic_id')->each(function ($item) use (&$dataList) {
+                $counter = $item->reduce(function ($sum, $item) {
+                    return $sum + $item->amount;
+                }, 0);
+                $dataList->push([
+                    'value' => $counter,
+                    'logistic_id' => $item[0]->logistic_id,
+                ]);
+            });
+            $map = [];
+            $logistics = Logistic::query()->whereIn('id', data_get($dataList, '*.logistic_id'))->get();
+            $logistics->each(function ($logistic) use (&$map) {
+                $map[$logistic->id] = $logistic;
+            });
+            return $dataList->map(function (&$item) use ($map) {
+                $logistic = $map[$item['logistic_id']] ?? '';
+                $item['name'] = $logistic->name ?? '';
+                return $item;
+            });
         });
     }
 
+    public function warehouseCountingRecords($start, $end, $ownerIds)
+    {
+        $key = 'warehouseCountingRecords_' . $start . '_' . $end . '_' . json_encode($ownerIds);
+        return Cache::remember($key, 600, function () use ($start, $end, $ownerIds) {
+            $dataList = collect();
+            $resultOrders = $this->get($start, $end, '日', $ownerIds);
+            $resultOrders->groupBy('warehouse_id')->each(function ($item) use (&$dataList) {
+                $counter = $item->reduce(function ($sum, $item) {
+                    return $sum + $item->amount;
+                }, 0);
+                $dataList->push([
+                    'value' => $counter,
+                    'warehouse_id' => $item[0]->warehouse_id,
+                ]);
+            });
+            $map = [];
+            $logistics = Warehouse::query()->whereIn('id', data_get($dataList, '*.warehouse_id'))->get();
+            $logistics->each(function ($warehouse) use (&$map) {
+                $map[$warehouse->id] = $warehouse;
+            });
+            return $dataList->map(function (&$item) use ($map) {
+                $warehouse = $map[$item['warehouse_id']] ?? '';
+                $item['code'] = $warehouse->name ?? '';
+                switch ($item['code']) {
+                    case 'WH01':
+                        $item['name'] = '松江一仓';
+                        break;
+                    case 'WH02':
+                        $item['name'] = '松江二仓';
+                        break;
+                    case 'WH03':
+                        $item['name'] = '嘉定一仓';
+                        break;
+                    default:
+                        $item['name'] = '仓库为空';
+                        break;
+                }
+                return $item;
+            });
+        });
+    }
+
+
+    public function get($start, $end, $unit, $ownerIds)
+    {
+        $queryCondition = $this->transfersToCondition($start, $end, $unit, $ownerIds);
+        return $this->getOrderCountingRecords($queryCondition);
+    }
+
     public function getFromCache($queryCondition)
     {
         $lackingCondition = [];
@@ -78,10 +166,8 @@ class NewOrderCountingRecordService
         if (empty($lackingCondition['data'])) {
             return $orderCountingRecords_fromCache->concat($orderCountingRecords_fromSelfTable);
         }
-        if ($queryCondition['unit'] != '日') {
-            list($orderCountingRecords_combinedByLower, $lackingCondition)
-                = $this->getByLowerUnit($lackingCondition);
-        }
+        list($orderCountingRecords_combinedByLower, $lackingCondition)
+            = $this->getByLowerUnit($lackingCondition);
 
         if (!empty($lackingCondition)) {
             $orderCountingRecords_FromOrder = $this->dataFromOrder($lackingCondition);
@@ -97,13 +183,11 @@ class NewOrderCountingRecordService
     {
         switch ($queryCondition['unit']) {
             case '年':
-                break;
-            case '月':
-                $lowUnit = '周';
+                $lowUnit = '月';
                 $conditionClone = ['unit' => $lowUnit, 'data' => []];
                 foreach ($queryCondition['data'] as $date => $ownerIds) {
                     $startAt = $date;
-                    $endAt = Carbon::parse($date)->endOfMonth()->toDateString();
+                    $endAt = Carbon::parse($date)->endOfYear()->toDateString();
                     $items = $this->transfersToCondition(
                         $startAt, $endAt, $lowUnit, $ownerIds
                     )['data'];
@@ -113,14 +197,14 @@ class NewOrderCountingRecordService
                     }
                 }
                 $orderCountingRecords_days = $this->getOrderCountingRecords($conditionClone);
-                $orderCountingRecords_combinedByLower = $this->turnGradingUpToLow($orderCountingRecords_days, $lowUnit, 'month');
+                $orderCountingRecords_combinedByLower = $this->turnGradingUpToLow($orderCountingRecords_days, $lowUnit, 'year');
                 break;
-            case '':
+            case '':
                 $lowUnit = '日';
                 $conditionClone = ['unit' => $lowUnit, 'data' => []];
                 foreach ($queryCondition['data'] as $date => $ownerIds) {
                     $startAt = $date;
-                    $endAt = Carbon::parse($date)->endOfWeek()->toDateString();
+                    $endAt = Carbon::parse($date)->endOfMonth()->toDateString();
                     $items = $this->transfersToCondition(
                         $startAt, $endAt, $lowUnit, $ownerIds
                     )['data'];
@@ -130,7 +214,7 @@ class NewOrderCountingRecordService
                     }
                 }
                 $orderCountingRecords_days = $this->getOrderCountingRecords($conditionClone);
-                $orderCountingRecords_combinedByLower = $this->turnGradingUpToLow($orderCountingRecords_days, $lowUnit, 'week');
+                $orderCountingRecords_combinedByLower = $this->turnGradingUpToLow($orderCountingRecords_days, $lowUnit, 'month');
                 break;
             case '日':
                 return [[], $queryCondition];
@@ -159,12 +243,6 @@ class NewOrderCountingRecordService
                         return $date->firstOfMonth();
                     });
                 break;
-            case '周':
-                $dates = collect($startAt->weeksUntil($end, 1)->toArray())
-                    ->map(function (Carbon $date) {
-                        return $date->startOfWeek();
-                    });
-                break;
             case '日':
                 $dates = collect($startAt->daysUntil($end, 1)->toArray())
                     ->map(function (Carbon $date) {
@@ -226,7 +304,6 @@ class NewOrderCountingRecordService
     public function isNotCurrentDate($dateStr): bool
     {
         return $dateStr != Carbon::now()->format('Y-m-d')
-            && $dateStr != Carbon::now()->year . '-' . Carbon::now()->week
             && $dateStr != Carbon::now()->year . '-' . Carbon::now()->month;
     }
 
@@ -246,6 +323,9 @@ class NewOrderCountingRecordService
                     unset($unQueryCondition['data'][$dateStr][$key]);
                 }
             }
+            if (empty($unQueryCondition['data'][$dateStr])) {
+                unset($unQueryCondition['data'][$dateStr]);
+            }
         }
         return $unQueryCondition;
     }
@@ -299,16 +379,12 @@ class NewOrderCountingRecordService
         if ($isEnd) {
             switch ($unit) {
                 case "日":
-                    $item['date_target'] = Carbon::parse($item['date_target'])->startOfWeek()->toDateString();
-                    break;
-                case "周":
                     $item['date_target'] = Carbon::parse($item['date_target'])->firstOfMonth()->toDateString();
                     break;
                 case "月":
                     $item['date_target'] = Carbon::parse($item['date_target'])->firstOfYear()->toDateString();
                     break;
             }
-
             $item['amount'] = $amount;
             $item['counting_unit'] = $unit;
             return $result->push($item);

+ 61 - 69
tests/Services/NewOrderCountingRecordService/GetOrderCountingRecordsTest.php

@@ -27,7 +27,7 @@ class GetOrderCountingRecordsTest extends TestCase
     protected $cache_key = 'order_counting_records_';
     protected $step_length = 1;
     protected $orderCountingRecordIds = [];
-    protected $units = ['日', '周', '月', '年'];
+    protected $units = ['日', '月', '年'];
     protected $orderIds;
 
 
@@ -54,63 +54,56 @@ class GetOrderCountingRecordsTest extends TestCase
     }
 
 
-    /**
-     * @test
-     */
-    public function get_all_from_cache()
-    {
-        for ($i = 0; $i <= $this->step_length; $i++) {
-            foreach ($this->ownerIds as $ownerId) {
-                foreach ($this->units as $unit) {
-                    switch ($unit) {
-                        case "日":
-                            $dateStr = Carbon::now()->subDays($i)->toDateString();
-                            break;
-                        case "周":
-                            $dateStr = Carbon::now()->subWeeks($i)->toDateString();
-                            break;
-                        case "月":
-                            $dateStr = Carbon::now()->subMonths($i)->toDateString();
-                            break;
-                        default:
-                            break;
-                    }
-                    if ($dateStr) {
-                        $orderCountingRecord = factory(OrderCountingRecord::class)->create([
-                            'date_target' => $dateStr,
-                            'owner_id' => $ownerId,
-                            'counting_unit' => $unit,
-                        ]);
-                        $key = 'order_counting_records_' . $dateStr . '_' . $ownerId . '_' . $unit;
-                        cache()->put($key, collect()->push($orderCountingRecord));
-                        if (empty($this->orderCountingRecordIds[$unit])) $this->orderCountingRecordIds[$unit] = [];
-                        $this->orderCountingRecordIds[$unit][] = $orderCountingRecord->id;
-                        $dateStr = null;
-                    }
-                }
-            }
-        }
-        $resultDay = $this->newOrderCountingRecordService->getOrderCountingRecords($this->queryConditionDay);
-        $resultWeek = $this->newOrderCountingRecordService->getOrderCountingRecords($this->queryConditionWeek);
-//        $resultMonth = $this->newOrderCountingRecordService->getOrderCountingRecords($this->queryConditionMonth);
-        foreach ($this->units as $unit) {
-            if (!empty($this->orderCountingRecordIds[$unit])) {
-                switch ($unit) {
-                    case "日":
-                        $this->assertEquals($this->orderCountingRecordIds[$unit], array_column($resultDay->sortBy('id')->toArray(), 'id'));
-                        break;
-                    case "周":
-                        $this->assertEquals($this->orderCountingRecordIds[$unit], array_column($resultWeek->sortBy('id')->toArray(), 'id'));
-                        break;
-                    case "月":
-//                        $this->assertEquals($this->orderCountingRecordIds[$unit], array_column($resultMonth->sortBy('id')->toArray(), 'id'));
-                        break;
-                }
-            }
-        }
-
-    }
-
+//    /**
+//     * @test
+//     */
+//    public function get_all_from_cache()
+//    {
+//        for ($i = 0; $i <= $this->step_length; $i++) {
+//            foreach ($this->ownerIds as $ownerId) {
+//                foreach ($this->units as $unit) {
+//                    switch ($unit) {
+//                        case "日":
+//                            $dateStr = Carbon::now()->subDays($i)->toDateString();
+//                            break;
+//                        case "月":
+//                            $dateStr = Carbon::now()->subMonths($i)->toDateString();
+//                            break;
+//                        default:
+//                            break;
+//                    }
+//                    if ($dateStr) {
+//                        $orderCountingRecord = factory(OrderCountingRecord::class)->create([
+//                            'date_target' => $dateStr,
+//                            'owner_id' => $ownerId,
+//                            'counting_unit' => $unit,
+//                        ]);
+//                        $key = 'order_counting_records_' . $dateStr . '_' . $ownerId . '_' . $unit;
+//                        cache()->put($key, collect()->push($orderCountingRecord));
+//                        if (empty($this->orderCountingRecordIds[$unit])) $this->orderCountingRecordIds[$unit] = [];
+//                        $this->orderCountingRecordIds[$unit][] = $orderCountingRecord->id;
+//                        $dateStr = null;
+//                    }
+//                }
+//            }
+//        }
+//        $resultDay = $this->newOrderCountingRecordService->getOrderCountingRecords($this->queryConditionDay);
+//        $resultWeek = $this->newOrderCountingRecordService->getOrderCountingRecords($this->queryConditionWeek);
+////        $resultMonth = $this->newOrderCountingRecordService->getOrderCountingRecords($this->queryConditionMonth);
+//        foreach ($this->units as $unit) {
+//            if (!empty($this->orderCountingRecordIds[$unit])) {
+//                switch ($unit) {
+//                    case "日":
+//                        $this->assertEquals($this->orderCountingRecordIds[$unit], array_column($resultDay->sortBy('id')->toArray(), 'id'));
+//                        break;
+//                    case "月":
+////                        $this->assertEquals($this->orderCountingRecordIds[$unit], array_column($resultMonth->sortBy('id')->toArray(), 'id'));
+//                        break;
+//                }
+//            }
+//        }
+//
+//    }
 
     /**
      * @test
@@ -151,16 +144,17 @@ class GetOrderCountingRecordsTest extends TestCase
             }
         }
         $result = $this->newOrderCountingRecordService->getOrderCountingRecords($this->queryConditionDay);
-        $this->assertNotEmpty($result);
+        $this->assertEquals([1, 1, 1, 1], array_column($result->toArray(), 'amount'));
     }
+
     /**
      * @test
      */
-    public function get_all_from_orders_week()
+    public function get_all_from_orders_Month()
     {
         for ($i = 0; $i <= $this->step_length; $i++) {
             foreach ($this->ownerIds as $ownerId) {
-                $dateStr = Carbon::now()->subWeeks($i)->toDateTimeString();
+                $dateStr = Carbon::now()->subMonths($i)->toDateTimeString();
                 $order = factory(Order::class)->create([
                     'created_at' => $dateStr,
                     'owner_id' => $ownerId,
@@ -169,19 +163,18 @@ class GetOrderCountingRecordsTest extends TestCase
                 $this->orderIds = $order->id;
             }
         }
-        $result = $this->newOrderCountingRecordService->getOrderCountingRecords($this->queryConditionWeek);
-        dump($result->toArray());
-        $this->assertEquals([1,1,1,1],array_column($result->toArray(),'amount'));
+        $result = $this->newOrderCountingRecordService->getOrderCountingRecords($this->queryConditionMonth);
+        $this->assertEquals([1, 1, 1, 1], array_column($result->toArray(), 'amount'));
     }
 
     /**
      * @test
      */
-    public function get_all_from_orders_Month()
+    public function get_all_from_orders_Year()
     {
         for ($i = 0; $i <= $this->step_length; $i++) {
             foreach ($this->ownerIds as $ownerId) {
-                $dateStr = Carbon::now()->subMonths($i)->toDateTimeString();
+                $dateStr = Carbon::now()->subYears($i)->toDateTimeString();
                 $order = factory(Order::class)->create([
                     'created_at' => $dateStr,
                     'owner_id' => $ownerId,
@@ -190,8 +183,7 @@ class GetOrderCountingRecordsTest extends TestCase
                 $this->orderIds = $order->id;
             }
         }
-        $result = $this->newOrderCountingRecordService->getOrderCountingRecords($this->queryConditionMonth);
-        dd($result->toArray());
-        $this->assertEquals([1,1,1,1],array_column($result->toArray(),'amount'));
+        $result = $this->newOrderCountingRecordService->getOrderCountingRecords($this->queryConditionYear);
+        $this->assertEquals([1, 1, 1, 1], array_column($result->toArray(), 'amount'));
     }
 }

+ 1 - 1
tests/Services/NewOrderCountingRecordService/NewOrderCountingRecordServiceTest.php

@@ -86,7 +86,7 @@ class NewOrderCountingRecordServiceTest extends TestCase
 
         cache()->put($key, 'This is a test value');
 
-        $result = $this->newOrderCountingRecordService->orderCountingRecords($start, $end, $unit);
+        $result = $this->newOrderCountingRecordService->get($start, $end, $unit);
         $this->assertEquals('This is a test value', $result);
     }
 

+ 75 - 0
tests/Services/NewOrderCountingRecordService/OrderCountingRecordsTest.php

@@ -0,0 +1,75 @@
+<?php
+
+namespace NewOrderCountingRecordService;
+
+
+use App\Order;
+use App\OrderCountingRecord;
+use App\Owner;
+use App\Services\NewOrderCountingRecordService;
+use App\User;
+use Carbon\Carbon;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Tests\TestCase;
+
+class OrderCountingRecordsTest extends TestCase
+{
+    use RefreshDatabase;
+
+    protected $newOrderCountingRecordService;
+    protected $queryConditionDay;
+    protected $queryConditionWeek;
+    protected $queryConditionMonth;
+    protected $queryConditionYear;
+    protected $ownerIds;
+    protected $cache_key = 'order_counting_records_';
+    protected $step_length = 1;
+    protected $orderCountingRecordIds = [];
+    protected $units = ['日', '月', '年'];
+    protected $orderIds;
+
+
+    protected function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        cache()->flush();
+        $this->newOrderCountingRecordService = new NewOrderCountingRecordService();
+        $this->actingAs(factory(User::class)->create(['name' => 'yang']));
+        $owners = factory(Owner::class)->times(2)->create();
+        $this->ownerIds = array_column($owners->toArray(), 'id');
+        $this->queryConditionDay = $this->newOrderCountingRecordService->transfersToCondition(Carbon::now()->subDays($this->step_length)->toDateString(), Carbon::now()->toDateString(), '日', $this->ownerIds);
+        $this->queryConditionMonth = $this->newOrderCountingRecordService->transfersToCondition(Carbon::now()->subMonths($this->step_length)->toDateString(), Carbon::now()->toDateString(), '月', $this->ownerIds);
+        $this->queryConditionYear = $this->newOrderCountingRecordService->transfersToCondition(Carbon::now()->subYears($this->step_length)->toDateString(), Carbon::now()->toDateString(), '年', $this->ownerIds);
+    }
+
+    protected function tearDown(): void
+    {
+        cache()->flush();
+        Owner::destroy($this->ownerIds);
+        orderCountingRecord::destroy($this->orderCountingRecordIds);
+        parent::tearDown();
+    }
+
+
+    /**
+     * @test
+     */
+    public function unit_day()
+    {
+        for ($i = 0; $i <= $this->step_length; $i++) {
+            foreach ($this->ownerIds as $ownerId) {
+                $dateStr = Carbon::now()->subDays($i)->toDateTimeString();
+                $order = factory(Order::class)->create([
+                    'created_at' => $dateStr,
+                    'owner_id' => $ownerId,
+                    'wms_status' => '订单完成'
+                ]);
+                $this->orderIds = $order->id;
+            }
+        }
+        $start = Carbon::now()->subDays($this->step_length)->toDateString();
+        $end = Carbon::now()->toDateString();
+        $result =  $this->newOrderCountingRecordService->orderCountingRecords($start, $end, '日', $this->ownerIds);
+        $this->assertEquals([2,2],$result->pluck('counter')->toArray());
+    }
+}