service = app('OwnerStoreFeeReportService'); } public function testReturned() { OwnerStoreFeeDetail::query()->truncate(); OwnerStoreFeeReport::query()->truncate(); $ownerStoreFeeDetail_xx_1_2 = factory(OwnerStoreFeeDetail::class)->times(100) ->create([ 'owner_id' => 8, 'work_name' => 'xx入库费', 'unit_price' => 1.2, 'unit_id' => 1, ]); $ownerStoreFeeDetail_xx_1_4 = factory(OwnerStoreFeeDetail::class)->times(100) ->create([ 'owner_id' => 8, 'work_name' => 'xx入库费', 'unit_price' => 1.4, 'unit_id' => 1, ]); $ownerStoreFeeDetail_xx2_1_6 = factory(OwnerStoreFeeDetail::class)->times(100) ->create([ 'owner_id' => 8, 'work_name' => 'xx入库费2', 'unit_price' => 1.2, 'unit_id' => 1, ]); $this->service->recordReport(); $report = OwnerStoreFeeReport::query() ->where('unit_price', '1.2') ->where('owner_id', 8) ->where('unit_id', 1) ->where('work_name', 'xx入库费') ->first(); $this->assertEquals($ownerStoreFeeDetail_xx_1_2->sum('amount'), $report->amount); $this->assertEquals($ownerStoreFeeDetail_xx_1_2->sum('fee'), $report->fee); $report = OwnerStoreFeeReport::query() ->where('unit_price', '1.4') ->where('owner_id', 8) ->where('unit_id', 1) ->where('work_name', 'xx入库费') ->first(); $this->assertEquals($ownerStoreFeeDetail_xx_1_4->sum('amount'), $report->amount); $this->assertEquals($ownerStoreFeeDetail_xx_1_4->sum('fee'), $report->fee); $report = OwnerStoreFeeReport::query() ->where('unit_price', '1.2') ->where('owner_id', 8) ->where('unit_id', 1) ->where('work_name', 'xx入库费2') ->first(); $this->assertEquals($ownerStoreFeeDetail_xx2_1_6->sum('amount'), $report->amount); $this->assertEquals($ownerStoreFeeDetail_xx2_1_6->sum('fee'), $report->fee); } function tearDown(): void { OwnerStoreFeeReport::query() ->whereIn('id', data_get($this->data['ownerStoreFeeReports'], '*.id') ?? []) ->delete(); parent::tearDown(); } }