[ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ], 'upstream_mirrors.connection' => 'business_mirror', 'upstream_mirrors.datasets' => [ ShopInfoFlowMirrorRepository::FORM_DATASET => [ 'source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'fys_shopInfo_flow', 'target' => 'shop_info_flow_form', 'keys' => ['Id'], ], ShopInfoFlowMirrorRepository::FLOW_DATASET => [ 'source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'flow_flow', 'target' => 'oa_flow_flow', 'keys' => ['Id'], ], ], ]); DB::purge('business_mirror'); $schema = Schema::connection('business_mirror'); $schema->create('business_mirror_table_states', function (Blueprint $table): void { $table->string('dataset_key')->primary(); $table->dateTime('initial_completed_at')->nullable(); }); $schema->create('shop_info_flow_form', function (Blueprint $table): void { foreach ([ 'Id', 'flowId', 'flowType', 'applyUser', 'applyTime', 'applyDepartment', 'remark', 'platform', 'responsibleDepartment', 'shopHead', 'customerManager', 'shopType', 'shopState', 'shopName', 'erpShopName', 'trademarkNumber', 'unifiedSocialCreditCode', 'informationChangeType', 'changeReason', 'changeSuccessful', 'closeReason', 'expectedClosingTime', 'refundType', 'refundAmount', 'refundIssue', ] as $column) { $table->string($column)->nullable(); } }); $schema->create('oa_flow_flow', function (Blueprint $table): void { foreach (['Id', 'flowId', 'flowType', 'flowStatus', 'subject', 'approver', 'updateTime'] as $column) { $table->string($column)->nullable(); } }); DB::connection('business_mirror')->table('business_mirror_table_states')->insert([ 'dataset_key' => ShopInfoFlowMirrorRepository::FORM_DATASET, 'initial_completed_at' => '2026-10-08 10:00:00', ]); // 三单:开店(完成)、变更(流程中,有当前审批人)、关店(拒绝)。 $this->insertApplication(1, 'shp-1', 8, '拼多多', '甲店', '拼多多-甲店', '张三', '2026-10-01 09:00:00'); $this->insertApplication(2, 'shp-2', 9, '京东', '乙店', '京东-乙店', '李四', '2026-10-02 09:00:00'); $this->insertApplication(3, 'shp-3', 10, '抖音小店', '丙店', '抖音-丙店', '王五', '2026-10-03 09:00:00'); DB::connection('business_mirror')->table('oa_flow_flow')->insert([ ['Id' => 1, 'flowId' => 'shp-1', 'flowType' => 8, 'flowStatus' => 3, 'subject' => '[店铺信息-开店流程]', 'approver' => '', 'updateTime' => '2026-10-01 10:00:00'], ['Id' => 2, 'flowId' => 'shp-2', 'flowType' => 9, 'flowStatus' => 1, 'subject' => '[店铺信息-变更流程]', 'approver' => '审核人A', 'updateTime' => '2026-10-02 10:00:00'], ['Id' => 3, 'flowId' => 'shp-3', 'flowType' => 10, 'flowStatus' => 2, 'subject' => '[店铺信息-关店流程]', 'approver' => '', 'updateTime' => '2026-10-03 10:00:00'], ]); $this->repository = new ShopInfoFlowMirrorRepository( new BusinessMirrorDatasetRegistry(), new GenericBusinessMirrorRepository(app('db')), ); } private function insertApplication(int $id, string $flowId, int $flowType, string $platform, string $shop, string $erpShop, string $user, string $applyTime): void { DB::connection('business_mirror')->table('shop_info_flow_form')->insert([ 'Id' => $id, 'flowId' => $flowId, 'flowType' => $flowType, 'platform' => $platform, 'shopName' => $shop, 'erpShopName' => $erpShop, 'applyUser' => $user, 'applyTime' => $applyTime, 'shopHead' => $user, 'responsibleDepartment' => '运营中心A', ]); } public function test_it_lists_applications_with_oa_approval_state(): void { $result = $this->repository->paginate(1, 10); $this->assertSame(3, $result['total']); $rows = collect($result['data'])->keyBy('flow_id'); $this->assertSame('店铺开店', $rows['shp-1']['flow_type']); $this->assertSame('完成', $rows['shp-1']['approval_status']); $this->assertSame('店铺变更', $rows['shp-2']['flow_type']); $this->assertSame('流程中', $rows['shp-2']['approval_status']); $this->assertSame('审核人A', $rows['shp-2']['current_approver']); $this->assertSame('店铺关店', $rows['shp-3']['flow_type']); $this->assertSame('拒绝', $rows['shp-3']['approval_status']); // 默认按申请时间倒序。 $this->assertSame(['shp-3', 'shp-2', 'shp-1'], array_column($result['data'], 'flow_id')); } public function test_it_filters_by_type_status_platform_and_dates(): void { $this->assertSame(1, $this->repository->paginate(1, 10, ['flow_type' => ['店铺开店']])['total']); $this->assertSame( 2, $this->repository->paginate(1, 10, ['flow_type' => ['店铺开店', '店铺变更']])['total'], ); $this->assertSame(1, $this->repository->paginate(1, 10, ['approval_status' => ['流程中']])['total']); $this->assertSame(2, $this->repository->paginate(1, 10, ['platform' => ['拼多多', '京东']])['total']); $this->assertSame(1, $this->repository->paginate(1, 10, ['apply_from' => '2026-10-03'])['total']); $this->assertSame(2, $this->repository->paginate(1, 10, ['apply_to' => '2026-10-02'])['total']); $this->assertSame(1, $this->repository->paginate(1, 10, ['apply_user' => '李四'])['total']); $this->assertSame(1, $this->repository->paginate(1, 10, ['erp_shop_name' => '丙店'])['total']); $this->assertSame(0, $this->repository->paginate(1, 10, ['flow_id' => '不存在'])['total']); } public function test_missing_oa_row_leaves_approval_state_blank(): void { DB::connection('business_mirror')->table('shop_info_flow_form')->insert([ 'Id' => 4, 'flowId' => 'shp-4', 'flowType' => 8, 'platform' => '天猫', 'shopName' => '丁店', 'applyUser' => '赵六', 'applyTime' => '2026-10-04 09:00:00', ]); $rows = collect($this->repository->paginate(1, 10)['data'])->keyBy('flow_id'); $this->assertSame('', $rows['shp-4']['approval_status']); $this->assertSame('', $rows['shp-4']['current_approver']); } }