Bladeren bron

更新

three
huangjiajun 11 maanden geleden
bovenliggende
commit
90a80794a9
3 gewijzigde bestanden met toevoegingen van 317 en 20 verwijderingen
  1. +42
    -0
      app/md/free.go
  2. +245
    -0
      app/svc/svc_perm.go
  3. +30
    -20
      consume/zhios_order_free.go

+ 42
- 0
app/md/free.go Bestand weergeven

@@ -0,0 +1,42 @@
package md

type PricePerm struct {
Auth struct {
ValidUser struct {
Open string `json:"open"`
} `json:"valid_user"`
NewUser struct {
Open string `json:"open"`
} `json:"new_user"`
UserLevel struct {
Open string `json:"open"`
Value string `json:"value"`
} `json:"user_level"`
Onrecord struct {
Open string `json:"open"`
} `json:"onrecord"`
InviteFriends struct {
Open string `json:"open"`
Value string `json:"value"`
} `json:"invite_friends"`
Commission struct {
Open string `json:"open"`
Days string `json:"days"`
Money string `json:"money"`
} `json:"commission"`
NewDays struct {
Open string `json:"open"`
Days string `json:"days"`
} `json:"new_days"`
TeamMembers struct {
Open string `json:"open"`
Amount string `json:"amount"`
} `json:"team_members"`
Orders struct {
Open string `json:"open"`
Days string `json:"days"`
Amount string `json:"amount"`
} `json:"orders"`
} `json:"auth"`
AuthType string `json:"auth_type"`
}

+ 245
- 0
app/svc/svc_perm.go Bestand weergeven

@@ -0,0 +1,245 @@
package svc

import (
"applet/app/db/model"
"applet/app/md"
db2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db"
model2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
"strconv"
"strings"
"time"

"xorm.io/xorm"

"applet/app/db"
"applet/app/utils"
"applet/app/utils/logx"
)

func CheckNewOrderAuth(eg *xorm.Engine, uid int, thisPrice *model.NewcomersFreePriceType) (bool, *md.PricePerm) {
// 测试开发阶段返回true

user, _ := db.UserFindByID(eg, uid)
userProfile, _ := db.UserProfileFindByID(eg, uid)
perm := &md.PricePerm{}
utils.Unserialize([]byte(thisPrice.Auth), perm)
var permList []bool
if perm.Auth.ValidUser.Open == "1" {
permList = append(permList, checkValidUser(userProfile))
}
if perm.Auth.NewUser.Open == "1" {
permList = append(permList, checkNewUser(userProfile))
}
if perm.Auth.UserLevel.Open == "1" {
permList = append(permList, checkUserLevel(eg, user, perm.Auth.UserLevel.Value))
}
if perm.Auth.Onrecord.Open == "1" {
permList = append(permList, checkOnRecord(userProfile))
}
if perm.Auth.InviteFriends.Open == "1" {
permList = append(permList, checkInviteFriends(eg, user, perm.Auth.InviteFriends.Value))
}
if perm.Auth.Commission.Open == "1" {
permList = append(permList, checkCommission(eg, perm.Auth.Commission.Days, perm.Auth.Commission.Money, user))
}
if perm.Auth.NewDays.Open == "1" {
permList = append(permList, checkNewdaysOrder(eg, perm.Auth.NewDays.Days, user))
}
if perm.Auth.TeamMembers.Open == "1" {
permList = append(permList, checkTeamMembers(eg, perm.Auth.TeamMembers.Amount, user))
}
if perm.Auth.Orders.Open == "1" {
permList = append(permList, checkCompleteOrders(eg, perm.Auth.Orders.Days, perm.Auth.Orders.Amount, user))
}
var r bool
if perm.AuthType == "all" {
r = true
for _, v := range permList {
r = r && v
}
} else {
r = false
for _, v := range permList {
r = r || v
}
}
// 检查福利券是否符合
needNewCoupon := thisPrice.NeedQuan
//如果全部条件都需要满足 但是福利券不满足
if perm.AuthType == "all" && userProfile.FreeRemainTime < needNewCoupon && thisPrice.NeedUseQuan == 1 {
r = false
}
return r, perm
}

// 是否有效用户
func checkValidUser(user *model.UserProfile) bool {
if user.IsVerify == 1 {
return true
}
return false
}

// 是否新用户
func checkNewUser(user *model.UserProfile) bool {
if user.IsNew == 1 {
return true
}
return false
}

// 用户等级
func checkUserLevel(Db *xorm.Engine, user *model.User, needUserLevelId string) bool {
if user == nil {
return false
}
needLevel, err := db2.UserLevelByID(Db, needUserLevelId)
if err != nil {
// 该等级已被删除的话就false
return false
}
userLevel, err := db2.UserLevelByID(Db, user.Level)
if err != nil {
// 该等级已被删除的话就false
return false
}
return userLevel.LevelWeight >= needLevel.LevelWeight
}

// 淘宝备案授权
func checkOnRecord(user *model.UserProfile) bool {
if user.AccTaobaoShareId > 0 {
return true
}
return false
}

// 直推好友
func checkInviteFriends(Db *xorm.Engine, user *model.User, need string) bool {
if user == nil {
return false
}
needPerson := utils.AnyToInt64(need)
total, err := InviteCountlevelOne(Db, user)
if err != nil {
_ = logx.Warn(err)
return false
}
if total >= needPerson {
return true
}
return false
}
func InviteCountlevelOne(Db *xorm.Engine, user *model.User) (total int64, err error) {
relate := new(model2.UserRelate)
total, err = Db.Where("parent_uid=? and level=1", user.Uid).Count(relate)
return
}

// 团队所有成员统计
func InviteCountlevelAll(Db *xorm.Engine, user *model.User) (total int64, err error) {
relate := new(model2.UserRelate)
total, err = Db.Where("parent_uid=?", user.Uid).Count(relate)
return
}

// 检查佣金
func checkCommission(Db *xorm.Engine, leftValue, rightValue string, user *model.User) bool {
if user == nil {
return false
}
needDays, _ := strconv.Atoi(leftValue)
needMoney, _ := strconv.Atoi(rightValue)
t := time.Now()
stime := time.Date(t.Year(), t.Month(), t.Day()-int(needDays), t.Hour(), 0, 0, 0, t.Location()).Unix()
etime := t.Unix()
ms, err := db.OrderListByTimeByState(Db, user.Uid, 3, stime, etime)
if err != nil {
_ = logx.Warn(err)
return false
} else {
money := getSumForOrder(utils.IntToStr(user.Uid), ms)
if money >= utils.AnyToFloat64(needMoney) {
return true
}
}
return false
}
func getSumForOrder(uid string, ol []*model.OrdList) float64 {
var oa []float64
var sum float64

for _, item := range ol {
for _, s := range strings.Split(item.BenefitList, "|") {
if strings.Contains(s, uid) {
uidbenfit := strings.Split(s, ":")
if len(uidbenfit) != 2 {
logx.Warn("OrderList BenefitList is format error")
return 0
}
oa = append(oa, utils.StrToFloat64(uidbenfit[len(uidbenfit)-1]))
break
}

}
}
for _, item := range oa {
sum += item
}
return sum
}

func getSumForOrderRelate(oidMapAmount map[int64]float64, ol []*model.OrdList) float64 {
var sum float64

for _, item := range ol {
if oidMapAmount[item.OrdId] > 0 {
sum += oidMapAmount[item.OrdId]
}
}
return sum
}

// 注册多少天之内没有订单
func checkNewdaysOrder(Db *xorm.Engine, value string, user *model.User) bool {
stime, etime := utils.GetTimeInterval("days", -utils.StrToInt(value))
ordList, err := db.OrderListCountByUIDByTime(Db, user.Uid, stime, etime)
if err != nil {
_ = logx.Warn(err)
return false
}
if len(*ordList) == 0 {
return true
}
return false
}

// 团队数量达到多少个
func checkTeamMembers(Db *xorm.Engine, value string, user *model.User) bool {
needPerson := utils.AnyToInt64(value)
total, err := InviteCountlevelAll(Db, user)
if err != nil {
_ = logx.Warn(err)
return false
}
if total >= needPerson {
return true
}
return false
}

// 几天内,已经结算订单达到几个
func checkCompleteOrders(Db *xorm.Engine, leftValue, rightValue string, user *model.User) bool {
needDays, _ := strconv.Atoi(leftValue)
needAmount, _ := strconv.Atoi(rightValue)
stime, etime := utils.GetTimeInterval("days", -needDays)
ms, err := db.OrderListByTimeByState(Db, user.Uid, 3, stime, etime)
if err != nil {
_ = logx.Warn(err)
return false
}
if len(ms) >= needAmount {
return true
}
return false
}

+ 30
- 20
consume/zhios_order_free.go Bestand weergeven

@@ -4,6 +4,7 @@ import (
"applet/app/db"
"applet/app/db/model"
md2 "applet/app/md"
svc2 "applet/app/svc"
"applet/app/utils"
"applet/app/utils/logx"
"applet/consume/md"
@@ -286,30 +287,39 @@ func orderFreeCheck(eg *xorm.Engine, sess *xorm.Session, canalMsg *md.ZhiosOrder
//判断要不要扣免单券
if mt.NeedUseQuan == 1 {
// 更新剩余次数
isNeed := 1
if mt.NeedQuan > profile.FreeRemainTime {
sess.Rollback()

return nil
auth, perm := svc2.CheckNewOrderAuth(eg, utils.StrToInt(canalMsg.Uid), mt)
if perm.AuthType == "all" || auth == false {
sess.Rollback()
return nil
}
if perm.AuthType != "all" && auth == true {
isNeed = 0
}
}
profile.FreeRemainTime = profile.FreeRemainTime - mt.NeedQuan
_, err = db.UserProfileUpdate(eg, profile.Uid, profile, "free_remain_time")
if err != nil {
logx.Warn(err)
sess.Rollback()
if isNeed == 1 {
profile.FreeRemainTime = profile.FreeRemainTime - mt.NeedQuan
_, err = db.UserProfileUpdate(eg, profile.Uid, profile, "free_remain_time")
if err != nil {
logx.Warn(err)
sess.Rollback()

return nil
return nil
}
// 插入日志记录
db.FreeQualificationRecordInsertOne(eg, &model.NewcomersQualificationRecord{
Uid: profile.Uid,
Source: 3,
SourceText: "消费扣除",
OrderId: utils.StrToInt64(canalMsg.Oid),
ChangeNum: -mt.NeedQuan,
AfterChangeNum: profile.FreeRemainTime,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
})
}
// 插入日志记录
db.FreeQualificationRecordInsertOne(eg, &model.NewcomersQualificationRecord{
Uid: profile.Uid,
Source: 3,
SourceText: "消费扣除",
OrderId: utils.StrToInt64(canalMsg.Oid),
ChangeNum: -mt.NeedQuan,
AfterChangeNum: profile.FreeRemainTime,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
})

}
m.Stock--
if m.Stock < 0 {


Laden…
Annuleren
Opslaan