售后金额
This commit is contained in:
@@ -72,7 +72,7 @@ class BillPaymentTest extends ProcurementTestCase
|
||||
], $attributes));
|
||||
}
|
||||
|
||||
/** 生成账单:按门店保存售后说明与备注(可选,不参与金额计算) */
|
||||
/** 生成账单:按门店保存售后金额(可正负,计入总金额)与备注(仅存档不参与计算) */
|
||||
public function test_generate_bill_saves_after_sale_and_remark(): void
|
||||
{
|
||||
$level = CustomerLevelModel::factory()->create();
|
||||
@@ -97,17 +97,17 @@ class BillPaymentTest extends ProcurementTestCase
|
||||
'delivery_fee' => 0,
|
||||
'box_num' => 0,
|
||||
'tray_num' => 0,
|
||||
'after_sale' => '白菜烂叶 2 斤已协商',
|
||||
'remark' => '下次配送顺带回收筐',
|
||||
'after_sale' => -5.5,
|
||||
'remark' => '白菜烂叶 2 斤已协商',
|
||||
]],
|
||||
])->assertJsonPath('success', true);
|
||||
|
||||
$bill = BillModel::where('store_id', $store->id)->first();
|
||||
$this->assertSame('白菜烂叶 2 斤已协商', $bill->after_sale);
|
||||
$this->assertSame('下次配送顺带回收筐', $bill->remark);
|
||||
$this->assertSame('20.00', (string) $bill->total_amount, '售后/备注不影响金额');
|
||||
$this->assertSame('-5.50', (string) $bill->after_sale);
|
||||
$this->assertSame('白菜烂叶 2 斤已协商', $bill->remark);
|
||||
$this->assertSame('14.50', (string) $bill->total_amount, '总金额 = 商品 20.00 + 售后金额 -5.50');
|
||||
|
||||
// 不传售后/备注时默认空字符串
|
||||
// 不传售后金额时按 0 计入,备注默认空字符串
|
||||
$store2 = StoreModel::factory()->create(['level_id' => $level->id]);
|
||||
$this->actingAsMiniStore($store2);
|
||||
$this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => 1]]])
|
||||
@@ -125,8 +125,65 @@ class BillPaymentTest extends ProcurementTestCase
|
||||
])->assertJsonPath('success', true);
|
||||
|
||||
$bill2 = BillModel::where('store_id', $store2->id)->first();
|
||||
$this->assertSame('', (string) $bill2->after_sale);
|
||||
$this->assertSame('0.00', (string) $bill2->after_sale);
|
||||
$this->assertSame('', (string) $bill2->remark);
|
||||
$this->assertSame('5.00', (string) $bill2->total_amount, '未传售后金额不影响总金额');
|
||||
}
|
||||
|
||||
/** 生成账单:售后金额为正数时加收计入总金额 */
|
||||
public function test_generate_bill_positive_after_sale_added_to_total(): void
|
||||
{
|
||||
[$store, , $bill] = $this->makeBillViaChain();
|
||||
$this->assertSame('20.00', (string) $bill->total_amount, '基线:无售后金额时总额=商品金额');
|
||||
|
||||
// 重新走一条链:售后金额 +8.00,配送费 2.00 → 总额 20 + 2 + 8 = 30.00
|
||||
$level = CustomerLevelModel::factory()->create();
|
||||
$store2 = StoreModel::factory()->create(['level_id' => $level->id]);
|
||||
$product = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'cost_price' => '5.00']);
|
||||
|
||||
$this->actingAsMiniStore($store2);
|
||||
$this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => 4]]])
|
||||
->assertJsonPath('success', true);
|
||||
$order2 = StoreOrderModel::where('store_id', $store2->id)->first();
|
||||
|
||||
$this->actingAsSysUser();
|
||||
$this->putJson("/order/store/{$order2->id}/status", ['status' => StoreOrderModel::STATUS_SUMMARIZED]);
|
||||
$this->postJson('/purchase/order/generate', ['purchase_date' => now()->toDateString()])
|
||||
->assertJsonPath('success', true);
|
||||
$purchase2 = PurchaseOrderModel::latest('id')->first();
|
||||
$this->putJson("/purchase/order/{$purchase2->id}/finish")->assertJsonPath('success', true);
|
||||
$this->postJson("/purchase/order/{$purchase2->id}/bill", [
|
||||
'stores' => [[
|
||||
'store_id' => $store2->id,
|
||||
'delivery_fee' => 2,
|
||||
'box_num' => 0,
|
||||
'tray_num' => 0,
|
||||
'after_sale' => 8,
|
||||
]],
|
||||
])->assertJsonPath('success', true);
|
||||
|
||||
$bill2 = BillModel::where('store_id', $store2->id)->first();
|
||||
$this->assertSame('8.00', (string) $bill2->after_sale);
|
||||
$this->assertSame('30.00', (string) $bill2->total_amount, '总金额 = 商品 20.00 + 配送费 2.00 + 售后金额 8.00');
|
||||
}
|
||||
|
||||
/** 生成账单:售后金额非数值 → 拒绝 */
|
||||
public function test_generate_bill_rejects_non_numeric_after_sale(): void
|
||||
{
|
||||
$level = CustomerLevelModel::factory()->create();
|
||||
$store = StoreModel::factory()->create(['level_id' => $level->id]);
|
||||
$this->actingAsSysUser();
|
||||
$purchase = PurchaseOrderModel::factory()->create(['status' => PurchaseOrderModel::STATUS_COMPLETED]);
|
||||
|
||||
$this->postJson("/purchase/order/{$purchase->id}/bill", [
|
||||
'stores' => [[
|
||||
'store_id' => $store->id,
|
||||
'delivery_fee' => 0,
|
||||
'box_num' => 0,
|
||||
'tray_num' => 0,
|
||||
'after_sale' => '白菜烂叶 2 斤已协商',
|
||||
]],
|
||||
])->assertJsonPath('success', false);
|
||||
}
|
||||
|
||||
/** 订单状态随业务链自动推进:接单→采购中→配送中→(生成账单)已完成 */
|
||||
|
||||
Reference in New Issue
Block a user