小程序用户改用门店登录

This commit is contained in:
liu
2026-08-20 13:46:04 +08:00
parent 6d9f02d831
commit c1d490134e
251 changed files with 689 additions and 2727 deletions
+20 -51
View File
@@ -6,11 +6,10 @@ use App\Models\CustomerLevelModel;
use App\Models\NoticeModel;
use App\Models\ProductModel;
use App\Models\StoreModel;
use App\Models\UserModel;
/**
* A2 等级价格体系(等级上浮比例):列表按等级换算价、批量调价(成本价)事务与调价通知、
* 等级上浮比例变更通知
* 等级上浮比例变更通知(门店即用户:通知按门店下发,一店一条)
*/
class ProductPriceTest extends ProcurementTestCase
{
@@ -23,13 +22,13 @@ class ProductPriceTest extends ProcurementTestCase
$storeB = StoreModel::factory()->create(['level_id' => $levelB->id]);
$product = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'cost_price' => 10.00]);
$this->actingAsMiniUser(UserModel::factory()->forStore($storeA->id)->create());
$this->actingAsMiniStore($storeA);
$rowA = collect($this->getJson('/mini/product/list')->assertOk()->json('data.data'))
->firstWhere('id', $product->id);
$this->assertNotNull($rowA, '商品应出现在列表中');
$this->assertSame(13.00, (float) $rowA['price'], 'A 等级:10 元上浮 30% = 13.00');
$this->actingAsMiniUser(UserModel::factory()->forStore($storeB->id)->create());
$this->actingAsMiniStore($storeB);
$rowB = collect($this->getJson('/mini/product/list')->assertOk()->json('data.data'))
->firstWhere('id', $product->id);
$this->assertSame(11.00, (float) $rowB['price'], 'B 等级:10 元上浮 10% = 11.00');
@@ -40,7 +39,7 @@ class ProductPriceTest extends ProcurementTestCase
{
$store = StoreModel::factory()->create(['level_id' => 0]);
$product = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON]);
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
$this->actingAsMiniStore($store);
$response = $this->getJson('/mini/product/list');
$response->assertOk()->assertJsonPath('success', true);
@@ -50,37 +49,13 @@ class ProductPriceTest extends ProcurementTestCase
$this->assertNull($row['price'], '未设等级时价格应为 null');
}
/** 未绑定门店:可浏览商品与分类,但价格不可见;加购仍被拦截(购买前置校验不变 */
public function test_unbound_user_can_browse_products_without_price_but_cannot_cart(): void
{
$product = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON]);
$this->actingAsMiniUser(UserModel::factory()->create()); // type=0 待绑定
$list = $this->getJson('/mini/product/list');
$list->assertOk()->assertJsonPath('success', true);
$row = collect($list->json('data.data'))->firstWhere('id', $product->id);
$this->assertNotNull($row, '未绑定门店应能看到商品');
$this->assertNull($row['price'], '未绑定门店不得看到价格');
$this->getJson('/mini/product/categories')
->assertOk()
->assertJsonPath('success', true);
$this->postJson('/mini/cart', ['product_id' => $product->id, 'quantity' => 1])
->assertJsonPath('success', false)
->assertJsonPath('msg', '尚未绑定门店,请联系客服处理');
}
/** 批量调价(成本价):事务写入 + 通知全部正常门店用户(成本变更影响所有等级售价) */
/** 批量调价(成本价):事务写入 + 通知全部正常门店(成本变更影响所有等级售价,一店一条 */
public function test_batch_price_updates_cost_and_notifies_all_stores(): void
{
$this->actingAsSysUser();
$storeA = StoreModel::factory()->create(['level_id' => CustomerLevelModel::factory()->create()->id]);
$storeB = StoreModel::factory()->create(['level_id' => CustomerLevelModel::factory()->create()->id]);
$userA = UserModel::factory()->forStore($storeA->id)->create();
$userB = UserModel::factory()->forStore($storeB->id)->create();
$product = ProductModel::factory()->create(['cost_price' => 10]);
@@ -90,17 +65,17 @@ class ProductPriceTest extends ProcurementTestCase
],
])->assertOk()->assertJsonPath('success', true);
$this->assertSame('12.00', (string) $product->fresh()->cost_price, '成本价应已更新');
$this->assertSame('12.00', (string) $product->refresh()->cost_price, '成本价应已更新');
$this->assertSame(
1,
NoticeModel::where('user_id', $userA->id)->where('type', NoticeModel::TYPE_PRICE)->count(),
'成本价变更影响所有等级售价,门店用户应收到价格变更通知'
NoticeModel::where('store_id', $storeA->id)->where('type', NoticeModel::TYPE_PRICE)->count(),
'成本价变更影响所有等级售价,门店应收到价格变更通知'
);
$this->assertSame(
1,
NoticeModel::where('user_id', $userB->id)->where('type', NoticeModel::TYPE_PRICE)->count(),
'成本价变更影响所有等级售价,门店用户应收到价格变更通知'
NoticeModel::where('store_id', $storeB->id)->where('type', NoticeModel::TYPE_PRICE)->count(),
'成本价变更影响所有等级售价,门店应收到价格变更通知'
);
}
@@ -125,35 +100,31 @@ class ProductPriceTest extends ProcurementTestCase
$this->assertSame(12.0, (float) $row['price_' . $level->id], '矩阵等级格应为换算价:10 元上浮 20% = 12.00');
}
/** 等级上浮比例变更:通知该等级下正常门店用户(不影响其他等级门店) */
/** 等级上浮比例变更:通知该等级下正常门店(不影响其他等级门店) */
public function test_level_percent_update_notifies_level_stores(): void
{
$this->actingAsSysUser();
$level = CustomerLevelModel::factory()->create(['percent' => 10]);
$otherLevel = CustomerLevelModel::factory()->create(['percent' => 20]);
$user = UserModel::factory()->forStore(
StoreModel::factory()->create(['level_id' => $level->id])->id
)->create();
$otherUser = UserModel::factory()->forStore(
StoreModel::factory()->create(['level_id' => $otherLevel->id])->id
)->create();
$store = StoreModel::factory()->create(['level_id' => $level->id]);
$otherStore = StoreModel::factory()->create(['level_id' => $otherLevel->id]);
$this->putJson('/customer/level/' . $level->id, [
'name' => $level->name,
'percent' => 30,
])->assertOk()->assertJsonPath('success', true);
$this->assertSame('30.00', (string) $level->fresh()->percent, '上浮比例应已更新');
$this->assertSame('30.00', (string) $level->refresh()->percent, '上浮比例应已更新');
$this->assertSame(
1,
NoticeModel::where('user_id', $user->id)->where('type', NoticeModel::TYPE_PRICE)->count(),
'该等级门店用户应收到价格变更通知'
NoticeModel::where('store_id', $store->id)->where('type', NoticeModel::TYPE_PRICE)->count(),
'该等级门店应收到价格变更通知'
);
$this->assertSame(
0,
NoticeModel::where('user_id', $otherUser->id)->count(),
'其他等级门店用户不应收到通知'
NoticeModel::where('store_id', $otherStore->id)->count(),
'其他等级门店不应收到通知'
);
}
@@ -163,16 +134,14 @@ class ProductPriceTest extends ProcurementTestCase
$this->actingAsSysUser();
$level = CustomerLevelModel::factory()->create(['percent' => 10]);
$user = UserModel::factory()->forStore(
StoreModel::factory()->create(['level_id' => $level->id])->id
)->create();
$store = StoreModel::factory()->create(['level_id' => $level->id]);
$this->putJson('/customer/level/' . $level->id, [
'name' => $level->name . '(改)',
'percent' => 10,
])->assertOk()->assertJsonPath('success', true);
$this->assertSame(0, NoticeModel::where('user_id', $user->id)->count(), '上浮比例未变不应发通知');
$this->assertSame(0, NoticeModel::where('store_id', $store->id)->count(), '上浮比例未变不应发通知');
}
/** 等级表单:上浮比例校验(负数/超限拒绝) */