소스 검색

add 服务奖分红

master
dengbiao 4 달 전
부모
커밋
e240ed8696
4개의 변경된 파일307개의 추가작업 그리고 1개의 파일을 삭제
  1. +1
    -1
      go.mod
  2. +2
    -0
      go.sum
  3. +289
    -0
      rule/service_award_dividend/index.go
  4. +15
    -0
      rule/service_award_dividend/md/service_award_dividend.go

+ 1
- 1
go.mod 파일 보기

@@ -7,7 +7,7 @@ go 1.15

require (
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240723073901-849ec3e356f3
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240805064206-7176a3f52675
github.com/gin-gonic/gin v1.9.1
github.com/go-redis/redis v6.15.9+incompatible
github.com/gomodule/redigo v1.8.9


+ 2
- 0
go.sum 파일 보기

@@ -6,6 +6,8 @@ code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240701102131-0408d7e
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240701102131-0408d7ee8572/go.mod h1:nT2x13YFgrS3tS1fDyUR6q/GNIK+hPw7bdzZXz99SM0=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240723073901-849ec3e356f3 h1:YQhrYavdlE5gUpQ6tm7029ONJVyy9IcSw4W1vU52+3E=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240723073901-849ec3e356f3/go.mod h1:nT2x13YFgrS3tS1fDyUR6q/GNIK+hPw7bdzZXz99SM0=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240805064206-7176a3f52675 h1:CHFIwllR+HxDvhOsrW2+h/riCpAclOVbPh5xm63530w=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240805064206-7176a3f52675/go.mod h1:nT2x13YFgrS3tS1fDyUR6q/GNIK+hPw7bdzZXz99SM0=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=


+ 289
- 0
rule/service_award_dividend/index.go 파일 보기

@@ -0,0 +1,289 @@
package service_award_dividend

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/service_award_dividend/md"
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache"
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/models"
"encoding/json"
"errors"
"time"
"xorm.io/xorm"
)

func Init(redisAddr string) (err error) {
if redisAddr != "" {
cache.NewRedis(redisAddr)
}
_, err = cache.SelectDb(md2.RedisDataBase)
return
}

func JoinServiceAwardDividendRelation(eg *xorm.Engine, masterId string, req md.JoinServiceAwardDividendRelationReq) (err error) {
user, err := db.DbsUserFindByUid(eg, req.Uid)
if err != nil {
return err
}
if user == nil {
return errors.New("未查询到相应会员记录")
}

serviceAwardDividendBasicDb := implement.NewServiceAwardDividendBasicDb(eg)
base, _ := serviceAwardDividendBasicDb.GetServiceAwardDividendBasic()
if base.IsOpen != 1 {
err = errors.New("服务奖分红未开启!")
return
}
var generalVipAllocationSetStruct md.GeneralVipAllocationSetStruct //普通会员设置
err = json.Unmarshal([]byte(base.GeneralVipAllocationSet), &generalVipAllocationSetStruct)
if err != nil {
return err
}
var seniorVipAllocationSetStruct []md.SeniorVipAllocationSetStruct //高级会员设置
err = json.Unmarshal([]byte(base.SeniorVipAllocationSet), &seniorVipAllocationSetStruct)
if err != nil {
return err
}
var seniorVipIdsStruct md.SeniorVipIdsStruct //高级会员ids
err = json.Unmarshal([]byte(base.SeniorVipIds), &seniorVipIdsStruct)
if err != nil {
return err
}

var levelMap = map[int]model.UserLevel{}
lvList, err := db.UserLevelInIDescByWeightLow(eg)
for _, v := range lvList {
levelMap[v.Id] = *v
}

//1、判断是否有直属推荐人
if req.ParentUid != 0 {
//2、判断直属推荐人是否为销售型会员
parentUser, err := db.DbsUserFindByUid(eg, req.ParentUid)
if err != nil {
return err
}
if parentUser == nil {
return errors.New("未查询到相应上级会员记录")
}
if zhios_order_relate_utils.InArrToInt(parentUser.Level, seniorVipIdsStruct) {
//3、判断当前用户和父级用户谁的会员等级更高
if levelMap[user.Level].LevelWeight >= levelMap[parentUser.Level].LevelWeight {
//4、判断当前用户是"普通会员" or "高级会员"
if zhios_order_relate_utils.InArrToInt(user.Level, seniorVipIdsStruct) {
err = AutoAddGeneralVip(eg, user, req.ParentUid, generalVipAllocationSetStruct)
if err != nil {
return err
}
} else {
for _, vv := range seniorVipAllocationSetStruct {
if vv.FromVipId == user.Level {
err = AutoAddSeniorVip(eg, user, req.ParentUid, vv)
if err != nil {
return err
}
}
}
}
} else {
err = AddVipToParent(eg, user, req.ParentUid)
if err != nil {
return err
}
}
} else {
//5、判断当前用户是"普通会员" or "高级会员"
if zhios_order_relate_utils.InArrToInt(user.Level, seniorVipIdsStruct) {
err = AutoAddGeneralVip(eg, user, req.ParentUid, generalVipAllocationSetStruct)
if err != nil {
return err
}
} else {
for _, vv := range seniorVipAllocationSetStruct {
if vv.FromVipId == user.Level {
err = AutoAddSeniorVip(eg, user, req.ParentUid, vv)
if err != nil {
return err
}
}
}
}
}
} else {
//2、判断当前用户是"普通会员" or "高级会员"
if zhios_order_relate_utils.InArrToInt(user.Level, seniorVipIdsStruct) {
err = AutoAddGeneralVip(eg, user, req.ParentUid, generalVipAllocationSetStruct)
if err != nil {
return err
}
} else {
for _, vv := range seniorVipAllocationSetStruct {
if vv.FromVipId == user.Level {
err = AutoAddSeniorVip(eg, user, req.ParentUid, vv)
if err != nil {
return err
}
}
}
}
}
return
}

// AutoAddGeneralVip 自动添加普通会员
func AutoAddGeneralVip(engine *xorm.Engine, user *model.User, parentUid int, generalVipAllocationSet md.GeneralVipAllocationSetStruct) (err error) {
//1、查询出当前应该分配给哪个上级会员
var serviceAwardDividendRelation models.ServiceAwardDividendRelation
has, err := engine.In("vip_level", generalVipAllocationSet).Asc("allocation_nums").Get(&serviceAwardDividendRelation)
if err != nil {
return err
}
if has == false {
return errors.New("未查询到合适的绑定上级会员用户!")
}

now := time.Now()
sess := engine.NewSession()
defer func() {
sess.Close()
if err := recover(); err != nil {

_ = zhios_order_relate_logx.Error(err)
}
}()
sess.Begin()

//2、新增 service_award_dividend_relation 记录
serviceAwardDividendRelationDb := implement.NewServiceAwardDividendRelationDb(engine)
_, err = serviceAwardDividendRelationDb.InsertServiceAwardDividendRelationBySess(sess, &models.ServiceAwardDividendRelation{
Uid: user.Uid,
ParentUid: parentUid,
BindUid: serviceAwardDividendRelation.Uid,
VipLevel: user.Level,
AllocationNums: 0,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
sess.Rollback()
return err
}

//3、修改 绑定上级的 service_award_dividend_relation 记录
serviceAwardDividendRelation.AllocationNums++
updateRelationAfftecd, err := serviceAwardDividendRelationDb.SaveServiceAwardDividendRelation(sess, serviceAwardDividendRelation.Id, &serviceAwardDividendRelation, "allocation_nums")
if err != nil {
return err
}
if updateRelationAfftecd <= 0 {
return errors.New("更新 绑定上级的 service_award_dividend_relation 记录 失败!")
}
return sess.Commit()
}

// AutoAddSeniorVip 自动添加高级会员
func AutoAddSeniorVip(engine *xorm.Engine, user *model.User, parentUid int, seniorVipAllocationSet md.SeniorVipAllocationSetStruct) (err error) {
//1、查询出当前应该分配给哪个上级会员
var serviceAwardDividendRelation models.ServiceAwardDividendRelation
has, err := engine.In("vip_level", seniorVipAllocationSet.ToVipId).Asc("allocation_nums").Get(&serviceAwardDividendRelation)
if err != nil {
return err
}
if has == false {
return errors.New("未查询到合适的绑定上级会员用户!")
}

now := time.Now()
sess := engine.NewSession()
defer func() {
sess.Close()
if err := recover(); err != nil {

_ = zhios_order_relate_logx.Error(err)
}
}()
sess.Begin()

//2、新增 service_award_dividend_relation 记录
serviceAwardDividendRelationDb := implement.NewServiceAwardDividendRelationDb(engine)
_, err = serviceAwardDividendRelationDb.InsertServiceAwardDividendRelationBySess(sess, &models.ServiceAwardDividendRelation{
Uid: user.Uid,
ParentUid: parentUid,
BindUid: serviceAwardDividendRelation.Uid,
VipLevel: user.Level,
AllocationNums: 0,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
sess.Rollback()
return err
}

//3、修改 绑定上级的 service_award_dividend_relation 记录
serviceAwardDividendRelation.AllocationNums++
updateRelationAfftecd, err := serviceAwardDividendRelationDb.SaveServiceAwardDividendRelation(sess, serviceAwardDividendRelation.Id, &serviceAwardDividendRelation, "allocation_nums")
if err != nil {
return err
}
if updateRelationAfftecd <= 0 {
return errors.New("更新 绑定上级的 service_award_dividend_relation 记录 失败!")
}
return sess.Commit()
}

// AddVipToParent 添加会员至父级
func AddVipToParent(engine *xorm.Engine, user *model.User, parentUid int) (err error) {
//1、查询出当前应该分配给哪个上级会员
var serviceAwardDividendRelation models.ServiceAwardDividendRelation
has, err := engine.Where("uid =?", parentUid).Get(&serviceAwardDividendRelation)
if err != nil {
return err
}
if has == false {
return errors.New("未查询到对应绑定上级会员用户!")
}

now := time.Now()
sess := engine.NewSession()
defer func() {
sess.Close()
if err := recover(); err != nil {

_ = zhios_order_relate_logx.Error(err)
}
}()
sess.Begin()

//2、新增 service_award_dividend_relation 记录
serviceAwardDividendRelationDb := implement.NewServiceAwardDividendRelationDb(engine)
_, err = serviceAwardDividendRelationDb.InsertServiceAwardDividendRelationBySess(sess, &models.ServiceAwardDividendRelation{
Uid: user.Uid,
ParentUid: parentUid,
BindUid: serviceAwardDividendRelation.Uid,
VipLevel: user.Level,
AllocationNums: 0,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
sess.Rollback()
return err
}

//3、修改 绑定上级的 service_award_dividend_relation 记录
serviceAwardDividendRelation.AllocationNums++
updateRelationAfftecd, err := serviceAwardDividendRelationDb.SaveServiceAwardDividendRelation(sess, serviceAwardDividendRelation.Id, &serviceAwardDividendRelation, "allocation_nums")
if err != nil {
return err
}
if updateRelationAfftecd <= 0 {
return errors.New("更新 绑定上级的 service_award_dividend_relation 记录 失败!")
}
return sess.Commit()
}

+ 15
- 0
rule/service_award_dividend/md/service_award_dividend.go 파일 보기

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

type GeneralVipIdsStruct []int
type GeneralVipAllocationSetStruct []int

type SeniorVipIdsStruct []int
type SeniorVipAllocationSetStruct struct {
FromVipId int `json:"from_vip_id"`
ToVipId []int `json:"to_vip_id"`
}

type JoinServiceAwardDividendRelationReq struct {
Uid int `json:"uid"` //用户id
ParentUid int `json:"parent_uid"` //父级id
}

불러오는 중...
취소
저장