小程序用户改用门店登录
This commit is contained in:
@@ -9,19 +9,19 @@ use App\Models\StoreModel;
|
||||
use App\Models\StoreOrderItemModel;
|
||||
use App\Models\StoreOrderModel;
|
||||
use App\Models\SupplierModel;
|
||||
use App\Models\UserModel;
|
||||
|
||||
/**
|
||||
* 门店订单明细(商品快照):
|
||||
* 下单快照完整商品档案、成本价防泄漏、采购单内门店单品增删改重算汇总、按商品名称搜索订单
|
||||
* (门店即用户:小程序端登录主体为 StoreModel)
|
||||
*/
|
||||
class StoreOrderItemTest extends ProcurementTestCase
|
||||
{
|
||||
/**
|
||||
* 造门店 + 上架商品(指定成本价)+ 门店用户;
|
||||
* 造门店 + 上架商品(指定成本价);
|
||||
* 等级上浮比例按 price/costPrice 反算(售价 = 成本价 × (100 + percent) / 100)
|
||||
*
|
||||
* @return array{0: StoreModel, 1: ProductModel, 2: UserModel}
|
||||
* @return array{0: StoreModel, 1: ProductModel}
|
||||
*/
|
||||
private function makeStoreWithProduct(string $price = '5.00', string $costPrice = '4.00'): array
|
||||
{
|
||||
@@ -33,17 +33,17 @@ class StoreOrderItemTest extends ProcurementTestCase
|
||||
'cost_price' => $costPrice,
|
||||
]);
|
||||
|
||||
return [$store, $product, UserModel::factory()->forStore($store->id)->create()];
|
||||
return [$store, $product];
|
||||
}
|
||||
|
||||
/** 以小程序身份下一单并返回订单(可指定初始状态) */
|
||||
private function placeOrder(ProductModel $product, UserModel $user, int $quantity = 2, int $status = StoreOrderModel::STATUS_PENDING): StoreOrderModel
|
||||
private function placeOrder(ProductModel $product, StoreModel $store, int $quantity = 2, int $status = StoreOrderModel::STATUS_PENDING): StoreOrderModel
|
||||
{
|
||||
$this->actingAsMiniUser($user);
|
||||
$this->actingAsMiniStore($store);
|
||||
$this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => $quantity]]])
|
||||
->assertOk()->assertJsonPath('success', true);
|
||||
|
||||
$order = StoreOrderModel::where('store_id', $user->store_id)->latest('id')->first();
|
||||
$order = StoreOrderModel::where('store_id', $store->id)->latest('id')->first();
|
||||
$this->assertNotNull($order);
|
||||
if ($status !== StoreOrderModel::STATUS_PENDING) {
|
||||
$order->update(['status' => $status]);
|
||||
@@ -80,9 +80,8 @@ class StoreOrderItemTest extends ProcurementTestCase
|
||||
'shelf_life' => 30,
|
||||
'cost_price' => '4.00',
|
||||
]);
|
||||
$user = UserModel::factory()->forStore($store->id)->create();
|
||||
|
||||
$this->actingAsMiniUser($user);
|
||||
$this->actingAsMiniStore($store);
|
||||
$this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => 3]]])
|
||||
->assertOk()->assertJsonPath('success', true);
|
||||
|
||||
@@ -100,10 +99,10 @@ class StoreOrderItemTest extends ProcurementTestCase
|
||||
/** 小程序订单详情不泄漏成本价 */
|
||||
public function test_mini_detail_hides_cost_price(): void
|
||||
{
|
||||
[, $product, $user] = $this->makeStoreWithProduct('5.00', '4.00');
|
||||
$order = $this->placeOrder($product, $user);
|
||||
[$store, $product] = $this->makeStoreWithProduct('5.00', '4.00');
|
||||
$order = $this->placeOrder($product, $store);
|
||||
|
||||
$this->actingAsMiniUser($user);
|
||||
$this->actingAsMiniStore($store);
|
||||
$this->getJson("/mini/order/{$order->id}")
|
||||
->assertOk()
|
||||
->assertJsonPath('success', true)
|
||||
@@ -114,9 +113,9 @@ class StoreOrderItemTest extends ProcurementTestCase
|
||||
public function test_admin_detail_shows_cost_price_and_supplier(): void
|
||||
{
|
||||
$supplier = SupplierModel::factory()->create();
|
||||
[, $product, $user] = $this->makeStoreWithProduct('5.00', '4.00');
|
||||
[$store, $product] = $this->makeStoreWithProduct('5.00', '4.00');
|
||||
$product->update(['supplier_id' => $supplier->id]);
|
||||
$order = $this->placeOrder($product, $user);
|
||||
$order = $this->placeOrder($product, $store);
|
||||
|
||||
$this->actingAsSysUser();
|
||||
$this->getJson("/order/store/{$order->id}")
|
||||
@@ -130,8 +129,8 @@ class StoreOrderItemTest extends ProcurementTestCase
|
||||
/** 采购单内修改门店单品:重算单品金额与订单/采购单汇总 */
|
||||
public function test_update_store_item_recalculates_totals(): void
|
||||
{
|
||||
[$store, $product, $user] = $this->makeStoreWithProduct('5.00');
|
||||
$order = $this->placeOrder($product, $user, 2, StoreOrderModel::STATUS_SUMMARIZED);
|
||||
[$store, $product] = $this->makeStoreWithProduct('5.00');
|
||||
$order = $this->placeOrder($product, $store, 2, StoreOrderModel::STATUS_SUMMARIZED);
|
||||
$item = $order->items->first();
|
||||
$purchase = $this->generatePurchase();
|
||||
|
||||
@@ -162,10 +161,9 @@ class StoreOrderItemTest extends ProcurementTestCase
|
||||
/** 采购单已完成:门店单品增删改均拒绝,明细不变 */
|
||||
public function test_store_item_edits_rejected_when_purchase_completed(): void
|
||||
{
|
||||
[, $product, $user] = $this->makeStoreWithProduct('5.00');
|
||||
$order = $this->placeOrder($product, $user, 1, StoreOrderModel::STATUS_SUMMARIZED);
|
||||
[$store, $product] = $this->makeStoreWithProduct('5.00');
|
||||
$order = $this->placeOrder($product, $store, 1, StoreOrderModel::STATUS_SUMMARIZED);
|
||||
$purchase = $this->generatePurchase();
|
||||
$store = StoreModel::find($order->store_id);
|
||||
|
||||
$purchase->update(['status' => PurchaseOrderModel::STATUS_COMPLETED]);
|
||||
$this->actingAsSysUser();
|
||||
@@ -182,15 +180,15 @@ class StoreOrderItemTest extends ProcurementTestCase
|
||||
->assertJsonPath('success', false);
|
||||
|
||||
$item = $order->items->first();
|
||||
$this->assertSame(1, $item->fresh()->quantity, '被拒绝后明细不变');
|
||||
$this->assertSame('5.00', (string) $order->fresh()->total_amount, '被拒绝后总金额不变');
|
||||
$this->assertSame(1, $item->refresh()->quantity, '被拒绝后明细不变');
|
||||
$this->assertSame('5.00', (string) $order->refresh()->total_amount, '被拒绝后总金额不变');
|
||||
}
|
||||
|
||||
/** 修改门店单品参数校验:负单价/负数量被拦截 */
|
||||
public function test_update_store_item_validates_negative_values(): void
|
||||
{
|
||||
[$store, $product, $user] = $this->makeStoreWithProduct('5.00');
|
||||
$this->placeOrder($product, $user, 1, StoreOrderModel::STATUS_SUMMARIZED);
|
||||
[$store, $product] = $this->makeStoreWithProduct('5.00');
|
||||
$this->placeOrder($product, $store, 1, StoreOrderModel::STATUS_SUMMARIZED);
|
||||
$purchase = $this->generatePurchase();
|
||||
|
||||
$this->actingAsSysUser();
|
||||
@@ -215,9 +213,8 @@ class StoreOrderItemTest extends ProcurementTestCase
|
||||
$store = StoreModel::factory()->create(['level_id' => $level->id]);
|
||||
$product = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'cost_price' => '10.00']);
|
||||
$extra = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'cost_price' => '20.00']);
|
||||
$user = UserModel::factory()->forStore($store->id)->create();
|
||||
|
||||
$this->placeOrder($product, $user, 2, StoreOrderModel::STATUS_SUMMARIZED);
|
||||
$this->placeOrder($product, $store, 2, StoreOrderModel::STATUS_SUMMARIZED);
|
||||
$purchase = $this->generatePurchase();
|
||||
|
||||
$this->actingAsSysUser();
|
||||
@@ -237,8 +234,8 @@ class StoreOrderItemTest extends ProcurementTestCase
|
||||
/** 新增单品:商品已删除时拒绝 */
|
||||
public function test_add_store_item_rejected_when_product_deleted(): void
|
||||
{
|
||||
[$store, $product, $user] = $this->makeStoreWithProduct('5.00');
|
||||
$this->placeOrder($product, $user, 1, StoreOrderModel::STATUS_SUMMARIZED);
|
||||
[$store, $product] = $this->makeStoreWithProduct('5.00');
|
||||
$this->placeOrder($product, $store, 1, StoreOrderModel::STATUS_SUMMARIZED);
|
||||
$purchase = $this->generatePurchase();
|
||||
|
||||
$extra = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'cost_price' => '9.00']);
|
||||
@@ -258,12 +255,11 @@ class StoreOrderItemTest extends ProcurementTestCase
|
||||
{
|
||||
$level = CustomerLevelModel::factory()->create();
|
||||
$store = StoreModel::factory()->create(['level_id' => $level->id]);
|
||||
$user = UserModel::factory()->forStore($store->id)->create();
|
||||
|
||||
$cabbage = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'name' => '大白菜A', 'cost_price' => '5.00']);
|
||||
$potato = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'name' => '土豆B', 'cost_price' => '5.00']);
|
||||
$this->placeOrder($cabbage, $user);
|
||||
$this->placeOrder($potato, $user);
|
||||
$this->placeOrder($cabbage, $store);
|
||||
$this->placeOrder($potato, $store);
|
||||
|
||||
$this->actingAsSysUser();
|
||||
$response = $this->getJson('/order/store?product_name=' . urlencode('白菜'));
|
||||
|
||||
Reference in New Issue
Block a user