diff --git a/enum/user_virtual_amount_flow.go b/enum/user_virtual_amount_flow.go index ab5f150..959e94d 100644 --- a/enum/user_virtual_amount_flow.go +++ b/enum/user_virtual_amount_flow.go @@ -15,6 +15,7 @@ const ( PersonEggGetByTeamEggEnergyRelease SettlementStarLevelDividends EggEnergyToExchangeToAmount + EggPointCoinToAliPayRealName ) func (kind UserVirtualAmountFlowTransferType) String() string { @@ -41,6 +42,8 @@ func (kind UserVirtualAmountFlowTransferType) String() string { return "星级分红" case EggEnergyToExchangeToAmount: return "个人蛋蛋能量兑换余额" + case EggPointCoinToAliPayRealName: + return "个人蛋蛋积分实名认证" default: return "未知状态" } diff --git a/enum/withdraw_apply.go b/enum/withdraw_apply.go index ef14969..60ef7bc 100644 --- a/enum/withdraw_apply.go +++ b/enum/withdraw_apply.go @@ -61,9 +61,9 @@ const ( func (kind FinWithdrawApplyWithdrawKind) String() string { switch kind { case FinWithdrawApplyWithdrawKindForAli: - return "支付宝" + return "alipay" case FinWithdrawApplyWithdrawKindForWx: - return "微信" + return "wx" default: return "未知状态" } diff --git a/rule/egg_energy/give_activty_coin.go b/rule/egg_energy/give_activty_coin.go index 7597387..6b59556 100644 --- a/rule/egg_energy/give_activty_coin.go +++ b/rule/egg_energy/give_activty_coin.go @@ -14,6 +14,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/shopspring/decimal" "strings" "time" "xorm.io/xorm" @@ -223,6 +224,118 @@ func SettlementGiveActivityCoin(engine *xorm.Engine, uid int64, ch *rabbit.Chann return } +func ActivityCoinToAlipayRealName(engine *xorm.Engine, uid int64, amount string) (err error) { + amountValue, _ := decimal.NewFromString(amount) + + //1、查找 `egg_energy_basic_setting` 基础设置 + eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(engine) + eggEnergyBasicSetting, err := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ + "key": "is_open", + "value": 1, + }) + if err != nil { + return + } + if eggEnergyBasicSetting == nil { + err = errors.New("蛋蛋能量设置未开启!") + return + } + + var coin model.VirtualCoin + _, err = engine.Where("id = ?", eggEnergyBasicSetting.PersonEggPointsCoinId).Get(&coin) + if err != nil { + return + } + personActivePointsCoinExchangeRatioValue, _ := decimal.NewFromString(coin.ExchangeRatio) + + //2、判断个人蛋蛋积分是否足够 + var personUserVirtualAmount model.UserVirtualAmount + _, err = engine.Where("coin_id = ?", eggEnergyBasicSetting.PersonEggPointsCoinId).Get(&personUserVirtualAmount) + if err != nil { + fmt.Println("err:::::1111", err) + return + } + personUserVirtualAmountValue, _ := decimal.NewFromString(personUserVirtualAmount.Amount) + needVirtualAmountValue := amountValue.Mul(personActivePointsCoinExchangeRatioValue) + needVirtualAmount, _ := amountValue.Mul(personActivePointsCoinExchangeRatioValue).Float64() + if personUserVirtualAmountValue.LessThan(needVirtualAmountValue) { + err = errors.New("当前蛋蛋积分不足!") + return + } + + //3、扣除对应个人蛋蛋积分 + session := engine.NewSession() + defer func() { + session.Close() + if err := recover(); err != nil { + _ = zhios_order_relate_logx.Error(err) + } + }() + session.Begin() + + //给相应的用户加上"个人"活跃积分 + err = rule.DealUserVirtualCoin(session, md.DealUserVirtualCoinReq{ + Kind: "sub", + Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggPointCoinToAliPayRealName), + TransferType: int(enum.EggPointCoinToAliPayRealName), + CoinId: eggEnergyBasicSetting.PersonEggPointsCoinId, + Uid: uid, + Amount: needVirtualAmount, + }) + if err != nil { + _ = session.Rollback() + fmt.Println("err:::::2222", err) + return err + } + + err = session.Commit() + if err != nil { + _ = session.Rollback() + return errors.New("事务提交失败") + } + + return +} + +func CheckActivityCoinToAlipayRealName(engine *xorm.Engine, uid int64, amount string) (err error, isCan bool) { + amountValue, _ := decimal.NewFromString(amount) + + //1、查找 `egg_energy_basic_setting` 基础设置 + eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(engine) + eggEnergyBasicSetting, err := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ + "key": "is_open", + "value": 1, + }) + if err != nil { + return + } + if eggEnergyBasicSetting == nil { + err = errors.New("蛋蛋能量设置未开启!") + return + } + + var coin model.VirtualCoin + _, err = engine.Where("id = ?", eggEnergyBasicSetting.PersonEggPointsCoinId).Get(&coin) + if err != nil { + return + } + personActivePointsCoinExchangeRatioValue, _ := decimal.NewFromString(coin.ExchangeRatio) + + //2、判断个人蛋蛋积分是否足够 + var personUserVirtualAmount model.UserVirtualAmount + _, err = engine.Where("coin_id = ?", eggEnergyBasicSetting.PersonEggPointsCoinId).Get(&personUserVirtualAmount) + if err != nil { + fmt.Println("err:::::1111", err) + return + } + personUserVirtualAmountValue, _ := decimal.NewFromString(personUserVirtualAmount.Amount) + needVirtualAmountValue := amountValue.Mul(personActivePointsCoinExchangeRatioValue) + if personUserVirtualAmountValue.GreaterThan(needVirtualAmountValue) { + isCan = true + } + return +} + // CalcUserContinuousDailyActivityDays 计算用户连续活跃天数 func CalcUserContinuousDailyActivityDays(engine *xorm.Engine, uid int, startDate string, endDate string) (err error, days int, isContinuousDailyActivity bool) { startAt, err := time.ParseInLocation("2006-01-02", startDate, time.Local) //起始时间 diff --git a/rule/egg_energy/md/mq_egg_app.go b/rule/egg_energy/md/mq_egg_app.go new file mode 100644 index 0000000..679190b --- /dev/null +++ b/rule/egg_energy/md/mq_egg_app.go @@ -0,0 +1,27 @@ +package md + +const EggAppExchange = "egg.app" + +const ( + EggFinWithdrawApply = "egg_fin_withdraw_apply" // 提现申请 +) + +type EggFinWithdrawApplyData struct { + Id int64 `json:"id"` + Uid int64 `json:"uid"` + AdmId int `json:"adm_id"` + Amount string `json:"amount"` + RealAmount string `json:"real_amount"` + Fee string `json:"fee"` + Type int `json:"type"` + WithdrawAccount string `json:"withdraw_account"` + WithdrawName string `json:"withdraw_name"` + Reason int `json:"reason"` + PaymentDate string `json:"payment_date"` + State int `json:"state"` + WithdrawKind int `json:"withdraw_kind"` + IsFirst int `json:"is_first"` + Memo string `json:"memo"` + UpdateAt string `json:"update_at"` + CreateAt string `json:"create_at"` +}