diff --git a/modules/EcommerceFinance/Repositories/InstallationDetailMirrorRepository.php b/modules/EcommerceFinance/Repositories/InstallationDetailMirrorRepository.php index 81929719..8554558e 100644 --- a/modules/EcommerceFinance/Repositories/InstallationDetailMirrorRepository.php +++ b/modules/EcommerceFinance/Repositories/InstallationDetailMirrorRepository.php @@ -121,11 +121,27 @@ class InstallationDetailMirrorRepository if (!empty($filters[$prefix.'_from'])) $query->where('v.'.$column, '>=', $filters[$prefix.'_from']); if (!empty($filters[$prefix.'_to'])) $query->where('v.'.$column, '<', \Illuminate\Support\Carbon::parse($filters[$prefix.'_to'])->addDay()->toDateString()); } - foreach (['push_status'=>'apistatus','order_no'=>'OrderNum','customer_review'=>'kfsh','finance_review'=>'cwsh','quote_status'=>'BidStatus','fee_payer'=>'costtaker','completed_status'=>'installComplete','shop_name'=>'shop_name','delete_status'=>'Delete','installation_company'=>'installCompanyName','installation_no'=>'ordernum_id','order_type'=>'TypeDto'] as $key=>$column) { + foreach (['push_status'=>'apistatus','order_no'=>'OrderNum','quote_status'=>'BidStatus','fee_payer'=>'costtaker','shop_name'=>'shop_name','installation_company'=>'installCompanyName','installation_no'=>'ordernum_id','order_type'=>'TypeDto'] as $key=>$column) { if (isset($filters[$key]) && $filters[$key] !== '') $query->where('v.'.$column, $filters[$key]); } + foreach (['customer_review'=>'kfsh','finance_review'=>'cwsh','completed_status'=>'installComplete','delete_status'=>'Delete'] as $key=>$column) { + if (!isset($filters[$key]) || $filters[$key] === '') continue; + if ((string) $filters[$key] === '1') { + $query->where('v.'.$column, 1); + } else { + $query->where(function ($sub) use ($column): void { + $sub->whereNull('v.'.$column)->orWhere('v.'.$column, 0); + }); + } + } if (isset($filters['arranged_status']) && $filters['arranged_status'] !== '') { - $query->where('v.StatusId', $filters['arranged_status'] === '1' ? '>' : '<=', 0); + if ($filters['arranged_status'] === '1') { + $query->where('v.StatusId', '>', 0); + } else { + $query->where(function ($sub): void { + $sub->whereNull('v.StatusId')->orWhere('v.StatusId', '<=', 0); + }); + } } if (!empty($filters['product_id'])) { $query->whereExists(function ($sub) use ($itemTable, $filters) { @@ -215,18 +231,18 @@ class InstallationDetailMirrorRepository ]; } - private function yesNo(mixed $value): ?string + private function yesNo(mixed $value): string { - return $value === null ? null : ((int) $value === 1 ? '是' : '否'); + return (int) $value === 1 ? '是' : '否'; } - private function review(mixed $value): ?string + private function review(mixed $value): string { - return $value === null ? null : ((int) $value === 1 ? '已审核' : '未审核'); + return (int) $value === 1 ? '已审核' : '未审核'; } - private function arranged(mixed $value): ?string + private function arranged(mixed $value): string { - return $value === null ? null : ((int) $value > 0 ? '已安排' : '未安排'); + return (int) $value > 0 ? '已安排' : '未安排'; } } diff --git a/tests/Unit/EcommerceFinance/InstallationDetailMirrorRepositoryTest.php b/tests/Unit/EcommerceFinance/InstallationDetailMirrorRepositoryTest.php index 9a35ef01..10b1ef7f 100644 --- a/tests/Unit/EcommerceFinance/InstallationDetailMirrorRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/InstallationDetailMirrorRepositoryTest.php @@ -29,7 +29,7 @@ class InstallationDetailMirrorRepositoryTest extends TestCase $schema->create('fixture_install',function(Blueprint $t){ $t->integer('Id'); foreach(['SourceGuid','OrderNum','ordernum_id','shop_name','SubmitTime','kfshTime','cwshTime','apistatus','kfsh','cwsh','BidStatus','costtaker','installComplete','Delete','installCompanyName','TypeDto'] as $c) $t->string($c)->nullable(); - $t->integer('StatusId')->default(0); + $t->integer('StatusId')->nullable()->default(0); foreach(['installcost','settleAmount','acceptAmount'] as $c) $t->decimal($c,14,2)->default(0); }); $schema->create('fixture_items',function(Blueprint $t){$t->integer('Id');$t->string('guid');$t->string('shopproid');$t->string('Sourceno')->nullable();}); @@ -79,6 +79,32 @@ class InstallationDetailMirrorRepositoryTest extends TestCase $this->assertTrue($result['has_more']); } + public function test_unset_status_filters_include_null_values_and_render_explicit_labels(): void + { + DB::connection('business_mirror')->table('fixture_install')->where('Id',3)->update(['StatusId'=>null]); + + foreach (['customer_review','finance_review','completed_status','delete_status','arranged_status'] as $key) { + $this->assertSame(3,$this->repository->paginate(1,50,[$key=>'0'])['total'],$key); + } + + $other=$this->repository->paginate(1,50,['shop_name'=>'其他店'])['data'][0]; + $this->assertSame('未审核',$other['customer_service_review']); + $this->assertSame('未审核',$other['finance_review']); + $this->assertSame('否',$other['completed_status']); + $this->assertSame('未安排',$other['arranged_status']); + + DB::connection('business_mirror')->table('fixture_install')->where('Id',2)->update([ + 'kfsh'=>1, + 'cwsh'=>1, + 'installComplete'=>1, + 'Delete'=>0, + 'StatusId'=>1, + ]); + foreach (['customer_review','finance_review','completed_status','arranged_status'] as $key) { + $this->assertSame(1,$this->repository->paginate(1,50,[$key=>'1'])['total'],$key); + } + } + public function test_end_date_alone_is_valid_and_invalid_status_is_rejected(): void { request()->merge(['created_to'=>'2026-08-20']);