Browse Source

Merge remote-tracking branch 'origin/master'

master
huangjiajun 5 days ago
parent
commit
c5cf32d191
3 changed files with 64 additions and 4 deletions
  1. +6
    -3
      enum/user_virtual_amount_flow.go
  2. +7
    -1
      rule/egg_energy/md/mq_egg_app.go
  3. +51
    -0
      rule/user_virtual_coin.go

+ 6
- 3
enum/user_virtual_amount_flow.go View File

@@ -20,7 +20,8 @@ const (
EggEnergyPlayletRewardPersonalActiveCoin
EggEnergyWatchAdRewardFansActiveCoin
EggEnergyRecruitNewUsersReward
EggEnergyMaliciousAccountFlashingDeduction
EggEnergyMaliciousAccountFlashingDeductionPersonal
EggEnergyMaliciousAccountFlashingDeductionTeam
)

func (kind UserVirtualAmountFlowTransferType) String() string {
@@ -57,8 +58,10 @@ func (kind UserVirtualAmountFlowTransferType) String() string {
return "粉丝奖励" //浏览视频奖励-直推奖励蛋蛋积分
case EggEnergyRecruitNewUsersReward:
return "拉新奖励"
case EggEnergyMaliciousAccountFlashingDeduction:
return "恶意账户刷机扣除"
case EggEnergyMaliciousAccountFlashingDeductionPersonal:
return "恶意账户刷机个人蛋蛋能量扣除"
case EggEnergyMaliciousAccountFlashingDeductionTeam:
return "恶意账户刷机团队蛋蛋能量扣除"

default:
return "未知状态"


+ 7
- 1
rule/egg_energy/md/mq_egg_app.go View File

@@ -10,7 +10,8 @@ const (
EggRoutKeyForRecordActive = "egg_record_active" // 更新活跃记录
EggRoutKeyForAutoScoreData = "egg_auto_score" // 自动打分
EggRoutKeyForSendFriendCircle = "egg_send_friend_circle" // 发送朋友圈
EggRoutKeyForComment = "egg_comment" // 发送朋友圈
EggRoutKeyForComment = "egg_comment" // 评论
EggRoutKeyForPunishmentRecord = "egg_publish" // 处罚冻结用户上级
)

type EggNewUserRegisterData struct {
@@ -79,3 +80,8 @@ type EggSendFriendCircleData struct {
type EggCommentData struct {
Uid int64 `json:"uid"`
}

type EggRoutKeyForPunishmentRecordData struct {
Uid int64 `json:"uid"`
Amount string `json:"amount"`
}

+ 51
- 0
rule/user_virtual_coin.go View File

@@ -91,6 +91,57 @@ func DealUserVirtualCoin(session *xorm.Session, req md.DealUserVirtualCoinReq) (
return nil
}

// DealUserVirtualCoinMinus 处理给用户虚拟币积分(可以扣到负数)
func DealUserVirtualCoinMinus(session *xorm.Session, req md.DealUserVirtualCoinReq) (err error) {
if req.Amount < 0 {
req.Amount = 0
}

//2、计算&&组装数据
now := time.Now()
coinAmount, err := GetUserCoinAmount(session, req.CoinId, req.Uid)
if err != nil {
return err
}
coinAmountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(coinAmount))
amountValue := decimal.NewFromFloat(req.Amount).RoundFloor(4)

var userVirtualCoinFlow model.UserVirtualCoinFlow
userVirtualCoinFlow.CoinId = req.CoinId
userVirtualCoinFlow.Title = req.Title
userVirtualCoinFlow.TransferType = req.TransferType
userVirtualCoinFlow.Uid = req.Uid
userVirtualCoinFlow.BeforeAmount = coinAmount
userVirtualCoinFlow.Amount = amountValue.String()
userVirtualCoinFlow.CreateAt = now.Format("2006-01-02 15:04:05")

if req.Kind == "add" {
userVirtualCoinFlow.Direction = 1
userVirtualCoinFlow.AfterAmount = coinAmountValue.Add(amountValue).RoundFloor(8).String()
} else if req.Kind == "sub" {
userVirtualCoinFlow.Direction = 2
userVirtualCoinFlow.AfterAmount = coinAmountValue.Sub(amountValue).RoundFloor(8).String()
} else {
err = errors.New("错误的kind类型")
return err
}

//3、插入 `user_virtual_coin_flow` 记录
userVirtualCoinFlowDb := implement.NewUserVirtualCoinFlowDb(session.Engine())
_, err = userVirtualCoinFlowDb.UserVirtualCoinFlowInsertBySession(session, &userVirtualCoinFlow)
if err != nil {
return err
}

//4、修改 `user_virtual_amount`的amount值 && 及缓存
err = SetCacheUserVirtualAmount(session, userVirtualCoinFlow.AfterAmount, req.CoinId, req.Uid, true)
if err != nil {
return err
}

return nil
}

// GetUserCoinAmount 获取用户虚拟积分余额
func GetUserCoinAmount(session *xorm.Session, coinId int, uid int64) (amount string, err error) {
redisKey := fmt.Sprintf(md.UserVirtualAmountRedisKey, coinId, uid)


Loading…
Cancel
Save