|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/md"
- "applet/app/utils"
- "applet/app/utils/logx"
- "fmt"
- "time"
- "xorm.io/xorm"
- )
-
- // 拉新
-
- // 统计奖励金额
- func SumAcquisitionReward(Db *xorm.Engine, condition *model.AcquisitionRewardLog) (string, error) {
- total, err := Db.Sum(condition, "money")
- if err != nil {
- return "0", err
- }
- return utils.AnyToString(total), nil
- }
-
- // 统计拉新人数
- func CountAcquisitionUser(Db *xorm.Engine, condition *model.AcquisitionLog) (string, error) {
- total, err := Db.Count(condition)
- if err != nil {
- return "0", err
- }
- return utils.AnyToString(total), nil
- }
-
- // 获取拉新记录
- func GetAcquisitionLog(Db *xorm.Engine, condition *model.AcquisitionLog) (*model.AcquisitionLog, bool, error) {
- r := new(model.AcquisitionLog)
- has, err := Db.Get(condition)
- if err != nil {
- return r, false, err
- }
- return condition, has, nil
- }
-
- // 获取拉新奖励记录
- func GetAcquisitionRewardLog(Db *xorm.Engine, condition *model.AcquisitionRewardLog) (*model.AcquisitionRewardLog, bool, error) {
- r := new(model.AcquisitionRewardLog)
- has, err := Db.Get(condition)
- if err != nil {
- return r, false, err
- }
- return condition, has, nil
- }
-
- // 插入拉新记录
- func InsertAcqLog(Db *xorm.Engine, acqLog *model.AcquisitionLog) {
- row, err := Db.InsertOne(acqLog)
- if err != nil || row == 0 {
- _ = logx.Warn(err)
- }
- }
-
- // 更新拉新记录
- func UpdateAcqLog(Db *xorm.Engine, acqLog *model.AcquisitionLog) {
- row, err := Db.ID(acqLog.Id).Cols("state,complete_con").Update(acqLog)
- if err != nil || row == 0 {
- _ = logx.Warn(err)
- }
- }
-
- // 查询是否存在奖励记录
- func HasRewardLog(Db *xorm.Engine, condition *model.AcquisitionRewardLog) (string, error) {
- has, err := Db.Get(condition)
- s := "0"
- if err != nil {
- return s, err
- }
- if has {
- s = "1"
- }
- if condition.State == 1 {
- s = "2"
- }
- return s, nil
- }
-
- // 查询是否存在奖励记录
- func GetRewardLog(Db *xorm.Engine, condition *model.AcquisitionRewardLog) (*model.AcquisitionRewardLog, error) {
- r := new(model.AcquisitionRewardLog)
- has, err := Db.Get(condition)
- if err != nil || !has {
- return r, err
- }
- return condition, nil
- }
-
- // 插入奖励记录
- func InsertRewardLog(Db *xorm.Engine, rewardLog *model.AcquisitionRewardLog) {
- row, err := Db.InsertOne(rewardLog)
- if err != nil || row == 0 {
- _ = logx.Warn(err)
- }
- }
-
- // 更新奖励记录
- func UpdateRewardLog(Db *xorm.Engine, rewardLog *model.AcquisitionRewardLog) (int64, error) {
- affected, err := Db.ID(rewardLog.Id).AllCols().Update(rewardLog)
- return affected, err
- }
-
- //
- func FindRewardLog(Db *xorm.Engine, state string, forbiddenState string, uid string) ([]*model.AcquisitionRewardLog, error) {
- var logs []*model.AcquisitionRewardLog
- err := Db.Where("state=? and is_frozen=? and uid=?", state, forbiddenState, uid).Find(&logs)
- return logs, err
- }
-
- func FindRewardLogLimit(Db *xorm.Engine, state, forbiddenState string, limit, start int) ([]*model.AcquisitionRewardLog, error) {
- var logs []*model.AcquisitionRewardLog
- err := Db.Where("state=? and is_frozen=?", state, forbiddenState).Limit(limit, start).Find(&logs)
- return logs, err
- }
-
- func FindAcqLogLimit(Db *xorm.Engine, state string, limit, start int) ([]*model.AcquisitionLog, error) {
- var logs []*model.AcquisitionLog
- err := Db.Where("state=?", state).Limit(limit, start).Find(&logs)
- return logs, err
- }
-
- func FindAcqRewardLogLimit(Db *xorm.Engine, state string, limit, start int, acqCfgLocal *md.AcquisitionCfg) ([]*model.AcquisitionRewardLog, error) {
- var logs []*model.AcquisitionRewardLog
- lastTime := time.Now().Unix()
- if acqCfgLocal != nil && utils.StrToInt(acqCfgLocal.RewardAccountDay) > 0 {
- lastTime = lastTime - utils.StrToInt64(acqCfgLocal.RewardAccountDay)*86400
- }
- err := Db.Where("state=? and created_at >? and created_at <? and source=? and is_frozen=?", state, "0", lastTime, 1, 0).Limit(limit, start).Find(&logs)
- fmt.Println(err)
- return logs, err
- }
- func FindAcqRewardLogLimitByIds(Db *xorm.Engine, ids []string) ([]*model.AcquisitionRewardLog, error) {
- var logs []*model.AcquisitionRewardLog
- err := Db.In("id", ids).And("state=?", 0).Find(&logs)
- fmt.Println(err)
- return logs, err
- }
|