商户管理优化, 商户只能上架下架, 管理员可以编辑

This commit is contained in:
yml2213
2026-08-04 14:35:53 +08:00
parent 6404b10626
commit 16b508eb9b
8 changed files with 202 additions and 196 deletions
@@ -723,6 +723,32 @@ func TestCreateOrderRejectsInsufficientBalance(t *testing.T) {
}
}
func TestCreateOrderRejectsInactiveProduct(t *testing.T) {
db := newServiceTestDB(t)
merchantID, product := seedFulfillmentMerchant(t, db, "merchant-inactive-product", 5000, 1, 100)
svc := NewFulfillmentService(db, nil)
// 商户下架商品后:开放接口下单与商户测试订单都应被拒绝
if err := db.Model(&model.MerchantProduct{}).Where("id = ?", product.ID).Update("status", model.ProductStatusInactive).Error; err != nil {
t.Fatalf("deactivate product: %v", err)
}
if _, err := svc.CreateOrder(CreateFulfillmentOrderInput{
MerchantID: merchantID,
APIClientID: 16,
ClientOrderNo: "client-inactive-product",
SKU: product.SKU,
}); err == nil || !strings.Contains(err.Error(), "已下架") {
t.Fatalf("inactive product should reject order, got %v", err)
}
if _, err := svc.CreateTestOrder(CreateTestOrderInput{
MerchantID: merchantID,
ActorUserID: 99,
SKU: product.SKU,
}); err == nil || !strings.Contains(err.Error(), "已下架") {
t.Fatalf("inactive product should reject test order, got %v", err)
}
}
func TestCreateTestOrderCreatesFulfillableOrderWithoutBilling(t *testing.T) {
db := newServiceTestDB(t)
merchantID, product := seedFulfillmentMerchant(t, db, "merchant-test-order", 0, 0, 100)