完善商城订单模拟快照与空值展示
This commit is contained in:
@@ -312,14 +312,18 @@ func MockData(database *gorm.DB) error {
|
||||
|
||||
ecOrder := models.EcOrder{
|
||||
Entity: entity(30, common.StatusEnable), OrderStatus: mockEcOrderPaidStatus(), OrderNo: "MOCK-ECORDER-001",
|
||||
UserAccountID: user.ID, GasStationID: gas.ID, DeliveryPointID: delivery.ID,
|
||||
RequestNo: "MOCK-REQ-ECORDER-001", UserAccountID: user.ID,
|
||||
GasStationID: gas.ID, DeliveryPointID: delivery.ID, UserAddressID: address.ID,
|
||||
Address: address.Address, Longitude: address.Longitude, Latitude: address.Latitude,
|
||||
ContactName: user.Name, ContactPhone: user.Phone, Remark: "模拟已支付商城订单",
|
||||
ProductAmount: ecProduct.PriceAmount, PayableAmount: ecProduct.PriceAmount,
|
||||
TotalAmount: ecProduct.PriceAmount, PaidAt: &now,
|
||||
}
|
||||
desiredEcOrder := ecOrder
|
||||
if err := put(tx, &ecOrder); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := repairMockEcOrder(tx, ecOrder, mockEcOrderPaidStatus(), ecProduct.PriceAmount, &now); err != nil {
|
||||
if err := repairMockEcOrder(tx, desiredEcOrder, mockEcOrderPaidStatus(), ecProduct.PriceAmount, &now); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -728,15 +732,19 @@ func seedAdditionalCoreScenarios(database *gorm.DB, passwordHash string, now tim
|
||||
|
||||
ecOrder := models.EcOrder{
|
||||
Entity: entity(sequence+16, common.StatusEnable), OrderStatus: mockEcOrderPendingStatus(),
|
||||
OrderNo: "MOCK-ECORDER-" + suffix, UserAccountID: user.ID,
|
||||
GasStationID: gas.ID, DeliveryPointID: delivery.ID,
|
||||
OrderNo: "MOCK-ECORDER-" + suffix, RequestNo: "MOCK-REQ-ECORDER-" + suffix,
|
||||
UserAccountID: user.ID, GasStationID: gas.ID, DeliveryPointID: delivery.ID,
|
||||
UserAddressID: address.ID, Address: address.Address,
|
||||
Longitude: address.Longitude, Latitude: address.Latitude,
|
||||
ContactName: user.Name, ContactPhone: user.Phone, Remark: "模拟待支付商城订单",
|
||||
ProductAmount: ecProduct.PriceAmount, PayableAmount: ecProduct.PriceAmount,
|
||||
TotalAmount: ecProduct.PriceAmount,
|
||||
}
|
||||
desiredEcOrder := ecOrder
|
||||
if err := put(database, &ecOrder); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := repairMockEcOrder(database, ecOrder, mockEcOrderPendingStatus(), ecProduct.PriceAmount, nil); err != nil {
|
||||
if err := repairMockEcOrder(database, desiredEcOrder, mockEcOrderPendingStatus(), ecProduct.PriceAmount, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -786,7 +794,11 @@ func repairMockEcOrder(database *gorm.DB, order models.EcOrder, status int, amou
|
||||
Where("identity = ? AND order_no LIKE ?", order.Identity, "MOCK-ECORDER-%").
|
||||
Updates(map[string]any{
|
||||
"order_status": status, "product_amount": amount, "payable_amount": amount,
|
||||
"total_amount": amount, "paid_at": paidAt,
|
||||
"total_amount": amount, "paid_at": paidAt, "request_no": order.RequestNo,
|
||||
"user_address_id": order.UserAddressID, "address": order.Address,
|
||||
"longitude": order.Longitude, "latitude": order.Latitude,
|
||||
"contact_name": order.ContactName, "contact_phone": order.ContactPhone,
|
||||
"remark": order.Remark,
|
||||
})
|
||||
if result.Error != nil {
|
||||
return fmt.Errorf("repair mock ec order: %w", result.Error)
|
||||
@@ -795,30 +807,57 @@ func repairMockEcOrder(database *gorm.DB, order models.EcOrder, status int, amou
|
||||
}
|
||||
|
||||
type mockEcOrderRepairSpec struct {
|
||||
identity string
|
||||
orderNo string
|
||||
status int
|
||||
amount int64
|
||||
paidAt *time.Time
|
||||
identity string
|
||||
orderNo string
|
||||
requestNo string
|
||||
userIdentity string
|
||||
addressIdentity string
|
||||
contactName string
|
||||
contactPhone string
|
||||
address string
|
||||
longitude string
|
||||
latitude string
|
||||
status int
|
||||
amount int64
|
||||
paidAt *time.Time
|
||||
remark string
|
||||
}
|
||||
|
||||
// mockEcOrderRepairSpecs 返回固定 Mock 商城订单的文档化交易状态与金额。
|
||||
func mockEcOrderRepairSpecs() []mockEcOrderRepairSpec {
|
||||
paidAt := time.Date(2026, time.July, 1, 9, 0, 0, 0, time.Local)
|
||||
specs := []mockEcOrderRepairSpec{{
|
||||
identity: entity(30, common.StatusEnable).Identity,
|
||||
orderNo: "MOCK-ECORDER-001",
|
||||
status: mockEcOrderPaidStatus(),
|
||||
amount: 10300,
|
||||
paidAt: &paidAt,
|
||||
identity: entity(30, common.StatusEnable).Identity,
|
||||
orderNo: "MOCK-ECORDER-001",
|
||||
requestNo: "MOCK-REQ-ECORDER-001",
|
||||
userIdentity: entity(7, common.StatusEnable).Identity,
|
||||
addressIdentity: entity(8, common.StatusEnable).Identity,
|
||||
contactName: "陈女士",
|
||||
contactPhone: "13800000001",
|
||||
address: "上海市浦东新区客户路 88 号",
|
||||
longitude: "121.5500",
|
||||
latitude: "31.2250",
|
||||
status: mockEcOrderPaidStatus(),
|
||||
amount: 10300,
|
||||
paidAt: &paidAt,
|
||||
remark: "模拟已支付商城订单",
|
||||
}}
|
||||
for scenario := 2; scenario <= 10; scenario++ {
|
||||
sequence := 1000 + scenario*100
|
||||
specs = append(specs, mockEcOrderRepairSpec{
|
||||
identity: entity(sequence+16, common.StatusEnable).Identity,
|
||||
orderNo: fmt.Sprintf("MOCK-ECORDER-%03d", scenario),
|
||||
status: mockEcOrderPendingStatus(),
|
||||
amount: int64(9500 + scenario*100),
|
||||
identity: entity(sequence+16, common.StatusEnable).Identity,
|
||||
orderNo: fmt.Sprintf("MOCK-ECORDER-%03d", scenario),
|
||||
requestNo: fmt.Sprintf("MOCK-REQ-ECORDER-%03d", scenario),
|
||||
userIdentity: entity(sequence+4, common.StatusEnable).Identity,
|
||||
addressIdentity: entity(sequence+5, common.StatusEnable).Identity,
|
||||
contactName: fmt.Sprintf("示例客户%d", scenario),
|
||||
contactPhone: "138" + fmt.Sprintf("%08d", scenario),
|
||||
address: fmt.Sprintf("上海市客户路 %d 号", scenario),
|
||||
longitude: fmt.Sprintf("121.5%03d", scenario),
|
||||
latitude: fmt.Sprintf("31.2%03d", scenario),
|
||||
status: mockEcOrderPendingStatus(),
|
||||
amount: int64(9500 + scenario*100),
|
||||
remark: "模拟待支付商城订单",
|
||||
})
|
||||
}
|
||||
return specs
|
||||
@@ -829,12 +868,34 @@ func RepairMockEcOrders(database *gorm.DB) (int64, error) {
|
||||
var repaired int64
|
||||
err := database.Transaction(func(tx *gorm.DB) error {
|
||||
for _, spec := range mockEcOrderRepairSpecs() {
|
||||
var user models.UserAccount
|
||||
if err := tx.Where("identity = ?", spec.userIdentity).First(&user).Error; err != nil {
|
||||
return fmt.Errorf("load mock ec order user %s: %w", spec.orderNo, err)
|
||||
}
|
||||
if err := tx.Model(&user).Updates(map[string]any{
|
||||
"name": spec.contactName, "phone": spec.contactPhone,
|
||||
}).Error; err != nil {
|
||||
return fmt.Errorf("repair mock ec order user %s: %w", spec.orderNo, err)
|
||||
}
|
||||
var address models.UserAddress
|
||||
if err := tx.Where("identity = ?", spec.addressIdentity).First(&address).Error; err != nil {
|
||||
return fmt.Errorf("load mock ec order address %s: %w", spec.orderNo, err)
|
||||
}
|
||||
if err := tx.Model(&address).Updates(map[string]any{
|
||||
"address": spec.address, "longitude": spec.longitude, "latitude": spec.latitude,
|
||||
}).Error; err != nil {
|
||||
return fmt.Errorf("repair mock ec order address %s: %w", spec.orderNo, err)
|
||||
}
|
||||
result := tx.Model(&models.EcOrder{}).
|
||||
Where("identity = ? AND order_no = ?", spec.identity, spec.orderNo).
|
||||
Updates(map[string]any{
|
||||
"order_status": spec.status, "product_amount": spec.amount,
|
||||
"payable_amount": spec.amount, "total_amount": spec.amount,
|
||||
"paid_at": spec.paidAt,
|
||||
"paid_at": spec.paidAt, "request_no": spec.requestNo,
|
||||
"user_address_id": address.ID, "address": spec.address,
|
||||
"longitude": spec.longitude, "latitude": spec.latitude,
|
||||
"contact_name": spec.contactName, "contact_phone": spec.contactPhone,
|
||||
"remark": spec.remark,
|
||||
})
|
||||
if result.Error != nil {
|
||||
return fmt.Errorf("repair mock ec order %s: %w", spec.orderNo, result.Error)
|
||||
|
||||
Reference in New Issue
Block a user