|
@@ -39,13 +39,14 @@ class NewOrderCountingRecordServiceTest extends TestCase
|
|
|
/**
|
|
/**
|
|
|
* @test
|
|
* @test
|
|
|
*/
|
|
*/
|
|
|
- public function dateUtils_day()
|
|
|
|
|
|
|
+ public function transfersToConditions()
|
|
|
{
|
|
{
|
|
|
factory(Owner::class)->times(2)->create();
|
|
factory(Owner::class)->times(2)->create();
|
|
|
$start = Carbon::now()->subDays(2)->toDateString();
|
|
$start = Carbon::now()->subDays(2)->toDateString();
|
|
|
$end = Carbon::now()->toDateString();
|
|
$end = Carbon::now()->toDateString();
|
|
|
$unit = '日';
|
|
$unit = '日';
|
|
|
- $dateArray = $this->newOrderCountingRecordService->dateUtils($start, $end, $unit);
|
|
|
|
|
|
|
+ $ownerIds = $this->newOrderCountingRecordService->getCountingOwnerIds();
|
|
|
|
|
+ $dateArray = $this->newOrderCountingRecordService->transfersToCondition($start, $end, $unit, $ownerIds);
|
|
|
$this->assertEquals([
|
|
$this->assertEquals([
|
|
|
Carbon::now()->subDays(2)->toDateString() => [0 => 1, 1 => 2],
|
|
Carbon::now()->subDays(2)->toDateString() => [0 => 1, 1 => 2],
|
|
|
Carbon::now()->subDays(1)->toDateString() => [0 => 1, 1 => 2],
|
|
Carbon::now()->subDays(1)->toDateString() => [0 => 1, 1 => 2],
|
|
@@ -53,6 +54,26 @@ class NewOrderCountingRecordServiceTest extends TestCase
|
|
|
], $dateArray);
|
|
], $dateArray);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @test
|
|
|
|
|
+ */
|
|
|
|
|
+ public function dateUtils_week()
|
|
|
|
|
+ {
|
|
|
|
|
+ factory(Owner::class)->times(2)->create();
|
|
|
|
|
+ $start = Carbon::now()->subWeeks(2)->toDateString();
|
|
|
|
|
+ $end = Carbon::now()->toDateString();
|
|
|
|
|
+ $unit = '周';
|
|
|
|
|
+ $ownerIds = $this->newOrderCountingRecordService->getCountingOwnerIds();
|
|
|
|
|
+ $dateArray = $this->newOrderCountingRecordService->transfersToCondition($start, $end, $unit, $ownerIds);
|
|
|
|
|
+ dd($dateArray);
|
|
|
|
|
+// $this->assertEquals([
|
|
|
|
|
+// Carbon::now()->subWeeks(2)->toDateString() => [0 => 1, 1 => 2],
|
|
|
|
|
+// Carbon::now()->subWeeks(1)->toDateString() => [0 => 1, 1 => 2],
|
|
|
|
|
+// Carbon::now()->toDateString() => [0 => 1, 1 => 2],
|
|
|
|
|
+// ], $dateArray);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @test
|
|
* @test
|
|
|
*/
|
|
*/
|
|
@@ -79,14 +100,16 @@ class NewOrderCountingRecordServiceTest extends TestCase
|
|
|
$end = Carbon::now()->toDateString();
|
|
$end = Carbon::now()->toDateString();
|
|
|
$unit = '日';
|
|
$unit = '日';
|
|
|
factory(Owner::class)->times(2)->create();
|
|
factory(Owner::class)->times(2)->create();
|
|
|
- $queryCondition = $this->newOrderCountingRecordService->dateUtils($start, $end, $unit);
|
|
|
|
|
|
|
+ $ownerIds = $this->newOrderCountingRecordService->getCountingOwnerIds();
|
|
|
|
|
+ $queryCondition = $this->newOrderCountingRecordService->transfersToCondition($start, $end, $unit, $ownerIds);
|
|
|
|
|
+
|
|
|
foreach ($queryCondition as $dateStr => $ownerIds) {
|
|
foreach ($queryCondition as $dateStr => $ownerIds) {
|
|
|
foreach ($ownerIds as $ownerId) {
|
|
foreach ($ownerIds as $ownerId) {
|
|
|
$key = 'order_counting_records_' . $dateStr . '_' . $ownerId . '_' . $unit . '_' . auth()->id();
|
|
$key = 'order_counting_records_' . $dateStr . '_' . $ownerId . '_' . $unit . '_' . auth()->id();
|
|
|
cache()->put($key, collect()->push(factory(Owner::class)->create()));
|
|
cache()->put($key, collect()->push(factory(Owner::class)->create()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- $result = $this->newOrderCountingRecordService->dataFromCache($start, $end, $unit);
|
|
|
|
|
|
|
+ $result = $this->newOrderCountingRecordService->getFromCache($queryCondition, $unit);
|
|
|
$this->assertCount(6, $result['dataFromCache']);
|
|
$this->assertCount(6, $result['dataFromCache']);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -99,7 +122,11 @@ class NewOrderCountingRecordServiceTest extends TestCase
|
|
|
$end = Carbon::now()->toDateString();
|
|
$end = Carbon::now()->toDateString();
|
|
|
$unit = '日';
|
|
$unit = '日';
|
|
|
factory(Owner::class)->times(2)->create();
|
|
factory(Owner::class)->times(2)->create();
|
|
|
- $result = $this->newOrderCountingRecordService->dataFromCache($start, $end, $unit);
|
|
|
|
|
|
|
+ $ownerIds = $this->newOrderCountingRecordService->getCountingOwnerIds();
|
|
|
|
|
+ $queryCondition = $this->newOrderCountingRecordService->transfersToCondition($start, $end, $unit, $ownerIds);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ $result = $this->newOrderCountingRecordService->getFromCache($queryCondition, $unit);
|
|
|
$this->assertEquals([
|
|
$this->assertEquals([
|
|
|
Carbon::now()->subDays(2)->toDateString() => [0 => 1, 1 => 2],
|
|
Carbon::now()->subDays(2)->toDateString() => [0 => 1, 1 => 2],
|
|
|
Carbon::now()->subDays(1)->toDateString() => [0 => 1, 1 => 2],
|
|
Carbon::now()->subDays(1)->toDateString() => [0 => 1, 1 => 2],
|
|
@@ -121,8 +148,10 @@ class NewOrderCountingRecordServiceTest extends TestCase
|
|
|
factory(OrderCountingRecord::class)->times(2)->create(['date_target' => Carbon::now()->toDateString(), 'owner_id' => $owner2->id]);
|
|
factory(OrderCountingRecord::class)->times(2)->create(['date_target' => Carbon::now()->toDateString(), 'owner_id' => $owner2->id]);
|
|
|
factory(OrderCountingRecord::class)->times(2)->create(['date_target' => Carbon::now()->subDays(1)->toDateString(), 'owner_id' => $owner1->id]);
|
|
factory(OrderCountingRecord::class)->times(2)->create(['date_target' => Carbon::now()->subDays(1)->toDateString(), 'owner_id' => $owner1->id]);
|
|
|
factory(OrderCountingRecord::class)->times(2)->create(['date_target' => Carbon::now()->subDays(1)->toDateString(), 'owner_id' => $owner2->id]);
|
|
factory(OrderCountingRecord::class)->times(2)->create(['date_target' => Carbon::now()->subDays(1)->toDateString(), 'owner_id' => $owner2->id]);
|
|
|
- $dateArray = $this->newOrderCountingRecordService->dateUtils($start, $end, $unit);
|
|
|
|
|
- $result = $this->newOrderCountingRecordService->dataFromMiddleTable($dateArray, $unit);
|
|
|
|
|
|
|
+ $ownerIds = $this->newOrderCountingRecordService->getCountingOwnerIds();
|
|
|
|
|
+
|
|
|
|
|
+ $queryCondition = $this->newOrderCountingRecordService->transfersToCondition($start, $end, $unit, $ownerIds);
|
|
|
|
|
+ $result = $this->newOrderCountingRecordService->dataFromMiddleTable($queryCondition, $unit);
|
|
|
|
|
|
|
|
$this->assertCount(8, $result['dataFromMiddleTable']);
|
|
$this->assertCount(8, $result['dataFromMiddleTable']);
|
|
|
$this->assertCount(0, $result['unQueryCondition'][Carbon::now()->toDateString()]);
|
|
$this->assertCount(0, $result['unQueryCondition'][Carbon::now()->toDateString()]);
|
|
@@ -137,10 +166,11 @@ class NewOrderCountingRecordServiceTest extends TestCase
|
|
|
$start = Carbon::now()->subDays(1)->toDateString();
|
|
$start = Carbon::now()->subDays(1)->toDateString();
|
|
|
$end = Carbon::now()->toDateString();
|
|
$end = Carbon::now()->toDateString();
|
|
|
$unit = '日';
|
|
$unit = '日';
|
|
|
- $owner1 = factory(Owner::class)->create();
|
|
|
|
|
- $owner2 = factory(Owner::class)->create();
|
|
|
|
|
|
|
+ factory(Owner::class)->create();
|
|
|
|
|
+ factory(Owner::class)->create();
|
|
|
|
|
+ $ownerIds = $this->newOrderCountingRecordService->getCountingOwnerIds();
|
|
|
|
|
|
|
|
- $dateArray = $this->newOrderCountingRecordService->dateUtils($start, $end, $unit);
|
|
|
|
|
|
|
+ $dateArray = $this->newOrderCountingRecordService->transfersToCondition($start, $end, $unit, $ownerIds);
|
|
|
$result = $this->newOrderCountingRecordService->dataFromMiddleTable($dateArray, $unit);
|
|
$result = $this->newOrderCountingRecordService->dataFromMiddleTable($dateArray, $unit);
|
|
|
|
|
|
|
|
$this->assertCount(0, $result['dataFromMiddleTable']);
|
|
$this->assertCount(0, $result['dataFromMiddleTable']);
|
|
@@ -158,8 +188,9 @@ class NewOrderCountingRecordServiceTest extends TestCase
|
|
|
$unit = '日';
|
|
$unit = '日';
|
|
|
$owner1 = factory(Owner::class)->create();
|
|
$owner1 = factory(Owner::class)->create();
|
|
|
$owner2 = factory(Owner::class)->create();
|
|
$owner2 = factory(Owner::class)->create();
|
|
|
|
|
+ $ownerIds = $this->newOrderCountingRecordService->getCountingOwnerIds();
|
|
|
|
|
|
|
|
- $dateArray = $this->newOrderCountingRecordService->dateUtils($start, $end, $unit);
|
|
|
|
|
|
|
+ $dateArray = $this->newOrderCountingRecordService->transfersToCondition($start, $end, $unit, $ownerIds);
|
|
|
factory(OrderCountingRecord::class)->times(2)->create(['date_target' => Carbon::now()->toDateString(), 'owner_id' => $owner1->id]);
|
|
factory(OrderCountingRecord::class)->times(2)->create(['date_target' => Carbon::now()->toDateString(), 'owner_id' => $owner1->id]);
|
|
|
|
|
|
|
|
$result = $this->newOrderCountingRecordService->dataFromMiddleTable($dateArray, $unit);
|
|
$result = $this->newOrderCountingRecordService->dataFromMiddleTable($dateArray, $unit);
|
|
@@ -179,8 +210,9 @@ class NewOrderCountingRecordServiceTest extends TestCase
|
|
|
$unit = '日';
|
|
$unit = '日';
|
|
|
$owner1 = factory(Owner::class)->create();
|
|
$owner1 = factory(Owner::class)->create();
|
|
|
$owner2 = factory(Owner::class)->create();
|
|
$owner2 = factory(Owner::class)->create();
|
|
|
|
|
+ $ownerIds = $this->newOrderCountingRecordService->getCountingOwnerIds();
|
|
|
|
|
|
|
|
- $dateArray = $this->newOrderCountingRecordService->dateUtils($start, $end, $unit);
|
|
|
|
|
|
|
+ $dateArray = $this->newOrderCountingRecordService->transfersToCondition($start, $end, $unit, $ownerIds);
|
|
|
$orderCountingRecord = factory(OrderCountingRecord::class)->times(2)->create(['date_target' => Carbon::now()->toDateString(), 'owner_id' => $owner1->id]);
|
|
$orderCountingRecord = factory(OrderCountingRecord::class)->times(2)->create(['date_target' => Carbon::now()->toDateString(), 'owner_id' => $owner1->id]);
|
|
|
|
|
|
|
|
$result = $this->newOrderCountingRecordService->dataFromMiddleTable($dateArray, $unit);
|
|
$result = $this->newOrderCountingRecordService->dataFromMiddleTable($dateArray, $unit);
|
|
@@ -202,8 +234,9 @@ class NewOrderCountingRecordServiceTest extends TestCase
|
|
|
$unit = '日';
|
|
$unit = '日';
|
|
|
$owner1 = factory(Owner::class)->create();
|
|
$owner1 = factory(Owner::class)->create();
|
|
|
$owner2 = factory(Owner::class)->create();
|
|
$owner2 = factory(Owner::class)->create();
|
|
|
|
|
+ $ownerIds = $this->newOrderCountingRecordService->getCountingOwnerIds();
|
|
|
|
|
|
|
|
- $unQueryCondition = $this->newOrderCountingRecordService->dateUtils($start, $end, $unit);
|
|
|
|
|
|
|
+ $unQueryCondition = $this->newOrderCountingRecordService->transfersToCondition($start, $end, $unit, $ownerIds);
|
|
|
|
|
|
|
|
factory(Order::class)->times(1)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now(), 'owner_id' => $owner1->id]);
|
|
factory(Order::class)->times(1)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now(), 'owner_id' => $owner1->id]);
|
|
|
factory(Order::class)->times(2)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now(), 'owner_id' => $owner2->id]);
|
|
factory(Order::class)->times(2)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now(), 'owner_id' => $owner2->id]);
|
|
@@ -228,8 +261,8 @@ class NewOrderCountingRecordServiceTest extends TestCase
|
|
|
$unit = '日';
|
|
$unit = '日';
|
|
|
$owner1 = factory(Owner::class)->create();
|
|
$owner1 = factory(Owner::class)->create();
|
|
|
$owner2 = factory(Owner::class)->create();
|
|
$owner2 = factory(Owner::class)->create();
|
|
|
-
|
|
|
|
|
- $unQueryCondition = $this->newOrderCountingRecordService->dateUtils($start, $end, $unit);
|
|
|
|
|
|
|
+ $ownerIds = $this->newOrderCountingRecordService->getCountingOwnerIds();
|
|
|
|
|
+ $unQueryCondition = $this->newOrderCountingRecordService->transfersToCondition($start, $end, $unit, $ownerIds);
|
|
|
|
|
|
|
|
factory(Order::class)->times(1)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now(), 'owner_id' => $owner1->id]);
|
|
factory(Order::class)->times(1)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now(), 'owner_id' => $owner1->id]);
|
|
|
factory(Order::class)->times(2)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now(), 'owner_id' => $owner2->id]);
|
|
factory(Order::class)->times(2)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now(), 'owner_id' => $owner2->id]);
|
|
@@ -255,7 +288,7 @@ class NewOrderCountingRecordServiceTest extends TestCase
|
|
|
$owner1 = factory(Owner::class)->create();
|
|
$owner1 = factory(Owner::class)->create();
|
|
|
$owner2 = factory(Owner::class)->create();
|
|
$owner2 = factory(Owner::class)->create();
|
|
|
|
|
|
|
|
- $unQueryCondition = $this->newOrderCountingRecordService->dateUtils($start, $end, $unit);
|
|
|
|
|
|
|
+ $unQueryCondition = $this->newOrderCountingRecordService->transfersToCondition($start, $end, $unit,$this->newOrderCountingRecordService->getCountingOwnerIds());
|
|
|
|
|
|
|
|
factory(Order::class)->times(1)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now(), 'owner_id' => $owner1->id]);
|
|
factory(Order::class)->times(1)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now(), 'owner_id' => $owner1->id]);
|
|
|
factory(Order::class)->times(2)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now(), 'owner_id' => $owner2->id]);
|
|
factory(Order::class)->times(2)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now(), 'owner_id' => $owner2->id]);
|
|
@@ -291,8 +324,9 @@ class NewOrderCountingRecordServiceTest extends TestCase
|
|
|
|
|
|
|
|
factory(Order::class)->times(3)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now()->subDays(1), 'owner_id' => $owner1->id]);
|
|
factory(Order::class)->times(3)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now()->subDays(1), 'owner_id' => $owner1->id]);
|
|
|
factory(Order::class)->times(4)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now()->subDays(1), 'owner_id' => $owner2->id]);
|
|
factory(Order::class)->times(4)->create(['wms_status' => '订单完成', 'created_at' => Carbon::now()->subDays(1), 'owner_id' => $owner2->id]);
|
|
|
|
|
+ $unQueryCondition = $this->newOrderCountingRecordService->transfersToCondition($start, $end, $unit,$this->newOrderCountingRecordService->getCountingOwnerIds());
|
|
|
|
|
|
|
|
- $result = $this->newOrderCountingRecordService->orderCountingRecordsDay($start, $end, $unit);
|
|
|
|
|
|
|
+ $result = $this->newOrderCountingRecordService->getOrderCountingRecords($unQueryCondition, $unit);
|
|
|
$this->assertEquals(3, $result->where('date_target', Carbon::now()->toDateString())->reduce(function ($carry, $item) {
|
|
$this->assertEquals(3, $result->where('date_target', Carbon::now()->toDateString())->reduce(function ($carry, $item) {
|
|
|
return $carry + $item->amount;
|
|
return $carry + $item->amount;
|
|
|
}));
|
|
}));
|