更新
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// Real ORM queries against an isolated in-memory database; never load business configuration.
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
use app\adminapi\lists\tcm\PrescriptionOrderLists;
|
||||
use think\facade\Db;
|
||||
|
||||
if (!in_array('sqlite', PDO::getAvailableDrivers(), true)) {
|
||||
throw new RuntimeException('In-memory SQLite is required; no external database fallback');
|
||||
}
|
||||
$app = new think\App(sys_get_temp_dir() . '/rx-list-no-app-' . bin2hex(random_bytes(8)));
|
||||
$manager = new think\DbManager();
|
||||
$manager->setConfig([
|
||||
'default' => 'sqlite', 'auto_timestamp' => false, 'datetime_format' => false,
|
||||
'connections' => ['sqlite' => ['type' => 'sqlite', 'database' => ':memory:', 'prefix' => 'zyt_']],
|
||||
]);
|
||||
$app->instance('think\DbManager', $manager);
|
||||
$app->instance('log', new Psr\Log\NullLogger());
|
||||
$config = new think\Config();
|
||||
$config->set(['data_scope' => ['enabled' => false]], 'project');
|
||||
$app->instance('config', $config);
|
||||
|
||||
Db::execute('CREATE TABLE zyt_tcm_prescription_order (
|
||||
id INTEGER PRIMARY KEY, ship_mode TEXT, gancao_reciperl_order_no TEXT,
|
||||
amount NUMERIC, prescription_audit_status INTEGER, payment_slip_audit_status INTEGER,
|
||||
fulfillment_status INTEGER, creator_id INTEGER DEFAULT 1, create_time INTEGER, delete_time INTEGER
|
||||
)');
|
||||
$fixture = static function (int $id, array $fields = []): void {
|
||||
Db::name('tcm_prescription_order')->insert(array_replace([
|
||||
'id' => $id, 'ship_mode' => 'gancao', 'gancao_reciperl_order_no' => '', 'amount' => 1000,
|
||||
'prescription_audit_status' => 0, 'payment_slip_audit_status' => 0,
|
||||
'fulfillment_status' => 1, 'create_time' => strtotime('2026-11-17 10:00:00'), 'delete_time' => null,
|
||||
], $fields));
|
||||
};
|
||||
$fixture(1); // New, pending review and not uploaded.
|
||||
$fixture(2, ['prescription_audit_status' => 1]); // Approved, still not uploaded.
|
||||
$fixture(3, ['prescription_audit_status' => 2]); // Rejected, still not uploaded.
|
||||
$fixture(4, ['prescription_audit_status' => 1, 'payment_slip_audit_status' => 1,
|
||||
'gancao_reciperl_order_no' => 'GC-4', 'fulfillment_status' => 2, 'amount' => 4000]);
|
||||
$fixture(5, ['amount' => 4000.01]);
|
||||
$fixture(6, ['ship_mode' => 'direct']);
|
||||
$fixture(7, ['ship_mode' => ' DIRECT ', 'gancao_reciperl_order_no' => 'LEGACY-GC']);
|
||||
$fixture(8, ['ship_mode' => null]);
|
||||
$fixture(9, ['ship_mode' => ' ']);
|
||||
$fixture(10, ['delete_time' => 1]);
|
||||
$fixture(11, ['prescription_audit_status' => 1, 'payment_slip_audit_status' => 2]);
|
||||
$fixture(12, ['ship_mode' => ' GANCAO ', 'amount' => 3999.99]);
|
||||
|
||||
$reflection = new ReflectionClass(PrescriptionOrderLists::class);
|
||||
$makeList = static function (array $params, array $where = []) use ($reflection): PrescriptionOrderLists {
|
||||
$list = $reflection->newInstanceWithoutConstructor();
|
||||
foreach (['params' => $params, 'searchWhere' => $where, 'adminId' => 1,
|
||||
'adminInfo' => ['root' => 1, 'admin_id' => 1]] as $key => $value) {
|
||||
$reflection->getProperty($key)->setValue($list, $value);
|
||||
}
|
||||
return $list;
|
||||
};
|
||||
$query = static fn (PrescriptionOrderLists $list) => $reflection->getMethod('buildFilteredQuery')->invoke($list);
|
||||
$ids = static fn (PrescriptionOrderLists $list): array => array_map('intval', $query($list)->order('id')->column('id'));
|
||||
$checks = 0;
|
||||
$expect = static function (mixed $expected, mixed $actual, string $message) use (&$checks): void {
|
||||
if ($expected !== $actual) {
|
||||
throw new RuntimeException($message . '\nExpected: ' . json_encode($expected) . '\nActual: ' . json_encode($actual));
|
||||
}
|
||||
++$checks;
|
||||
};
|
||||
$params = ['ship_mode' => 'gancao', 'amount_lte' => 4000];
|
||||
$list = $makeList($params);
|
||||
$expected = [1, 2, 3, 4, 8, 9, 11, 12];
|
||||
$expect($expected, $ids($list), 'All review states and pre-upload orders must be visible within the amount cap');
|
||||
$expect(8, $list->count(), 'Count must match the complete filtered list');
|
||||
$expect([1, 2, 3], array_map('intval', $query($list)->order('id')->limit(0, 3)->column('id')), 'First page');
|
||||
$expect([4, 8, 9], array_map('intval', $query($list)->order('id')->limit(3, 3)->column('id')), 'Next page includes 4000 exactly');
|
||||
$expect([1, 8, 9, 12], $ids($makeList($params, [['prescription_audit_status', '=', 0]])), 'Explicit pending review filter');
|
||||
$expect([2, 4, 11], $ids($makeList($params, [['prescription_audit_status', '=', 1]])), 'Explicit approved filter');
|
||||
$expect([3], $ids($makeList($params, [['prescription_audit_status', '=', 2]])), 'Explicit rejected filter');
|
||||
$expect([1, 2, 3, 8, 9, 12], $ids($makeList($params, [['payment_slip_audit_status', '=', 0]])), 'Explicit payment pending filter');
|
||||
$statsQuery = $reflection->getMethod('buildBaseQueryForStats')->invoke($list);
|
||||
$expect($expected, array_map('intval', (clone $statsQuery)->order('id')->column('id')), 'Statistics include the same orders');
|
||||
$expect(13999.99, round((float) $statsQuery->sum('amount'), 2), 'Statistics retain the business amount cap');
|
||||
$focus = ['pending_rx' => 4, 'pending_pay' => 1, 'pending_ship' => 1, 'risk' => 1];
|
||||
$expect($focus, $reflection->getMethod('computeFocusCountsForExtend')->invoke($list), 'Pending count must include pre-upload orders');
|
||||
$expect($focus, $reflection->getMethod('computeFocusCountsForExtend')->invoke(
|
||||
$makeList($params, [['prescription_audit_status', '=', 1]])
|
||||
), 'Focus counts remove the selected review filter');
|
||||
$expect(8, $makeList($params + ['export' => 1])->count(), 'Export count uses the same scope');
|
||||
|
||||
// An order must not disappear when it is approved, rejected, or uploaded.
|
||||
foreach ([[1, ''], [2, ''], [1, 'GC-NEW']] as [$review, $remoteNo]) {
|
||||
Db::name('tcm_prescription_order')->where('id', 1)->update([
|
||||
'prescription_audit_status' => $review, 'gancao_reciperl_order_no' => $remoteNo,
|
||||
]);
|
||||
$expect($expected, $ids($list), 'Review/upload transitions must not change inclusion');
|
||||
}
|
||||
Db::name('tcm_prescription_order')->where('id', 1)->update(['prescription_audit_status' => 0, 'gancao_reciperl_order_no' => '']);
|
||||
$expect([4], $ids($makeList(['supply_mode' => 'gancao', 'amount_lte' => 4000])), 'Legacy supply classification stays compatible');
|
||||
$expect([1, 2, 3, 8, 9, 11, 12], $ids($makeList(['supply_mode' => 'self', 'amount_lte' => 4000])), 'Legacy self bucket stays compatible');
|
||||
$expect([6, 7], $ids($makeList(['ship_mode' => 'direct', 'amount_lte' => 4000])), 'Direct pharmacy remains separate');
|
||||
$expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12], $ids($makeList([])), 'Unfiltered API consumers stay unrestricted');
|
||||
$expect([1, 2, 3, 8, 9, 11, 12], $ids($makeList(['ship_mode' => 'gancao', 'amount_lt' => 4000])), 'Legacy strict amount cap remains exclusive');
|
||||
echo "PRESCRIPTION_ORDER_LIST_PHARMACY_FILTER assertions={$checks} PASS sqlite=memory network=0\n";
|
||||
Reference in New Issue
Block a user