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