售后金额上浮
This commit is contained in:
@@ -133,6 +133,56 @@ class BillPaymentTest extends ProcurementTestCase
|
||||
$this->assertSame('5.00', (string) $bill2->total_amount, '未传售后金额不影响总金额');
|
||||
}
|
||||
|
||||
/** 售后金额按客户等级上浮折算:输入 15、上浮 1% → 实收 15.15;billPrepare 回显等级(负数同比例放大) */
|
||||
public function test_generate_bill_after_sale_marked_up_by_level(): void
|
||||
{
|
||||
$level = CustomerLevelModel::factory()->create(['percent' => 1]);
|
||||
$store = StoreModel::factory()->create(['level_id' => $level->id]);
|
||||
$level2 = CustomerLevelModel::factory()->create(['percent' => 2]);
|
||||
$store2 = StoreModel::factory()->create(['level_id' => $level2->id]);
|
||||
$product = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'cost_price' => '5.00']);
|
||||
|
||||
// 两店各下一单:店1 等级价 5.05 × 4 = 20.20;店2 等级价 5.10 × 2 = 10.20
|
||||
foreach ([[$store, 4], [$store2, 2]] as [$s, $qty]) {
|
||||
$this->actingAsMiniStore($s);
|
||||
$this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => $qty]]])
|
||||
->assertJsonPath('success', true);
|
||||
}
|
||||
StoreOrderModel::query()->update(['status' => StoreOrderModel::STATUS_SUMMARIZED]);
|
||||
|
||||
$this->actingAsSysUser();
|
||||
$this->postJson('/purchase/order/generate', ['purchase_date' => now()->toDateString()])
|
||||
->assertJsonPath('success', true);
|
||||
$purchase = PurchaseOrderModel::first();
|
||||
$this->putJson("/purchase/order/{$purchase->id}/finish")->assertJsonPath('success', true);
|
||||
|
||||
// billPrepare 回显客户等级与上浮比例(弹窗预览用)
|
||||
$prepare = $this->getJson("/purchase/order/{$purchase->id}/bill/prepare")
|
||||
->assertJsonPath('success', true)
|
||||
->json('data.stores');
|
||||
$prepareByStore = collect($prepare)->keyBy('store_id');
|
||||
$this->assertSame($level->name, $prepareByStore[$store->id]['level_name']);
|
||||
$this->assertSame('1.00', (string) $prepareByStore[$store->id]['level_percent']);
|
||||
$this->assertSame($level2->name, $prepareByStore[$store2->id]['level_name']);
|
||||
$this->assertSame('2.00', (string) $prepareByStore[$store2->id]['level_percent']);
|
||||
|
||||
// 店1 售后 15 × 101% = 15.15;店2 售后 -10 × 102% = -10.20
|
||||
$this->postJson("/purchase/order/{$purchase->id}/bill", [
|
||||
'stores' => [
|
||||
['store_id' => $store->id, 'delivery_fee' => 0, 'box_num' => 0, 'tray_num' => 0, 'after_sale' => 15],
|
||||
['store_id' => $store2->id, 'delivery_fee' => 0, 'box_num' => 0, 'tray_num' => 0, 'after_sale' => -10],
|
||||
],
|
||||
])->assertJsonPath('success', true);
|
||||
|
||||
$bill = BillModel::where('store_id', $store->id)->first();
|
||||
$this->assertSame('15.15', (string) $bill->after_sale, '15 × 101%');
|
||||
$this->assertSame('35.35', (string) $bill->total_amount, '商品 20.20 + 售后 15.15');
|
||||
|
||||
$bill2 = BillModel::where('store_id', $store2->id)->first();
|
||||
$this->assertSame('-10.20', (string) $bill2->after_sale, '-10 × 102%(负数同比例放大)');
|
||||
$this->assertSame('0.00', (string) $bill2->total_amount, '商品 10.20 + 售后 -10.20');
|
||||
}
|
||||
|
||||
/** 生成账单:售后金额为正数时加收计入总金额 */
|
||||
public function test_generate_bill_positive_after_sale_added_to_total(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user