huangjiajun 11 месяцев назад
Родитель
Сommit
bc0f6d7b72
13 измененных файлов: 578 добавлений и 8 удалений
  1. +22
    -0
      app/db/db_newcomers_free_price_type.go
  2. +3
    -3
      app/db/db_newcomers_free_product.go
  3. +12
    -4
      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. +1
    -0
      consume/init.go
  9. +10
    -0
      consume/md/consume_key.go
  10. +10
    -0
      consume/md/free.go
  11. +9
    -1
      consume/md/md_zhios_capital_pool_order_total.go
  12. +83
    -0
      consume/zhios_order_buckle.go
  13. +347
    -0
      consume/zhios_order_free.go

+ 22
- 0
app/db/db_newcomers_free_price_type.go Просмотреть файл

@@ -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 Просмотреть файл

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


+ 12
- 4
app/db/db_order.go Просмотреть файл

@@ -37,6 +37,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,8 +446,8 @@ 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))
}
@@ -447,8 +455,8 @@ func OrderListCountByPriceType(Db *xorm.Engine, uid string, priceType, day int)
}

// 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 = ?", uid, itemId)
if day > 0 {
sess = sess.And("create_at>=?", time.Now().Unix()-int64(day*86400))
}


+ 18
- 0
app/db/db_user_virtual_coin_amount.go Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

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

+ 1
- 0
consume/init.go Просмотреть файл

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

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


+ 10
- 0
consume/md/consume_key.go Просмотреть файл

@@ -326,6 +326,15 @@ 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.order_buckle.exchange",
// Name: "zhios_order_buckle_dev",
@@ -338,6 +347,7 @@ var RabbitMqQueueKeyList = []*MqQueue{
}

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


+ 10
- 0
consume/md/free.go Просмотреть файл

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

+ 9
- 1
consume/md/md_zhios_capital_pool_order_total.go Просмотреть файл

@@ -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"`


+ 83
- 0
consume/zhios_order_buckle.go Просмотреть файл

@@ -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
//可能没有极差返利 只有补贴


+ 347
- 0
consume/zhios_order_free.go Просмотреть файл

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

import (
"applet/app/db"
"applet/app/db/model"
md2 "applet/app/md"
"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 {
// 更新剩余次数
if mt.NeedQuan > profile.FreeRemainTime {
sess.Rollback()

return nil
}
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
}

Загрузка…
Отмена
Сохранить