Browse Source

Merge remote-tracking branch 'origin/master'

three
DengBiao 11 months ago
parent
commit
cdf70511a5
14 changed files with 576 additions and 126 deletions
  1. +12
    -0
      app/db/db_newcomers_free_price_type.go
  2. +24
    -0
      app/db/db_newcomers_free_product.go
  3. +16
    -1
      app/db/db_order.go
  4. +3
    -0
      app/db/db_user_virtual_coin_amount.go
  5. +17
    -0
      app/db/model/more_newcomers_free_price_type.go
  6. +36
    -0
      app/db/model/more_newcomers_free_product.go
  7. +1
    -0
      app/db/model/ord_list.go
  8. +21
    -0
      app/db/model/third_newcomers_qualification_record.go
  9. +2
    -0
      app/db/model/user_profile.go
  10. +55
    -0
      app/svc/svc_perm.go
  11. +1
    -1
      consume/init.go
  12. +383
    -120
      consume/zhios_order_free.go
  13. +3
    -0
      consume/zhios_user_up_lv.go
  14. +2
    -4
      go.mod

+ 12
- 0
app/db/db_newcomers_free_price_type.go View File

@@ -20,3 +20,15 @@ func FreePriceTypeByID(sess *xorm.Session, id interface{}) (*model.NewcomersFree
return m, nil

}
func MoreFreePriceTypeByID(sess *xorm.Session, id interface{}) (*model.MoreNewcomersFreePriceType, error) {
m := new(model.MoreNewcomersFreePriceType)
has, err := sess.ID(id).Get(m)
if err != nil {
return nil, err
}
if !has {
return nil, errors.New("Not Found")
}
return m, nil

}

+ 24
- 0
app/db/db_newcomers_free_product.go View File

@@ -35,3 +35,27 @@ func FreeProductByID(sess *xorm.Session, gid, provider string) (*model.Newcomers

return m, nil
}
func MoreFreeProductByID(sess *xorm.Session, gid, provider string) (*model.MoreNewcomersFreeProduct, error) {
m := new(model.MoreNewcomersFreeProduct)
var has bool
var err error
if utils.InArr(provider, []string{"taobao", "tmall"}) && php2go.IsNumeric(gid) == false {
gidArr := strings.Split(gid, "-")
if len(gidArr) == 2 {
gid = gidArr[1]
}
has, err = sess.Where("good_id LIKE ?", "%-"+gid).Get(m)
} else {
m.GoodId = gid
has, err = sess.Get(m)
}

if err != nil {
return nil, err
}
if !has {
return nil, errors.New("Not Found")
}

return m, nil
}

+ 16
- 1
app/db/db_order.go View File

@@ -463,7 +463,22 @@ func OrderListCountByItemId(sess *xorm.Session, uid string, itemId string, day i
}
return sess.Count(&model.OrdList{})
}

func OrderListCountByMorePriceType(sess *xorm.Session, uid string, priceType, day int) (int64, error) {
sess = sess.Where(" uid = ? AND state != 4 AND third_price_type= ?", uid, priceType)
if day > 0 {
today := utils.GetTimeRange("today")
sess = sess.And("create_at>=?", today["end"]-int64(day*86400))
}
return sess.Count(&model.OrdList{})
}
func OrderListCountByMoreItemId(sess *xorm.Session, uid string, itemId string, day int) (int64, error) {
sess = sess.Where(" uid = ? AND state != 4 AND item_id = ? and third_price_type>0", uid, itemId)
if day > 0 {
today := utils.GetTimeRange("today")
sess = sess.And("create_at>=?", today["end"]-int64(day*86400))
}
return sess.Count(&model.OrdList{})
}
func OrderUpdateWithSession(session *xorm.Session, ordId int64, order *model.OrdList, forceCols ...string) (int64, error) {
var (
affected int64


+ 3
- 0
app/db/db_user_virtual_coin_amount.go View File

@@ -16,3 +16,6 @@ func GetUserVirtualCoinAmount(eg *xorm.Engine, uid int, coinId string) *model.Us
func FreeQualificationRecordInsertOne(Db *xorm.Engine, m *model.NewcomersQualificationRecord) (int64, error) {
return Db.InsertOne(m)
}
func ThirdFreeQualificationRecordInsertOne(Db *xorm.Engine, m *model.ThirdNewcomersQualificationRecord) (int64, error) {
return Db.InsertOne(m)
}

+ 17
- 0
app/db/model/more_newcomers_free_price_type.go View File

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

type MoreNewcomersFreePriceType 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"`
CommissionId string `json:"commission_id" xorm:"default '' VARCHAR(255)"`
CommissionData string `json:"commission_data" xorm:"default '' VARCHAR(500)"`
}

+ 36
- 0
app/db/model/more_newcomers_free_product.go View File

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

import (
"time"
)

type MoreNewcomersFreeProduct struct {
Id int `json:"id" xorm:"not null pk autoincr INT(10)"`
GoodId string `json:"good_id" xorm:"not null default '' comment('平台商品ID') VARCHAR(255)"`
Source string `json:"source" xorm:"not null default 'taobao' comment('来源平台') VARCHAR(255)"`
SourceUrl string `json:"source_url" xorm:"not null default '' comment('用户输入地址') VARCHAR(255)"`
PriceType int `json:"price_type" xorm:"not null default 0 comment('所属价格类型') TINYINT(1)"`
OriginalPrice string `json:"original_price" xorm:"not null default 0.00 comment('原价') DECIMAL(10,2)"`
CouponPrice string `json:"coupon_price" xorm:"not null default 0.00 comment('券后价格') DECIMAL(10,2)"`
ReturnMoney string `json:"return_money" xorm:"not null default 0.00 comment('返还的钱') DECIMAL(10,2)"`
Bili string `json:"bili" xorm:"not null default 0.00 comment('返还的钱') DECIMAL(10,2)"`
Fee string `json:"fee" xorm:"not null default 0.00 comment('') DECIMAL(10,2)"`
Money string `json:"money" xorm:"not null default 0 comment('实付金额') DECIMAL(10)"`
Stock int `json:"stock" xorm:"not null default 0 comment('库存数量') INT(11)"`
Sale int `json:"sale" xorm:"not null default 0 comment('卖掉的数量') INT(11)"`
EndTime time.Time `json:"end_time" xorm:"not null comment('结束时间') DATETIME"`
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否上架') TINYINT(1)"`
IsDel int `json:"is_del" xorm:"not null default 0 comment('是否删除') TINYINT(1)"`
CreatedAt int `json:"created_at" xorm:"not null default 0 INT(11)"`
UpdatedAt int `json:"updated_at" xorm:"not null default 0 INT(11)"`
Title string `json:"title" xorm:"not null default '' comment('标题') VARCHAR(255)"`
StartTime time.Time `json:"start_time" xorm:"not null comment('开始时间') DATETIME"`
Pictures string `json:"pictures" xorm:"not null default '' comment('图片地址') VARCHAR(255)"`
CouponUrl string `json:"coupon_url" xorm:"not null default '' comment('优惠券链接') VARCHAR(255)"`
ActivityId string `json:"activity_id" xorm:"not null default '' comment('优惠券链接') VARCHAR(255)"`
Amount int `json:"amount" xorm:"default 0 comment('总数') INT(11)"`
ReturnType int `json:"return_type" xorm:"default 0 comment('0平台补贴 1 淘礼金补贴') INT(1)"`
OwnbuyReturnType int `json:"ownbuy_return_type" xorm:"default 0 comment('自购补贴:1开启、0关闭') INT(1)"`
StoreId int `json:"store_id" xorm:"default 0 comment('') INT(11)"`
Sort int `json:"sort" xorm:"default 0 comment('') INT(11)"`
}

+ 1
- 0
app/db/model/ord_list.go View File

@@ -13,6 +13,7 @@ type OrdList struct {
PaidPrice float64 `xorm:"not null default 0.00 DOUBLE(10,2)" json:"paid_price"`
OrderType int `xorm:"not null default 0 TINYINT(1)" json:"order_type"`
PriceType int `xorm:"not null default 0 INT(1)" json:"price_type"`
ThirdPriceType int `xorm:"not null default 0 INT(1)" json:"third_price_type"`
OrderCompare int `xorm:"not null default 0 TINYINT(1)" json:"order_compare"`
SubsidyFee float64 `xorm:"not null default 0.00 DOUBLE(8,2)" json:"subsidy_fee"`
SubsidyRate float64 `xorm:"not null default 0.0000 DOUBLE(10,4)" json:"subsidy_rate"`


+ 21
- 0
app/db/model/third_newcomers_qualification_record.go View File

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

import (
"time"
)

type ThirdNewcomersQualificationRecord 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"`
}

+ 2
- 0
app/db/model/user_profile.go View File

@@ -89,4 +89,6 @@ admin:管理员添加;taobao_bind_phone:淘宝注册绑定手机号,apple_bi
IsDelete int `json:"is_delete" xorm:"not null default 0 comment('是否已删除') TINYINT(1)"`
UpdateAt time.Time `json:"update_at" xorm:"updated not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
IsSet int `json:"is_set" xorm:"not null default 0 comment('用于一个客户生成关系链匹配的') INT(1)"`
ThirdFreeRemainTime int `json:"third_free_remain_time" xorm:"not null default 0 comment('免单剩余次数') INT(11)"`
ThirdFreeCumulativeTime int `json:"third_free_cumulative_time" xorm:"not null default 0 comment('免单累计次数') INT(11)"`
}

+ 55
- 0
app/svc/svc_perm.go View File

@@ -71,6 +71,61 @@ func CheckNewOrderAuth(eg *xorm.Engine, uid int, thisPrice *model.NewcomersFreeP
}
return r, perm
}
func MoreCheckNewOrderAuth(eg *xorm.Engine, uid int, thisPrice *model.MoreNewcomersFreePriceType) (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 {


+ 1
- 1
consume/init.go View File

@@ -65,7 +65,7 @@ func initConsumes() {
//jobs[consumeMd.ZhiosCapitalPoolOrderTotalFunName] = ZhiosCapitalPoolOrderTotal
//jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail
//jobs[consumeMd.ZhiosWithdrawReward] = ZhiosWithdrawReward
//
//jobs[consumeMd.ZhiosRechargeOrderFailDevFunName] = ZhiosRechargeOrderFailDev

////////////////////////////////////// V1 /////////////////////////////////////////////////////


+ 383
- 120
consume/zhios_order_free.go View File

@@ -82,135 +82,258 @@ func handleZhiosOrderFree(msg []byte) error {
if err != nil || ordData == nil {
return nil
}
if ordData.State > 3 || ordData.PriceType > 0 {
if ordData.State > 3 || ordData.PriceType > 0 || ordData.ThirdPriceType > 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()
if canalMsg.OrderType == "13" {
freeNewType := db.SysCfgGetWithDb(eg, canalMsg.Mid, "more_free_new_type")
freeOrder := moreOrderFreeCheck(eg, sess, canalMsg)
if freeOrder != nil {
priceType := freeOrder.PriceType
ordData.ThirdPriceType = 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,
}
return nil
}
BenefitAll := ordData.BenefitAll
pvd := "moreFree_" + utils.IntToStr(priceType)
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
//调用公共的分佣
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
}
}
}
} else {
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()

//批量写入
if lvUser != nil {
if freeNewType == "1" {
lvUser.AdditionalSubsidy = ordData.BenefitAll
return nil
}
if canalMsg.OrderType == "6" || canalMsg.OrderType == "7" {
ordData.OrderType = 3 //淘礼金免单
}
err := OrderRelateInsertNew(eg, sess, ordData.OrdId, ordData.Pvd, ordData.CreateAt, lvUser, ordData, canalMsg.Mid, true, opt.Mode, "1")
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 err
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
}
}
}
}
@@ -358,3 +481,143 @@ func orderFreeCheck(eg *xorm.Engine, sess *xorm.Session, canalMsg *md.ZhiosOrder
sess.Commit()
return m
}
func moreOrderFreeCheck(eg *xorm.Engine, sess *xorm.Session, canalMsg *md.ZhiosOrderFree) *model.MoreNewcomersFreeProduct {

m, err := db.MoreFreeProductByID(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, "moreFree_") && m.ReturnType == 0 {
mt, err := db.MoreFreePriceTypeByID(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.OrderListCountByMorePriceType(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.OrderListCountByMoreItemId(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.ThirdFreeRemainTime {
auth, perm := svc2.MoreCheckNewOrderAuth(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.ThirdFreeRemainTime = profile.ThirdFreeRemainTime - mt.NeedQuan
_, err = db.UserProfileUpdate(eg, profile.Uid, profile, "third_free_remain_time")
if err != nil {
logx.Warn(err)
sess.Rollback()

return nil
}
// 插入日志记录
db.ThirdFreeQualificationRecordInsertOne(eg, &model.ThirdNewcomersQualificationRecord{
Uid: profile.Uid,
Source: 3,
SourceText: "消费扣除",
OrderId: utils.StrToInt64(canalMsg.Oid),
ChangeNum: -mt.NeedQuan,
AfterChangeNum: profile.ThirdFreeRemainTime,
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
}

+ 3
- 0
consume/zhios_user_up_lv.go View File

@@ -62,6 +62,9 @@ func handleUserUpLv(msg []byte) error {
}
mid := canalMsg.Mid
eg := db.DBs[mid]
if eg == nil {
return nil
}
uid := canalMsg.Uid
levelList, _ := db.UserLevlEgAll(eg)
isAuto := 0


+ 2
- 4
go.mod View File

@@ -6,7 +6,7 @@ require (
code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git v1.1.2-0.20231117125527-cb06c9e24f3f
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.0
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.4
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20231213085413-6f5ba418f36c
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20240104094422-d0d0ef549175
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20231116085701-9ba6e19f877b
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20231221064048-3937c0824e59
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
@@ -28,6 +28,7 @@ require (
github.com/jinzhu/copier v0.3.5
github.com/json-iterator/go v1.1.12
github.com/makiuchi-d/gozxing v0.1.1
github.com/mingrammer/commonregex v1.0.1
github.com/robfig/cron/v3 v3.0.1
github.com/shopspring/decimal v1.3.1
github.com/sony/sonyflake v1.0.0
@@ -44,7 +45,6 @@ require (
)

require (
github.com/360EntSecGroup-Skylar/excelize v1.4.1 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
@@ -64,10 +64,8 @@ require (
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mingrammer/commonregex v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/mvdan/xurls v1.1.0 // indirect
github.com/nilorg/sdk v0.0.0-20221104025912-4b6ccb7004d8 // indirect
github.com/olivere/elastic/v7 v7.0.32 // indirect


Loading…
Cancel
Save