|
|
@@ -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) //起始时间 |
|
|
|