修复换货迁移后 after_order 实名门槛误判
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Failing after 3m55s
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Failing after 3m55s
换货迁移只迁移套餐权益不迁移订单,已支付订单仍挂在旧资产上, 导致新资产 HasValidRechargeOrPaidOrder 查不到支付事实,返回 1189。 现增加套餐权益兜底:当前世代存在未退款套餐权益且其关联订单已支付, 即视为满足充值/购买条件。
This commit is contained in:
@@ -1387,9 +1387,34 @@ func (s *Service) HasValidRechargeOrPaidOrder(ctx context.Context, assetType str
|
||||
}
|
||||
}
|
||||
|
||||
if assetType == "card" || assetType == "device" {
|
||||
return s.hasPaidPackageUsage(ctx, assetType, assetID, generation)
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// hasPaidPackageUsage 检查资产在当前世代是否存在已支付订单购买且未退款的套餐权益
|
||||
// 换货迁移只迁移套餐权益不迁移订单,订单仍挂在旧资产上,需要按套餐权益兜底判定
|
||||
func (s *Service) hasPaidPackageUsage(ctx context.Context, assetType string, assetID uint, generation int) (bool, error) {
|
||||
assetColumn := "tb_package_usage.iot_card_id"
|
||||
if assetType == "device" {
|
||||
assetColumn = "tb_package_usage.device_id"
|
||||
}
|
||||
|
||||
var count int64
|
||||
err := s.db.WithContext(ctx).Model(&model.PackageUsage{}).
|
||||
Joins("JOIN tb_order ON tb_order.id = tb_package_usage.order_id AND tb_order.deleted_at IS NULL").
|
||||
Where(assetColumn+" = ? AND tb_package_usage.generation = ?", assetID, generation).
|
||||
Where("tb_package_usage.refund_id IS NULL").
|
||||
Where("tb_order.payment_status = ?", model.PaymentStatusPaid).
|
||||
Count(&count).Error
|
||||
if err != nil {
|
||||
return false, errors.Wrap(errors.CodeDatabaseError, err, "查询套餐权益订单失败")
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// packageStatusName 套餐状态码转中文名称
|
||||
func packageStatusName(status int) string {
|
||||
switch status {
|
||||
|
||||
Reference in New Issue
Block a user