|
|
@@ -29,8 +29,9 @@ class OrderCountingRecordServiceGetTest extends TestCase
|
|
|
/**
|
|
|
* @test
|
|
|
*/
|
|
|
- public function current_date()
|
|
|
+ public function counting_unit_date()
|
|
|
{
|
|
|
+ cache()->flush();
|
|
|
$start = Carbon::now()->subDays(2)->format('Y-m-d');
|
|
|
$end = (new Carbon())->toDateString();
|
|
|
|
|
|
@@ -40,24 +41,97 @@ class OrderCountingRecordServiceGetTest extends TestCase
|
|
|
$orders = factory(Order::class)->times(20)->create([
|
|
|
'created_at' => Carbon::now(),
|
|
|
'owner_id' => $owner->id,
|
|
|
- 'wms_status'=>'订单完成']);
|
|
|
+ 'wms_status' => '订单完成']);
|
|
|
$orders = factory(Order::class)->times(10)->create([
|
|
|
'created_at' => Carbon::now()->subDays(1),
|
|
|
'owner_id' => $owner->id,
|
|
|
- 'wms_status'=>'订单完成']);
|
|
|
+ 'wms_status' => '订单完成']);
|
|
|
$result = $this->orderCountingRecordService->orderCountingRecords($start, $end)->toArray();
|
|
|
- $this->assertEquals([0,10,20], array_column($result, 'counter'));
|
|
|
+ $this->assertEquals([0, 10, 20], array_column($result, 'counter'));
|
|
|
cache()->flush();
|
|
|
$orders = factory(Order::class)->times(20)->create([
|
|
|
'created_at' => Carbon::now(),
|
|
|
'owner_id' => $owner->id,
|
|
|
- 'wms_status'=>'订单完成']);
|
|
|
+ 'wms_status' => '订单完成']);
|
|
|
$result = $this->orderCountingRecordService->orderCountingRecords($start, $end)->toArray();
|
|
|
- $this->assertEquals([0,10,40], array_column($result, 'counter'));
|
|
|
+ $this->assertEquals([0, 10, 40], array_column($result, 'counter'));
|
|
|
+ cache()->flush();
|
|
|
+ Order::query()->delete();
|
|
|
+ Owner::query()->delete();
|
|
|
+ User::query()->delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @test
|
|
|
+ */
|
|
|
+ public function counting_unit_week()
|
|
|
+ {
|
|
|
+ cache()->flush();
|
|
|
+ $start = Carbon::now()->subWeek()->format('Y-m-d');
|
|
|
+ $end = (new Carbon())->toDateString();
|
|
|
+ $this->actingAs(factory(User::class)->create(['name' => 'yang']));
|
|
|
+ $owner = factory(Owner::class)->create();
|
|
|
+ $orders1 = factory(Order::class)->times(20)->create([
|
|
|
+ 'created_at' => Carbon::now(),
|
|
|
+ 'owner_id' => $owner->id,
|
|
|
+ 'wms_status' => '订单完成']);
|
|
|
+
|
|
|
+ $orders2 = factory(Order::class)->times(20)->create([
|
|
|
+ 'created_at' => Carbon::now()->subWeek(),
|
|
|
+ 'owner_id' => $owner->id,
|
|
|
+ 'wms_status' => '订单完成']);
|
|
|
+
|
|
|
+ $result = $this->orderCountingRecordService->orderCountingRecords($start, $end, null, '周')->toArray();
|
|
|
+ $this->assertEquals([20, 20], array_column($result, 'counter'));
|
|
|
cache()->flush();
|
|
|
+ $orders1 = factory(Order::class)->times(20)->create([
|
|
|
+ 'created_at' => Carbon::now(),
|
|
|
+ 'owner_id' => $owner->id,
|
|
|
+ 'wms_status' => '订单完成']);
|
|
|
|
|
|
+ $result = $this->orderCountingRecordService->orderCountingRecords($start, $end, null, '周')->toArray();
|
|
|
+ $this->assertEquals([20, 40], array_column($result, 'counter'));
|
|
|
+ Order::query()->delete();
|
|
|
+ Owner::query()->delete();
|
|
|
+ User::query()->delete();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @test
|
|
|
+ */
|
|
|
+ public function counting_unit_month()
|
|
|
+ {
|
|
|
+ cache()->flush();
|
|
|
+ $start = Carbon::now()->subMonth()->format('Y-m-d');
|
|
|
+ $end = (new Carbon())->toDateString();
|
|
|
+ $this->actingAs(factory(User::class)->create(['name' => 'yang']));
|
|
|
+ $owner = factory(Owner::class)->create();
|
|
|
+ $orders1 = factory(Order::class)->times(20)->create([
|
|
|
+ 'created_at' => Carbon::now(),
|
|
|
+ 'owner_id' => $owner->id,
|
|
|
+ 'wms_status' => '订单完成']);
|
|
|
+
|
|
|
+ $orders2 = factory(Order::class)->times(20)->create([
|
|
|
+ 'created_at' => Carbon::now()->subMonth(),
|
|
|
+ 'owner_id' => $owner->id,
|
|
|
+ 'wms_status' => '订单完成']);
|
|
|
+
|
|
|
+ $result = $this->orderCountingRecordService->orderCountingRecords($start, $end, null, '月')->toArray();
|
|
|
+ $this->assertEquals([20, 20], array_column($result, 'counter'));
|
|
|
+ cache()->flush();
|
|
|
+ $orders1 = factory(Order::class)->times(20)->create([
|
|
|
+ 'created_at' => Carbon::now(),
|
|
|
+ 'owner_id' => $owner->id,
|
|
|
+ 'wms_status' => '订单完成']);
|
|
|
+
|
|
|
+ $result = $this->orderCountingRecordService->orderCountingRecords($start, $end, null, '月')->toArray();
|
|
|
+ $this->assertEquals([20, 40], array_column($result, 'counter'));
|
|
|
+ Order::query()->delete();
|
|
|
+ Owner::query()->delete();
|
|
|
+ User::query()->delete();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @test
|
|
|
*/
|
|
|
@@ -72,14 +146,14 @@ class OrderCountingRecordServiceGetTest extends TestCase
|
|
|
*/
|
|
|
public function isNotCurrentDate()
|
|
|
{
|
|
|
- $day_ture =$this->orderCountingRecordService->isNotCurrentDate(Carbon::now()->subDay()->format('Y-m-d'));
|
|
|
- $day_false =$this->orderCountingRecordService->isNotCurrentDate(Carbon::now()->format('Y-m-d'));
|
|
|
+ $day_ture = $this->orderCountingRecordService->isNotCurrentDate(Carbon::now()->subDay()->format('Y-m-d'));
|
|
|
+ $day_false = $this->orderCountingRecordService->isNotCurrentDate(Carbon::now()->format('Y-m-d'));
|
|
|
|
|
|
- $week_ture =$this->orderCountingRecordService->isNotCurrentDate(Carbon::now()->subWeek()->year . '-' . Carbon::now()->subWeek()->week);
|
|
|
- $week_false =$this->orderCountingRecordService->isNotCurrentDate(Carbon::now()->year . '-' . Carbon::now()->week);
|
|
|
+ $week_ture = $this->orderCountingRecordService->isNotCurrentDate(Carbon::now()->subWeek()->year . '-' . Carbon::now()->subWeek()->week);
|
|
|
+ $week_false = $this->orderCountingRecordService->isNotCurrentDate(Carbon::now()->year . '-' . Carbon::now()->week);
|
|
|
|
|
|
- $month_true =$this->orderCountingRecordService->isNotCurrentDate(Carbon::now()->subMonth()->year.'-'. Carbon::now()->subMonth()->month);
|
|
|
- $month_false =$this->orderCountingRecordService->isNotCurrentDate(Carbon::now()->year.'-'. Carbon::now()->month);
|
|
|
+ $month_true = $this->orderCountingRecordService->isNotCurrentDate(Carbon::now()->subMonth()->year . '-' . Carbon::now()->subMonth()->month);
|
|
|
+ $month_false = $this->orderCountingRecordService->isNotCurrentDate(Carbon::now()->year . '-' . Carbon::now()->month);
|
|
|
|
|
|
$this->assertTrue($day_ture);
|
|
|
$this->assertFalse($day_false);
|