Kaynağa Gözat

Merge remote-tracking branch 'origin/master'

three
DengBiao 10 ay önce
ebeveyn
işleme
317dd33e07
19 değiştirilmiş dosya ile 1178 ekleme ve 45 silme
  1. +22
    -0
      app/db/db_newcomers_free_price_type.go
  2. +3
    -3
      app/db/db_newcomers_free_product.go
  3. +16
    -7
      app/db/db_order.go
  4. +18
    -0
      app/db/db_user_virtual_coin_amount.go
  5. +27
    -0
      app/db/model/guide_store_goods.go
  6. +15
    -0
      app/db/model/newcomers_free_price_type.go
  7. +21
    -0
      app/db/model/newcomers_qualification_record.go
  8. +22
    -20
      app/db/model/user_virtual_coin_flow.go
  9. +42
    -0
      app/md/free.go
  10. +245
    -0
      app/svc/svc_perm.go
  11. +83
    -0
      consume/canal_guide_order_by_user_up_lv_consume.go
  12. +3
    -0
      consume/init.go
  13. +30
    -0
      consume/md/consume_key.go
  14. +10
    -0
      consume/md/free.go
  15. +11
    -1
      consume/md/md_zhios_capital_pool_order_total.go
  16. +84
    -14
      consume/zhios_guide_store_order_success.go
  17. +83
    -0
      consume/zhios_order_buckle.go
  18. +360
    -0
      consume/zhios_order_free.go
  19. +83
    -0
      consume/zhios_user_up_lv.go

+ 22
- 0
app/db/db_newcomers_free_price_type.go Dosyayı Görüntüle

@@ -0,0 +1,22 @@
package db

import (
"applet/app/db/model"
"errors"

"xorm.io/xorm"
)

// FreePriceTypeByID is 获取新人免单对应的商品价格的类型
func FreePriceTypeByID(sess *xorm.Session, id interface{}) (*model.NewcomersFreePriceType, error) {
m := new(model.NewcomersFreePriceType)
has, err := sess.ID(id).Get(m)
if err != nil {
return nil, err
}
if !has {
return nil, errors.New("Not Found")
}
return m, nil

}

+ 3
- 3
app/db/db_newcomers_free_product.go Dosyayı Görüntüle

@@ -11,7 +11,7 @@ import (
)

// FreeProductByID is 获取新人免单对应的商品id
func FreeProductByID(Db *xorm.Engine, gid, provider string) (*model.NewcomersFreeProduct, error) {
func FreeProductByID(sess *xorm.Session, gid, provider string) (*model.NewcomersFreeProduct, error) {
m := new(model.NewcomersFreeProduct)
var has bool
var err error
@@ -20,10 +20,10 @@ func FreeProductByID(Db *xorm.Engine, gid, provider string) (*model.NewcomersFre
if len(gidArr) == 2 {
gid = gidArr[1]
}
has, err = Db.Where("good_id LIKE ?", "%-"+gid).Get(m)
has, err = sess.Where("good_id LIKE ?", "%-"+gid).Get(m)
} else {
m.GoodId = gid
has, err = Db.Get(m)
has, err = sess.Get(m)
}

if err != nil {


+ 16
- 7
app/db/db_order.go Dosyayı Görüntüle

@@ -6,7 +6,6 @@ import (
"applet/app/utils/logx"
"errors"
"fmt"
"time"
"xorm.io/xorm"
)

@@ -37,6 +36,14 @@ func OrderListByOid(sess *xorm.Session, oids string) (*model.OrdList, error) {
}
return &o, nil
}
func OrderListByOidEg(eg *xorm.Engine, oids string) (*model.OrdList, error) {
var o model.OrdList
get, err := eg.Where("ord_id=?", oids).Get(&o)
if err != nil || get == false {
return nil, errors.New("没订单")
}
return &o, nil
}

// 按传入的oid顺序排序
func OrderListByOidsAndOrderByOids(Db *xorm.Engine, oids []int64) (*[]model.OrdList, error) {
@@ -438,19 +445,21 @@ func OrderListCountByPvdByUidByTimeByValid(Db *xorm.Engine, provider, startTime,
}

// OrderListCountByPriceType is 计算免单价格类型下的购买
func OrderListCountByPriceType(Db *xorm.Engine, uid string, priceType, day int) (int64, error) {
sess := Db.Where(" uid = ? AND state != 4 AND price_type= ?", uid, priceType)
func OrderListCountByPriceType(sess *xorm.Session, uid string, priceType, day int) (int64, error) {
sess = sess.Where(" uid = ? AND state != 4 AND price_type= ?", uid, priceType)
if day > 0 {
sess = sess.And("create_at>=?", time.Now().Unix()-int64(day*86400))
today := utils.GetTimeRange("today")
sess = sess.And("create_at>=?", today["end"]-int64(day*86400))
}
return sess.Count(&model.OrdList{})
}

// OrderListCountByItemId is 计算免单单个商品购买的次数
func OrderListCountByItemId(Db *xorm.Engine, uid string, itemId string, day int) (int64, error) {
sess := Db.Where(" uid = ? AND state != 4 AND item_id = ?", uid, itemId)
func OrderListCountByItemId(sess *xorm.Session, uid string, itemId string, day int) (int64, error) {
sess = sess.Where(" uid = ? AND state != 4 AND item_id = ? and price_type>0", uid, itemId)
if day > 0 {
sess = sess.And("create_at>=?", time.Now().Unix()-int64(day*86400))
today := utils.GetTimeRange("today")
sess = sess.And("create_at>=?", today["end"]-int64(day*86400))
}
return sess.Count(&model.OrdList{})
}


+ 18
- 0
app/db/db_user_virtual_coin_amount.go Dosyayı Görüntüle

@@ -0,0 +1,18 @@
package db

import (
"applet/app/db/model"
"xorm.io/xorm"
)

func GetUserVirtualCoinAmount(eg *xorm.Engine, uid int, coinId string) *model.UserVirtualAmount {
var data model.UserVirtualAmount
get, err := eg.Where("uid=? and coin_id=?", uid, coinId).Get(&data)
if get == false || err != nil {
return nil
}
return &data
}
func FreeQualificationRecordInsertOne(Db *xorm.Engine, m *model.NewcomersQualificationRecord) (int64, error) {
return Db.InsertOne(m)
}

+ 27
- 0
app/db/model/guide_store_goods.go Dosyayı Görüntüle

@@ -0,0 +1,27 @@
package model

import (
"time"
)

type GuideStoreGoods struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"default 0 INT(11)"`
Gid string `json:"gid" xorm:"VARCHAR(100)"`
GoodsInfo string `json:"goods_info" xorm:"VARCHAR(5000)"`
Stock int `json:"stock" xorm:"default 0 INT(11)"`
SubsidyPrice string `json:"subsidy_price" xorm:"default 0.00 DECIMAL(20,2)"`
Fee string `json:"fee" xorm:"DECIMAL(20,2)"`
State int `json:"state" xorm:"default 0 comment('1待审核 2审核通过 3审核失败') INT(11)"`
Remark string `json:"remark" xorm:"VARCHAR(255)"`
Time time.Time `json:"time" xorm:"DATETIME"`
AuditTime time.Time `json:"audit_time" xorm:"DATETIME"`
Title string `json:"title" xorm:"VARCHAR(255)"`
ActivityId string `json:"activity_id" xorm:"VARCHAR(255)"`
Pvd string `json:"pvd" xorm:"VARCHAR(255)"`
OldStock int `json:"old_stock" xorm:"default 0 INT(11)"`
DeductState int `json:"deduct_state" xorm:"comment('1已扣 2已退') INT(1)"`
EndTime int `json:"end_time" xorm:"default 0 INT(11)"`
DownState int `json:"down_state" xorm:"default 0 INT(11)"`
PriceType int `json:"price_type" xorm:"not null default 0 comment('所属价格类型') TINYINT(1)"`
}

+ 15
- 0
app/db/model/newcomers_free_price_type.go Dosyayı Görüntüle

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

type NewcomersFreePriceType struct {
Id int `json:"id" xorm:"not null pk autoincr INT(10)"`
PriceName string `json:"price_name" xorm:"not null comment('价格类型') VARCHAR(255)"`
NeedQuan int `json:"need_quan" xorm:"not null default 0 comment('需要的福利券') INT(11)"`
CreatedAt int `json:"created_at" xorm:"not null default 0 INT(11)"`
UpdatedAt int `json:"updated_at" xorm:"not null default 0 INT(11)"`
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否开启') TINYINT(1)"`
IsDel int `json:"is_del" xorm:"not null default 0 INT(11)"`
NeedUseQuan int `json:"need_use_quan" xorm:"not null default 1 INT(1)"`
NeedLimitBuy int `json:"need_limit_buy" xorm:"not null default 0 INT(1)"`
Auth string `json:"auth" xorm:"not null comment('权限') TEXT"`
LimitBuyCondition string `json:"limit_buy_condition" xorm:"not null comment('限购条件') TEXT"`
}

+ 21
- 0
app/db/model/newcomers_qualification_record.go Dosyayı Görüntüle

@@ -0,0 +1,21 @@
package model

import (
"time"
)

type NewcomersQualificationRecord struct {
Id int `json:"id" xorm:"not null pk autoincr INT(10)"`
Uid int `json:"uid" xorm:"not null default 0 INT(11)"`
Source int `json:"source" xorm:"not null default 0 comment('1为注册获得
2为分享获得
3为消费扣除
4为后台修改
来源标识') TINYINT(4)"`
SourceText string `json:"source_text" xorm:"not null default '' comment('来源') VARCHAR(255)"`
ChangeNum int `json:"change_num" xorm:"not null default 0 comment('变更值') INT(11)"`
AfterChangeNum int `json:"after_change_num" xorm:"not null default 0 comment('变更后值') INT(11)"`
OrderId int64 `json:"order_id" xorm:"not null default 0 comment('新人免单订单ID(与order_list主键对应)') BIGINT(20)"`
CreatedAt time.Time `json:"created_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
}

+ 22
- 20
app/db/model/user_virtual_coin_flow.go Dosyayı Görüntüle

@@ -5,24 +5,26 @@ import (
)

type UserVirtualCoinFlow struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
Uid int `json:"uid" xorm:"not null comment('用户id') index INT(11)"`
CoinId int `json:"coin_id" xorm:"not null comment('虚拟币id') INT(11)"`
Direction int `json:"direction" xorm:"not null comment('方向:1收入 2支出') TINYINT(255)"`
Title string `json:"title" xorm:"comment('标题') VARCHAR(255)"`
OrdId string `json:"ord_id" xorm:"comment('相关的订单id') VARCHAR(255)"`
Date string `json:"date" xorm:"comment('相关的订单id') VARCHAR(255)"`
Amout string `json:"amout" xorm:"not null comment('变更数量') DECIMAL(16,6)"`
BeforeAmout string `json:"before_amout" xorm:"not null comment('变更前数量') DECIMAL(16,6)"`
AfterAmout string `json:"after_amout" xorm:"not null comment('变更后数量') DECIMAL(16,6)"`
SysFee string `json:"sys_fee" xorm:"not null default 0.000000 comment('手续费') DECIMAL(16,6)"`
Price string `json:"price" xorm:"not null default 0.000000 comment('') DECIMAL(16,6)"`
CoinTransferData string `json:"coin_transfer_data" xorm:"not null comment('虚拟币转赠信息') TEXT"`
CreateTime time.Time `json:"create_time" xorm:"created default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
TransferType int `json:"transfer_type" xorm:"comment('转账类型:1全球分红,2管理员修改,3消费,4退回,5虚拟币兑换') TINYINT(100)"`
CoinIdTo int `json:"coin_id_to" xorm:"not null default 0 comment('兑换时目标币种id') INT(11)"`
IsRevoke int `json:"is_revoke" xorm:"not null default 0 comment('转赠是否撤回') INT(1)"`
TransferId int `json:"transfer_id" xorm:"not null default 0 comment('转赠关联id') INT(11)"`
ToUid int `json:"to_uid" xorm:"not null default 0 comment('转赠的用户id') INT(11)"`
TransferMoney string `json:"transfer_money" xorm:"not null default '0.000000' comment('转赠已撤回金额') INT(11)"`
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
Uid int `json:"uid" xorm:"not null comment('用户id') index INT(11)"`
CoinId int `json:"coin_id" xorm:"not null comment('虚拟币id') INT(11)"`
Direction int `json:"direction" xorm:"not null comment('方向:1收入 2支出') TINYINT(255)"`
Title string `json:"title" xorm:"comment('标题') VARCHAR(255)"`
OrdId string `json:"ord_id" xorm:"comment('相关的订单id') VARCHAR(255)"`
Date string `json:"date" xorm:"comment('相关的订单id') VARCHAR(255)"`
Amout string `json:"amout" xorm:"not null comment('变更数量') DECIMAL(16,6)"`
BeforeAmout string `json:"before_amout" xorm:"not null comment('变更前数量') DECIMAL(16,6)"`
AfterAmout string `json:"after_amout" xorm:"not null comment('变更后数量') DECIMAL(16,6)"`
SysFee string `json:"sys_fee" xorm:"not null default 0.000000 comment('手续费') DECIMAL(16,6)"`
Price string `json:"price" xorm:"not null default 0.000000 comment('') DECIMAL(16,6)"`
CoinTransferData string `json:"coin_transfer_data" xorm:"not null comment('虚拟币转赠信息') TEXT"`
CreateTime time.Time `json:"create_time" xorm:"created default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
TransferType int `json:"transfer_type" xorm:"comment('转账类型:1全球分红,2管理员修改,3消费,4退回,5虚拟币兑换') TINYINT(100)"`
CoinIdTo int `json:"coin_id_to" xorm:"not null default 0 comment('兑换时目标币种id') INT(11)"`
IsRevoke int `json:"is_revoke" xorm:"not null default 0 comment('转赠是否撤回') INT(1)"`
TransferId int `json:"transfer_id" xorm:"not null default 0 comment('转赠关联id') INT(11)"`
ToUid int `json:"to_uid" xorm:"not null default 0 comment('转赠的用户id') INT(11)"`
TransferMoney string `json:"transfer_money" xorm:"not null default '0.000000' comment('转赠已撤回金额') INT(11)"`
FreezeBeforeAmout string `json:"freeze_before_amout" xorm:" comment('变更前数量') DECIMAL(16,6)"`
FreezeAfterAmout string `json:"freeze_after_amout" xorm:" comment('变更后数量') DECIMAL(16,6)"`
}

+ 42
- 0
app/md/free.go Dosyayı Görüntüle

@@ -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 Dosyayı Görüntüle

@@ -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
}

+ 83
- 0
consume/canal_guide_order_by_user_up_lv_consume.go Dosyayı Görüntüle

@@ -0,0 +1,83 @@
package consume

import (
"applet/app/db"
"applet/app/utils"
"applet/app/utils/logx"
"applet/consume/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"encoding/json"
"errors"
"fmt"
"github.com/streadway/amqp"
"strings"
)

func CanalGuideOrderByUserUpLvConsume(queue md.MqQueue) {
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>")
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
logx.Error(err)
return
}
defer ch.Release()
//1、将自己绑定到交换机上
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
//2、取出数据进行消费
ch.Qos(1000)
delivery := ch.Consume(queue.Name, true) //设置自动应答

var res amqp.Delivery
var ok bool
for {
res, ok = <-delivery
if ok == true {
//fmt.Println(string(res.Body))
fmt.Println(">>>>>>>>>>>>>>>>>>CanalGuideOrderConsume<<<<<<<<<<<<<<<<<<<<<<<<<")
handleCanalGuideOrderByUserUpLvConsume(res.Body)
//_ = res.Reject(false)
//_ = res.Ack(true)
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleCanalGuideOrderByUserUpLvConsume(msg []byte) error {
//1、解析canal采集至mq中queue的数据结构体
var canalMsg *md.CanalOrderMessage[md.CanalGuideOrder]
err := json.Unmarshal(msg, &canalMsg)
if err != nil {
return nil
}

masterId := strings.Split(canalMsg.Database, "_")[1]
uids := make([]string, 0)
for _, data := range canalMsg.Data {
uids = append(uids, data.Uid)
}
eg := db.DBs[masterId]
if eg == nil {
return nil
}
levelList, _ := db.UserLevlEgAll(eg)
isAuto := 0
for _, v := range levelList {
if v.AutoUpdate == 1 {
isAuto = 1
}
}
if isAuto == 0 {
return nil
}
for _, v := range uids {
FindUser(eg, v, masterId, levelList)
oneUser, _ := db.UserProfileFindByID(eg, v)
if oneUser == nil || (oneUser != nil && oneUser.ParentUid == 0) {
continue
}
FindUser(eg, utils.IntToStr(oneUser.ParentUid), masterId, levelList)
}
return nil
}

+ 3
- 0
consume/init.go Dosyayı Görüntüle

@@ -17,6 +17,9 @@ func Init() {

// 增加消费任务队列
func initConsumes() {
jobs[consumeMd.ZhiosUserUpLvFunName] = ZhiosUserUpLv
jobs[consumeMd.CanalGuideOrderByUserUpLvConsume] = CanalGuideOrderByUserUpLvConsume
jobs[consumeMd.ZhiosOrderFreeFunName] = ZhiosOrderFree
jobs[consumeMd.ZhiosOrderTotalFunName] = ZhiosOrderTotal
jobs[consumeMd.ZhiosOrderTotalSecondFunName] = ZhiosOrderTotalSecond
//


+ 30
- 0
consume/md/consume_key.go Dosyayı Görüntüle

@@ -56,6 +56,15 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "CanalGuideOrderConsume",
},
{
ExchangeName: "canal.topic",
Name: "canal_guide_order_by_user_up_lv",
Type: TopicQueueType,
IsPersistent: false,
RoutKey: "canal_order_list",
BindKey: "",
ConsumeFunName: "CanalGuideOrderByUserUpLvConsume",
},
{
ExchangeName: "zhios.app.user.visit.ip.address.exchange",
Name: "zhios_user_visit_ip_address_queue",
@@ -335,6 +344,24 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "ZhiosOrderTotalSecond",
},
{
ExchangeName: "zhios.order_free.exchange",
Name: "zhios_order_free",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "order_free",
BindKey: "",
ConsumeFunName: "ZhiosOrderFree",
},
{
ExchangeName: "zhios.user_up_lv.exchange",
Name: "zhios_user_up_lv",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "user_up_lv",
BindKey: "",
ConsumeFunName: "ZhiosUserUpLv",
},
//{
// ExchangeName: "zhios.order_buckle.exchange",
// Name: "zhios_order_buckle_dev",
@@ -347,6 +374,9 @@ var RabbitMqQueueKeyList = []*MqQueue{
}

const (
ZhiosUserUpLvFunName = "ZhiosUserUpLv"
CanalGuideOrderByUserUpLvConsume = "CanalGuideOrderByUserUpLvConsume"
ZhiosOrderFreeFunName = "ZhiosOrderFree"
ZhiosOrderSettleTotalFunName = "ZhiosOrderSettleTotal"
ZhiosOrderTotalFunName = "ZhiosOrderTotal"
ZhiosOrderTotalSecondFunName = "ZhiosOrderTotalSecond"


+ 10
- 0
consume/md/free.go Dosyayı Görüntüle

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

type LimitBuyCondition struct {
MoregoodsBuyLimit string `json:"moregoods_buy_limit"`
OnegoodsBuyLimit string `json:"onegoods_buy_limit"`
MoregoodsBuyLimitDay string `json:"moregoods_buy_limit_day"`
OnegoodsBuyLimitDay string `json:"onegoods_buy_limit_day"`
OpenMoregoodsBuy string `json:"open_moregoods_buy"`
OpenOnegoodsBuy string `json:"open_onegoods_buy"`
}

+ 11
- 1
consume/md/md_zhios_capital_pool_order_total.go Dosyayı Görüntüle

@@ -23,7 +23,15 @@ type ZhiosOrderBuckle struct {
Uid string `json:"uid"`
Mid string `json:"mid"`
}

type ZhiosOrderFree struct {
ItemId string `json:"item_id"`
OptPvd string `json:"opt_pvd"`
OrderType string `json:"order_type"`
Pid string `json:"pid"`
Oid string `json:"oid"`
Uid string `json:"uid"`
Mid string `json:"mid"`
}
type ZhiosAppreciation struct {
Uid string `json:"uid"`
Mid string `json:"mid"`
@@ -44,4 +52,6 @@ type ZhiosGuideStoreOrder struct {
State string `json:"state"`
ItemId string `json:"item_id"`
Type string `json:"type"`
CoinId string `json:"coin_id"`
Stock string `json:"stock"`
}

+ 84
- 14
consume/zhios_guide_store_order_success.go Dosyayı Görüntüle

@@ -81,6 +81,30 @@ func handleZhiosGuideStoreOrderSuccess(msg []byte) error {
return err
}
}
if canalMsg.Type == "down" {
err := down(eg, canalMsg)
if err != nil {
return err
}
}
return nil
}

func down(eg *xorm.Engine, canalMsg *md.ZhiosGuideStoreOrder) error {
sess := eg.NewSession()
defer sess.Close()
sess.Begin()
//退积分
sum := canalMsg.DeductPrice
//退积分
// 111商家发布商品扣除 112商家商品审核失败退回 113 商家删除商品退回 114商品退款退回 115商家商品下架退回
err := UpdateUserFinValidAndInterFlowFreezeSess(sess,
utils.AnyToString(sum), "商品("+canalMsg.ItemId+")删除"+canalMsg.Stock+"个退回", "0", 1, utils.StrToInt(canalMsg.Uid), utils.StrToInt(canalMsg.CoinId), 113, utils.StrToInt64(utils.OrderUUID(utils.StrToInt(canalMsg.Uid))))
if err != nil {
sess.Rollback()
return err
}
sess.Commit()
return nil
}
func success(eg *xorm.Engine, canalMsg *md.ZhiosGuideStoreOrder) error {
@@ -160,6 +184,44 @@ func fail(eg *xorm.Engine, canalMsg *md.ZhiosGuideStoreOrder) error {
sess.Commit()
return nil
}
func UpdateUserFinValidAndInterFlowFreezeSess(session *xorm.Session, money, Title, fee string, types, uid, coinId, transferType int, ordId int64) error {
UserVirtualAmount, err := db.UserVirtualAmountFindByIdWithSession(session, uid, coinId)
if err != nil || UserVirtualAmount == nil {
if err == nil {
err = errors.New("获取用户余额信息失败")
}
return err
}
beforeAmount := UserVirtualAmount.Amount
freezeBeforeAmount := UserVirtualAmount.FreezeAmount

if types == 1 {
UserVirtualAmount.Amount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.Amount) + utils.StrToFloat64(money))
UserVirtualAmount.FreezeAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.FreezeAmount) - utils.StrToFloat64(money))
} else if types == 2 {
UserVirtualAmount.Amount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.Amount) - utils.StrToFloat64(money))
UserVirtualAmount.FreezeAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.FreezeAmount) + utils.StrToFloat64(money))
if utils.StrToFloat64(UserVirtualAmount.Amount) < 0 {
return errors.New("额度不足")
}
}
afterAmount := UserVirtualAmount.Amount
freezeAfterAmount := UserVirtualAmount.FreezeAmount

affected, err := db.UserVirtualAmountUpdateWithSession(session, uid, coinId, UserVirtualAmount, "amount,freeze_amount")
if err != nil || affected == 0 {
if err == nil {
err = errors.New("更新用户余额信息失败")
}
return err
}
err = virtualCoinFlowInsert(session, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount, freezeBeforeAmount, freezeAfterAmount)
if err != nil {
return err
}
return nil
}

func UpdateUserVirtualCoinFinValidAndInterFlow(sess *xorm.Session, money, Title, fee string, types, uid, coinId, transferType int, ordId int64) error {
UserVirtualAmount, err := db.UserVirtualAmountFindById(sess, uid, coinId)
if err != nil || UserVirtualAmount == nil {
@@ -169,6 +231,7 @@ func UpdateUserVirtualCoinFinValidAndInterFlow(sess *xorm.Session, money, Title,
return err
}
beforeAmount := UserVirtualAmount.Amount
freezeBeforeAmount := UserVirtualAmount.FreezeAmount
if types == 2 {
UserVirtualAmount.Amount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.Amount) - utils.StrToFloat64(money))
UserVirtualAmount.UseAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.UseAmount) + utils.StrToFloat64(money))
@@ -177,6 +240,8 @@ func UpdateUserVirtualCoinFinValidAndInterFlow(sess *xorm.Session, money, Title,
UserVirtualAmount.UseAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.UseAmount) - utils.StrToFloat64(money))
}
afterAmount := UserVirtualAmount.Amount
freezeAfterAmount := UserVirtualAmount.FreezeAmount

affected, err := db.UserVirtualAmountUpdate(sess, uid, coinId, UserVirtualAmount, "amount")
if err != nil || affected == 0 {
if err == nil {
@@ -184,7 +249,7 @@ func UpdateUserVirtualCoinFinValidAndInterFlow(sess *xorm.Session, money, Title,
}
return err
}
err = virtualCoinFlowInsert(sess, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount)
err = virtualCoinFlowInsert(sess, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount, freezeBeforeAmount, freezeAfterAmount)
if err != nil {
return err
}
@@ -200,6 +265,8 @@ func UpdateUserFinValidAndInterFlowFreeze(sess *xorm.Session, money, Title, fee
return err
}
beforeAmount := UserVirtualAmount.Amount
freezeBeforeAmount := UserVirtualAmount.FreezeAmount

if types == 2 {
UserVirtualAmount.FreezeAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.FreezeAmount) - utils.StrToFloat64(money))
UserVirtualAmount.UseAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.UseAmount) + utils.StrToFloat64(money))
@@ -208,6 +275,7 @@ func UpdateUserFinValidAndInterFlowFreeze(sess *xorm.Session, money, Title, fee
UserVirtualAmount.UseAmount = utils.AnyToString(utils.AnyToFloat64(UserVirtualAmount.UseAmount) - utils.StrToFloat64(money))
}
afterAmount := UserVirtualAmount.Amount
freezeAfterAmount := UserVirtualAmount.FreezeAmount
affected, err := db.UserVirtualAmountUpdate(sess, uid, coinId, UserVirtualAmount, "freeze_amount,use_amount")
if err != nil || affected == 0 {
if err == nil {
@@ -215,28 +283,30 @@ func UpdateUserFinValidAndInterFlowFreeze(sess *xorm.Session, money, Title, fee
}
return err
}
err = virtualCoinFlowInsert(sess, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount)
err = virtualCoinFlowInsert(sess, uid, coinId, money, fee, ordId, Title, types, transferType, beforeAmount, afterAmount, freezeBeforeAmount, freezeAfterAmount)
if err != nil {
return err
}
return nil
}
func virtualCoinFlowInsert(sess *xorm.Session, uid, coinId int, money, SysFee string, ordId int64, ItemTitle string, types, transferType int, beforeAmount string, afterAmount string) error {
func virtualCoinFlowInsert(sess *xorm.Session, uid, coinId int, money, SysFee string, ordId int64, ItemTitle string, types, transferType int, beforeAmount string, afterAmount string, freezeBeforeAmount string, freezeAfterAmount string) error {
now := time.Now()
if err := db.UserVirtualCoinFlowInsertOne(
sess,
&model.UserVirtualCoinFlow{
Uid: uid,
OrdId: utils.Int64ToStr(ordId),
CoinId: coinId,
Direction: types,
Title: ItemTitle,
Amout: money,
BeforeAmout: beforeAmount,
AfterAmout: afterAmount,
SysFee: SysFee,
CreateTime: now,
TransferType: transferType,
Uid: uid,
OrdId: utils.Int64ToStr(ordId),
CoinId: coinId,
Direction: types,
Title: ItemTitle,
Amout: money,
FreezeBeforeAmout: freezeBeforeAmount,
FreezeAfterAmout: freezeAfterAmount,
BeforeAmout: beforeAmount,
AfterAmout: afterAmount,
SysFee: SysFee,
CreateTime: now,
TransferType: transferType,
}); err != nil {
_ = logx.Warn(err)
return err


+ 83
- 0
consume/zhios_order_buckle.go Dosyayı Görüntüle

@@ -397,6 +397,89 @@ func OrderRelateInsert(eg *xorm.Engine, sess *xorm.Session, oid int64, pvd strin
}
return nil
}
func OrderRelateInsertNew(eg *xorm.Engine, sess *xorm.Session, oid int64, pvd string, createTime int, lvUser *comm_plan.LvUser, newOrd *model.OrdList, masterId string, isDelete bool, mode string, isNew string) error {
if lvUser == nil {
return nil
}
uid := lvUser.Uid
if uid == 0 {
return nil
}
oldLvUser := lvUser
oldLevel := 0
data := OrderRelateInsertComm(eg, oid, pvd, createTime, lvUser, newOrd, masterId, mode)
fmt.Println(data)

if data == nil || len(data) == 0 {
return nil
}
list, _ := db.OrderRelateFindByOid(sess, oid, pvd)
listMap := make(map[int]model.OrdListRelate)
if list != nil {
for _, v := range *list {
listMap[v.Uid] = v
}
}

fmt.Println(isDelete)
_, err2 := db.OrderRelateDeleteByOid(sess, oid, pvd)
if err2 != nil {
return err2
}
_, err2 = db.VirtualCoinOrderRelateDeleteByOid(sess, oid, pvd)
if err2 != nil {
return err2
}
//后写入
err := db.DbInsertBatchSess(sess, data)
if err != nil {
return err

} else if lvUser.ProfitList != nil {
// 插入虚拟币数据
vcrData := CombineVirtualCoinRelateData(oldLvUser, oid, pvd, oldLevel, mode)
if len(vcrData) == 0 {
return nil
}
err := db.DbInsertBatchSess(sess, vcrData)
if err != nil {
return err

}
}
if lvUser.TikTokOwnSubsidyFeeList != nil {
_, err2 := db.TikTokTeamOrderRelateDeleteByOid(sess, oid, pvd)
if err != nil {
return err2
}
var teamData []model.TikTokTeamOrderRelate
TikTokTeamCommission := newOrd.TikTokTeamCommission
if utils.StrToFloat64(newOrd.TikTokTeamRealCommission) > 0 {
TikTokTeamCommission = newOrd.TikTokTeamRealCommission
}
for k, v := range lvUser.TikTokOwnSubsidyFeeList {
tmp := model.TikTokTeamOrderRelate{
CoinId: utils.StrToInt(k),
Uid: uid,
Amount: utils.Float64ToStrByPrec(v, 8),
Oid: utils.Int64ToStr(oid),
Time: time.Now(),
Commission: TikTokTeamCommission,
Pvd: pvd,
}
teamData = append(teamData, tmp)
}
if len(teamData) == 0 {
return nil
}
err := db.DbInsertBatchSess(sess, &teamData)
if err != nil {
return err

}
}
return nil
}
func CombineVirtualCoinRelateData(lvUser *comm_plan.LvUser, oid int64, pvd string, level int, mode string) []*model.VirtualCoinRelate {
var data []*model.VirtualCoinRelate
//可能没有极差返利 只有补贴


+ 360
- 0
consume/zhios_order_free.go Dosyayı Görüntüle

@@ -0,0 +1,360 @@
package consume

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"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
md3 "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/svc"
"encoding/json"
"errors"
"fmt"
"github.com/streadway/amqp"
"strings"
"time"
"xorm.io/xorm"
)

func ZhiosOrderFree(queue md.MqQueue) {
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>")
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
logx.Error(err)
return
}
defer ch.Release()
//1、将自己绑定到交换机上
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
//2、取出数据进行消费
ch.Qos(100)
delivery := ch.Consume(queue.Name, false)

var res amqp.Delivery
var ok bool
for {
res, ok = <-delivery
if ok == true {
//fmt.Println(string(res.Body))
fmt.Println(">>>>>>>>>>>>>>>>CanalOrderConsume<<<<<<<<<<<<<<<<<<<<<<<<<")
err = handleZhiosOrderFree(res.Body)
//_ = res.Reject(false)
if err == nil {
_ = res.Ack(true)
}
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleZhiosOrderFree(msg []byte) error {
time.Sleep(time.Microsecond * 20) // 等待500毫秒
//1、解析canal采集至mq中queue的数据结构体
var canalMsg *md.ZhiosOrderFree
fmt.Println(string(msg))
var tmpString string
err := json.Unmarshal(msg, &tmpString)
if err != nil {
fmt.Println("===with", err.Error())
return err
}
fmt.Println(tmpString)
err = json.Unmarshal([]byte(tmpString), &canalMsg)
if err != nil {
fmt.Println("===with", err.Error())
return err
}
mid := canalMsg.Mid
eg := db.DBs[mid]
if eg == nil {
return nil
}
sess := eg.NewSession()
defer sess.Close()
sess.Begin()
ordData, err := db.OrderListByPvdOid(sess, canalMsg.Oid)
if err != nil || ordData == nil {
return nil
}
if ordData.State > 3 || ordData.PriceType > 0 {
return nil
}
//if ordData.PriceType > 0 {
// return nil
//}
freeNewType := db.SysCfgGetWithDb(eg, canalMsg.Mid, "free_new_type")
freeOrder := orderFreeCheck(eg, sess, canalMsg)
if freeOrder != nil {
priceType := freeOrder.PriceType
ordData.PriceType = priceType
fee := utils.StrToFloat64(freeOrder.Fee)
allCommission := utils.StrToFloat64(freeOrder.ReturnMoney)
ordData.BenefitAll = allCommission
ownbuyReturnType := 0
if freeOrder.OwnbuyReturnType == 0 && freeOrder.ReturnType == 1 { //自购补贴等于0为关闭 并且是淘礼金商品
ownbuyReturnType = 1
}
storeId := freeOrder.StoreId
bili := utils.StrToFloat64(freeOrder.Bili)
//加入分佣关系链
opts, commissionOpts, _ := svc.GetAllPlan(eg, canalMsg.Mid)
if opts == nil {
sess.Commit()

return nil
}
if canalMsg.OrderType == "6" || canalMsg.OrderType == "7" {
ordData.OrderType = 3 //淘礼金免单
}
BenefitAll := ordData.BenefitAll
pvd := "free"
var rmd = md3.CommissionParam{IsTikTokTeamOrder: utils.IntToStr(ordData.IsTikTokTeamOrder)}
opt, err := svc.GetPlanCfg(eg, pvd, canalMsg.Mid, opts, commissionOpts, map[int]string{}, &rmd)
if err != nil {
sess.Commit()
return nil
}
var ord = md2.OrderInfo{
PvdOid: ordData.PvdOid,
Pvd: pvd,
ItemId: ordData.ItemId,
ItemNum: ordData.ItemNum,
ItemPrice: ordData.ItemPrice,
PaidPrice: ordData.PaidPrice,
OrderType: ordData.OrderType,
Commission: BenefitAll,
State: ordData.State,
}

//调用公共的分佣
isShare := 0
if ord.OrderType == 1 {
isShare = 1
}
//计算每个用户的分佣
req := md2.CommissionFirstParam{
CommissionParam: md2.CommissionParam{
Commission: utils.Float64ToStr(ord.Commission),
PaidPrice: utils.Float64ToStr(ord.PaidPrice),
OldPrice: utils.Float64ToStr(ord.PaidPrice),
IsTikTokTeamOrder: utils.IntToStr(ordData.IsTikTokTeamOrder),
},
Uid: utils.IntToStr(ordData.Uid),
IsShare: isShare,
Provider: ord.Pvd,
IsAllLevelReturn: 1,
OwnbuyReturnType: ownbuyReturnType,
}
if utils.InArr(ord.Pvd, []string{md3.PVD_TB, md3.PVD_TM, md3.PVD_PDD, md3.PVD_SN, md3.PVD_KL, md3.PVD_JD, md3.PVD_JDOwn, md3.PVD_VIP}) == false {
req.CommissionParam.GoodsPrice = utils.Float64ToStr(ord.PaidPrice)
}
commissionList, err := GetCommissionByCommApi(eg, canalMsg.Mid, req)
if err != nil || commissionList.LvUser == nil {
sess.Commit()
return nil
}
pvdFee := commissionList.PvdFee
sysFee := commissionList.SysFee
subsidyFee := commissionList.SubsidyFee
lvUser := commissionList.LvUser
profit := commissionList.Profit
ordData.SubsidyFee = subsidyFee
ordData.PvdCommission = pvdFee
ordData.SysCommission = sysFee
var selfRate float64 = 0
var subsidyRate float64 = 0
//处理记录佣金
if opt != nil {
profit = lvUser.Profit
//判断下这个等级有么有设置
ordData.UserCommission = profit
ordData.SubsidyRate = subsidyRate
ordData.UserCommissionRate = selfRate
ordData.PlanCommissionId = opt.PlanCommissionId
ordData.BenefitList = SerializeLvUser(NewCalcLvUserFee(lvUser))
}
if storeId > 0 {
deductPrice := (allCommission + fee) * bili
arg := md.ZhiosGuideStoreOrder{
Uid: utils.IntToStr(ordData.Uid),
Mid: canalMsg.Mid,
Oid: ordData.PvdOid,
StoreId: utils.IntToStr(storeId),
DeductPrice: utils.Float64ToStr(deductPrice),
ItemTitle: ord.ItemTitle,
Pvd: "free",
SubsidyPrice: utils.Float64ToStr(allCommission),
Fee: utils.Float64ToStr(fee),
State: utils.IntToStr(ordData.State),
Type: "success",
}
ordData.Data = utils.SerializeStr(arg)
}
has, _ := db.OrderListByUpdateOrd(sess, ordData)
if has == false {
sess.Rollback()
return nil
}

//批量写入
if lvUser != nil {
if freeNewType == "1" {
lvUser.AdditionalSubsidy = ordData.BenefitAll
}
err := OrderRelateInsertNew(eg, sess, ordData.OrdId, ordData.Pvd, ordData.CreateAt, lvUser, ordData, canalMsg.Mid, true, opt.Mode, "1")
if err != nil {
sess.Rollback()
return err
}
}
}
sess.Commit()

return nil
}
func orderFreeCheck(eg *xorm.Engine, sess *xorm.Session, canalMsg *md.ZhiosOrderFree) *model.NewcomersFreeProduct {

m, err := db.FreeProductByID(sess, canalMsg.ItemId, canalMsg.OptPvd)
stock := 0
if m != nil && m.StoreId > 0 { //小于多少份就不能出售了
guideStoreStock := db.SysCfgGetWithDb(eg, canalMsg.Mid, "guide_store_stock")
stock = utils.StrToInt(guideStoreStock)
}
if err != nil || m == nil || (m != nil && m.Stock <= stock) {
sess.Rollback()
return nil
}

if strings.Contains(canalMsg.Pid, "free_") && m.ReturnType == 0 {
mt, err := db.FreePriceTypeByID(sess, m.PriceType)
if err != nil || mt == nil {
sess.Rollback()

return nil
}
limitBuyConditions := &md.LimitBuyCondition{}
utils.Unserialize([]byte(mt.LimitBuyCondition), limitBuyConditions)
//判断条件前,先判断下有没有限购
if mt.NeedLimitBuy == 1 {
//判断当前栏目购买商品数量 并且开启了
if limitBuyConditions.OpenMoregoodsBuy == "1" && utils.StrToInt64(limitBuyConditions.MoregoodsBuyLimit) > 0 {
moreGoodsCount, _ := db.OrderListCountByPriceType(sess, canalMsg.Uid, mt.Id, utils.StrToInt(limitBuyConditions.MoregoodsBuyLimitDay))
if moreGoodsCount+1 > utils.StrToInt64(limitBuyConditions.MoregoodsBuyLimit) {
sess.Rollback()

return nil
}
}
//判断当前栏目购买商品数量 并且开启了
if limitBuyConditions.OpenOnegoodsBuy == "1" && utils.StrToInt64(limitBuyConditions.OnegoodsBuyLimit) > 0 {
moreGoodsCount, _ := db.OrderListCountByItemId(sess, canalMsg.Uid, canalMsg.ItemId, utils.StrToInt(limitBuyConditions.OnegoodsBuyLimitDay))
if moreGoodsCount+1 > utils.StrToInt64(limitBuyConditions.OnegoodsBuyLimit) {
sess.Rollback()
return nil
}
}
}
// 查找用户剩余的免单资格数
profile, err := db.UserProfileFindByID(eg, canalMsg.Uid)
if err != nil || profile == nil {
logx.Warn(err)
sess.Rollback()

return nil
}
if m.StoreId > 0 {
//商家放单 查下冻结
coinId := db.SysCfgGetWithDb(eg, canalMsg.Uid, "guide_store_coin_id")
amount := db.GetUserVirtualCoinAmount(eg, m.StoreId, coinId)
if amount == nil {
sess.Rollback()

return nil
}
if utils.StrToFloat64(amount.FreezeAmount) < utils.StrToFloat64(m.ReturnMoney) {
sess.Rollback()

return nil
}
}

//判断要不要扣免单券
if mt.NeedUseQuan == 1 {
// 更新剩余次数
isNeed := 1
if mt.NeedQuan == 0 {
isNeed = 0
}
if mt.NeedQuan > profile.FreeRemainTime {
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
}
}
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
}
// 插入日志记录
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 {
m.Stock = 0
}
m.Sale++
_, err = eg.Where("id=?", m.Id).Cols("stock,sale").Update(m)
if err != nil {
sess.Rollback()
return nil
}
if m.StoreId > 0 { //扣库存
var storeGoods model.GuideStoreGoods
_, err := sess.Where("gid=? and delete_time is null and stock>?", m.GoodId, 0).Get(&storeGoods)
if err != nil {
sess.Rollback()
return nil
}
storeGoods.Stock--
if storeGoods.Stock < 0 {
storeGoods.DownState = 3
storeGoods.EndTime = int(time.Now().Unix())
}
_, err = sess.Where("id=?", storeGoods.Id).Cols("down_state,end_time,stock").Update(&storeGoods)
if err != nil {
sess.Rollback()
return nil
}
}
sess.Commit()
return m
}
sess.Commit()
return m
}

+ 83
- 0
consume/zhios_user_up_lv.go Dosyayı Görüntüle

@@ -0,0 +1,83 @@
package consume

import (
"applet/app/db"
"applet/app/utils"
"applet/app/utils/logx"
"applet/consume/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"encoding/json"
"errors"
"fmt"
"github.com/streadway/amqp"
)

//自动升级
func ZhiosUserUpLv(queue md.MqQueue) {
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>")
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
logx.Error(err)
return
}
defer ch.Release()
//1、将自己绑定到交换机上
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
//2、取出数据进行消费
ch.Qos(1000)
delivery := ch.Consume(queue.Name, false)

var res amqp.Delivery
var ok bool
for {
res, ok = <-delivery
if ok == true {
//fmt.Println(string(res.Body))
fmt.Println(">>>>>>>>>>>>>>>>CanalOrderConsume<<<<<<<<<<<<<<<<<<<<<<<<<")
err = handleUserUpLv(res.Body)
//_ = res.Reject(false)
fmt.Println(err)
_ = res.Ack(true)
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleUserUpLv(msg []byte) error {
//1、解析canal采集至mq中queue的数据结构体
var canalMsg *md.ZhiosAcquisition
fmt.Println(string(msg))
var tmpString string
err := json.Unmarshal(msg, &tmpString)
if err != nil {
fmt.Println(err.Error())
return err
}
fmt.Println(tmpString)
err = json.Unmarshal([]byte(tmpString), &canalMsg)
if err != nil {
return err
}
mid := canalMsg.Mid
eg := db.DBs[mid]
uid := canalMsg.Uid
levelList, _ := db.UserLevlEgAll(eg)
isAuto := 0
for _, v := range levelList {
if v.AutoUpdate == 1 {
isAuto = 1
}
}
if isAuto == 0 {
return nil
}
FindUser(eg, uid, mid, levelList)
oneUser, _ := db.UserProfileFindByID(eg, uid)
if oneUser == nil || (oneUser != nil && oneUser.ParentUid == 0) {
return nil
}
FindUser(eg, utils.IntToStr(oneUser.ParentUid), mid, levelList)
return nil
}

Yükleniyor…
İptal
Kaydet