feat(card): 新增骆驼加油卡密类别及相关业务逻辑
- 新增 CardRedeemAccountCategoryCamelOil 类型及名称映射 - 修改绑定 Token 查询变量名避免变量覆盖 - 优化苹果订单推送中备注字段命名,区分订单和操作备注 - 修复苹果订单支付异常处理中的备注赋值错误 - 在骆驼加油卡密消费时同步更新商户消费记录 - 调整骆驼加油相关代码,完善订单绑定及状态处理逻辑
This commit is contained in:
@@ -8,6 +8,7 @@ const (
|
||||
CardRedeemAccountCategoryApple CardRedeemAccountCategory = "apple"
|
||||
CardRedeemAccountCategoryOriginalJD CardRedeemAccountCategory = "originalJD"
|
||||
CardRedeemAccountCategoryCTrip CardRedeemAccountCategory = "cTrip"
|
||||
CardRedeemAccountCategoryCamelOil CardRedeemAccountCategory = "camelOil"
|
||||
)
|
||||
|
||||
func (c CardRedeemAccountCategory) Name() string {
|
||||
@@ -20,8 +21,12 @@ func (c CardRedeemAccountCategory) Name() string {
|
||||
return "苹果"
|
||||
case CardRedeemAccountCategoryCTrip:
|
||||
return "携程"
|
||||
case CardRedeemAccountCategoryCamelOil:
|
||||
return "骆驼加油"
|
||||
case CardRedeemAccountCategoryOriginalJD:
|
||||
return "京东"
|
||||
default:
|
||||
return "未知"
|
||||
return "未知错误"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +38,9 @@ var ChannelTypeList = []CardRedeemAccountCategory{
|
||||
CardRedeemAccountCategoryJD,
|
||||
CardRedeemAccountCategoryWalMart,
|
||||
CardRedeemAccountCategoryCTrip,
|
||||
CardRedeemAccountCategoryApple,
|
||||
CardRedeemAccountCategoryOriginalJD,
|
||||
CardRedeemAccountCategoryCamelOil,
|
||||
}
|
||||
|
||||
type RedeemAccountStatus int32
|
||||
|
||||
@@ -332,11 +332,11 @@ func (s *sCamelOil) CronCardBindingTask(ctx context.Context) error {
|
||||
|
||||
for _, order := range orders {
|
||||
// 检查是否有可用的 Token
|
||||
availableTokenCount, err := dao.V1CamelOilToken.Ctx(ctx).DB(config.GetDatabaseV1()).
|
||||
availableTokenCount, err2 := dao.V1CamelOilToken.Ctx(ctx).DB(config.GetDatabaseV1()).
|
||||
Where(dao.V1CamelOilToken.Columns().Status, consts.CamelOilTokenStatusAvailable).
|
||||
Count()
|
||||
|
||||
if err != nil || availableTokenCount == 0 {
|
||||
if err2 != nil || availableTokenCount == 0 {
|
||||
glog.Warningf(ctx, "无可用 Token,订单 ID: %d 无法绑定", order.Id)
|
||||
failCount++
|
||||
continue
|
||||
|
||||
@@ -2,6 +2,7 @@ package camel_oil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kami/internal/model"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
@@ -381,6 +382,16 @@ func (s *sCamelOil) BindCardToToken(ctx context.Context, orderId int64, cardNumb
|
||||
Value: gconv.Float64(amount),
|
||||
}).Data(dao.V1CamelOilToken.Columns().LastBindAt, gtime.Now()).Data(dao.V1CamelOilToken.Columns().LastUsedAt, gtime.Now()).Update()
|
||||
|
||||
//给商户加宽
|
||||
_, _ = service.SysUserPayment().Consumption(ctx, &model.SysUserPaymentRechargeOrConsumeInput{
|
||||
UserId: selectedToken.UserId,
|
||||
OrderNo: gconv.String(orderId),
|
||||
Amount: amount,
|
||||
Remark: "核销扣款",
|
||||
TransactionType: consts.UserPaymentRecordStatusConsume,
|
||||
Category: consts.CardRedeemAccountCategoryCamelOil,
|
||||
}, nil)
|
||||
|
||||
glog.Infof(ctx, "卡密绑定成功: bindingId=%d, tokenId=%d, 订单ID=%d, 绑定金额=%.2f",
|
||||
bindingId, selectedToken.Id, orderId, amount.InexactFloat64())
|
||||
|
||||
|
||||
@@ -162,16 +162,19 @@ func (h *sAppleOrder) handleRedeemSuccess(ctx context.Context, orderEntity *enti
|
||||
// 判断金额是否一致
|
||||
var orderStatus consts.AppleRechargeOrderStatus
|
||||
var historyOperation consts.AppleOrderOperation
|
||||
var remark string
|
||||
var orderRemark string
|
||||
var orderOperationRemark string
|
||||
|
||||
if amount == orderEntity.CardAmount {
|
||||
orderStatus = consts.AppleRechargeOrderSuccess
|
||||
historyOperation = consts.AppleRechargeOperationItunesSucceed
|
||||
remark = fmt.Sprintf("充值成功:使用卡密【%s】为账号【%s】充值【%.2f】元,卡密已核销成功,余额【%.2f】", orderEntity.CardPass, accountInfo.Account, amount, balanceAfter)
|
||||
orderRemark = "核销成功"
|
||||
orderOperationRemark = fmt.Sprintf("充值成功:使用卡密【%s】为账号【%s】充值【%.2f】元,卡密已核销成功,余额【%.2f】", orderEntity.CardPass, accountInfo.Account, amount, balanceAfter)
|
||||
} else {
|
||||
orderStatus = consts.AppleRechargeOrderAmountDifferent
|
||||
historyOperation = consts.AppleRechargeOperationItunesSucceedButWrongAmount
|
||||
remark = fmt.Sprintf("充值失败:使用卡密【%s】为账号【%s】充值时,拉单金额【%.2f】与实际金额【%.2f】不一致,卡密已核销成功,因为金额不一致,所以订单不给回调.", orderEntity.CardPass, accountInfo.Account, orderEntity.CardAmount, amount)
|
||||
orderRemark = fmt.Sprintf("金额不一致,拉单金额%.2f元,实际金额%.2f元", orderEntity.CardAmount, amount)
|
||||
orderOperationRemark = fmt.Sprintf("充值失败:使用卡密【%s】为账号【%s】充值时,拉单金额【%.2f】与实际金额【%.2f】不一致,卡密已核销成功,因为金额不一致,所以订单不给回调.", orderEntity.CardPass, accountInfo.Account, orderEntity.CardAmount, amount)
|
||||
}
|
||||
|
||||
// 更新订单和账户余额
|
||||
@@ -180,10 +183,10 @@ func (h *sAppleOrder) handleRedeemSuccess(ctx context.Context, orderEntity *enti
|
||||
OrderNo: orderEntity.OrderNo,
|
||||
Amount: amount,
|
||||
Status: orderStatus,
|
||||
Remark: remark,
|
||||
Remark: orderRemark,
|
||||
},
|
||||
AccountId: accountInfo.Id,
|
||||
HistoryRemark: remark,
|
||||
HistoryRemark: orderOperationRemark,
|
||||
HistoryOperation: historyOperation,
|
||||
BalanceFromItunes: balanceAfter,
|
||||
})
|
||||
@@ -374,14 +377,14 @@ func (h *sAppleOrder) handleCardCodeError(ctx context.Context, orderEntity *enti
|
||||
func (h *sAppleOrder) handleBalanceAnomalyError(ctx context.Context, orderEntity *entity.V1CardAppleRechargeInfo, accountInfo *entity.V1CardAppleAccountInfo, diffAmount float64, itunesBalance float64) error {
|
||||
var orderStatus consts.AppleRechargeOrderStatus
|
||||
var historyOperation consts.AppleOrderOperation
|
||||
//var orderRemark string
|
||||
var orderRemark string
|
||||
|
||||
if diffAmount == orderEntity.CardAmount {
|
||||
//orderRemark = "支付成功"
|
||||
orderRemark = "支付成功"
|
||||
historyOperation = consts.AppleRechargeOperationItunesSucceed
|
||||
orderStatus = consts.AppleRechargeOrderSuccess
|
||||
} else {
|
||||
//orderRemark = fmt.Sprintf("金额不一致,拉单金额%.2f元,实际金额%.2f元", orderEntity.CardAmount, diffAmount)
|
||||
orderRemark = fmt.Sprintf("金额不一致,拉单金额%.2f元,实际金额%.2f元", orderEntity.CardAmount, diffAmount)
|
||||
historyOperation = consts.AppleRechargeOperationItunesSucceedButWrongAmount
|
||||
orderStatus = consts.AppleRechargeOrderAmountDifferent
|
||||
}
|
||||
@@ -394,7 +397,7 @@ func (h *sAppleOrder) handleBalanceAnomalyError(ctx context.Context, orderEntity
|
||||
OrderNo: orderEntity.OrderNo,
|
||||
Amount: diffAmount,
|
||||
Status: orderStatus,
|
||||
Remark: operationRemark,
|
||||
Remark: orderRemark,
|
||||
},
|
||||
AccountId: accountInfo.Id,
|
||||
HistoryRemark: operationRemark,
|
||||
|
||||
Reference in New Issue
Block a user