|
@@ -0,0 +1,938 @@ |
|
|
|
|
|
package svc |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
|
"applet/app/cfg" |
|
|
|
|
|
"applet/app/utils/cache" |
|
|
|
|
|
md3 "code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/md" |
|
|
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/svc" |
|
|
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" |
|
|
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git/o2o" |
|
|
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/lib/comm_plan" |
|
|
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement" |
|
|
|
|
|
"fmt" |
|
|
|
|
|
"github.com/tidwall/gjson" |
|
|
|
|
|
"strings" |
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"xorm.io/xorm" |
|
|
|
|
|
|
|
|
|
|
|
"applet/app/db" |
|
|
|
|
|
"applet/app/db/model" |
|
|
|
|
|
"applet/app/lib/plan" |
|
|
|
|
|
"applet/app/md" |
|
|
|
|
|
"applet/app/utils" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// 订单入库, TODO 1. 入库, 判断订单是否已经在库, 并到各个会员里面进行订单判断分润状态, 2.算利并进行分配, 所有订单都要进行拆单, 包括从智盟获取的订单 |
|
|
|
|
|
func OrderSaveCreateUpdateZero(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts map[string]*plan.PlanOpt, secondOpts map[string]*plan.PlanOpt, dbName string) error { |
|
|
|
|
|
var ( |
|
|
|
|
|
allOrdIds []string |
|
|
|
|
|
pids []string // |
|
|
|
|
|
allStationOrdIds []int64 |
|
|
|
|
|
stationOrdIds []int64 |
|
|
|
|
|
) |
|
|
|
|
|
littlePocket := db.SysCfgFindWithDb(eg, dbName, "little_pocket_basic_data") |
|
|
|
|
|
returnMoneyType := "0" |
|
|
|
|
|
if littlePocket != nil && gjson.Get(littlePocket["little_pocket_basic_data"], "return_money_type").String() == "1" { |
|
|
|
|
|
returnMoneyType = "1" |
|
|
|
|
|
} |
|
|
|
|
|
var ch *rabbit.Channel |
|
|
|
|
|
var err error |
|
|
|
|
|
//if cfg.Prd { |
|
|
|
|
|
ch, err = rabbit.Cfg.Pool.GetChannel() |
|
|
|
|
|
if err == nil { |
|
|
|
|
|
defer ch.Release() |
|
|
|
|
|
} |
|
|
|
|
|
//} |
|
|
|
|
|
ords := map[string]md.OrderInfo{} |
|
|
|
|
|
for _, v := range *ordData { |
|
|
|
|
|
// 如果订单存在则更改订单状态, 其它不需要操作, 结算由另外一个任务进行结算 |
|
|
|
|
|
ords[v.PvdOid] = v |
|
|
|
|
|
// 计算推广位 |
|
|
|
|
|
if v.Pid != "" { |
|
|
|
|
|
pids = append(pids, v.Pid) |
|
|
|
|
|
} |
|
|
|
|
|
allOrdIds = append(allOrdIds, v.PvdOid) |
|
|
|
|
|
} |
|
|
|
|
|
fmt.Println(pids) |
|
|
|
|
|
if strings.Contains(pvd, "meituan") { |
|
|
|
|
|
pvd = "meituan" |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == "hw_movie" { |
|
|
|
|
|
pvd = "cinema" |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_PDDUNIONOWN || pvd == md.PVD_PDDBYCREATETIME || pvd == md.PVD_PDDBYAGOTIME || pvd == md.PVD_PDDBYSTATUS || pvd == md.PVD_PDDBYSTATUSSUCCESS || pvd == md.PVD_PDDBYSTATUSFAIL { //判断下拼多多 |
|
|
|
|
|
pvd = md.PVD_PDD |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if pvd == md.PVD_JDUNIONOWN || pvd == md.PVD_JDUNIONOWNUPDATE || pvd == md.PVD_JDBYCREATETIME || pvd == md.PVD_JDBYSUCCESS || pvd == md.PVD_JDFAILBYCREATETIME || pvd == md.PVD_JDBYSTATUS { //判断下京东 |
|
|
|
|
|
pvd = md.PVD_JD |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{"csjp_create", "own_csjp", "own_csjp_activity"}) { |
|
|
|
|
|
pvd = "csjp" |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{"own_csjp_live"}) { |
|
|
|
|
|
pvd = "csjp_live" |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{md.PVD_TB12, md.PVD_TB13, md.PVD_TB14, md.PVD_TB3, md.PVD_TBBYPAY, md.PVD_TBBYCREATETIME, md.PVD_TBBYSETTLE}) { |
|
|
|
|
|
pvd = md.PVD_TB |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_DIDI_ENERGY { // |
|
|
|
|
|
pvd = "oil" |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_TO_KFC { //判断下 |
|
|
|
|
|
pvd = md.PVD_KFC |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if pvd == md.PVD_TIKTOKOWNLIVE { //判断下 |
|
|
|
|
|
pvd = md.PVD_TIKTOKLIVE |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{md.PVD_TIKTOKOwn, md.PVD_TIKTOKOwnCreate, md.PVD_TIKTOKOwnActivity, md.PVD_TIKTOKOwnMix}) { //判断下 |
|
|
|
|
|
pvd = md.PVD_TIKTOK |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{md.PVD_KuaishouOwn, md.PVD_KuaishouOwnCreate}) { //判断下 |
|
|
|
|
|
pvd = md.PVD_KUAISHOU |
|
|
|
|
|
} |
|
|
|
|
|
var syncTime int64 = 0 |
|
|
|
|
|
use, _ := db.SysUnionByPVDByUse(eg, dbName, pvd) |
|
|
|
|
|
if use != nil && use.SyncTime.IsZero() == false { |
|
|
|
|
|
syncTime = use.SyncTime.Unix() |
|
|
|
|
|
} |
|
|
|
|
|
// 用推广位计算出查询对应人员的等级 |
|
|
|
|
|
userInfo := parsePids(eg, dbName, pvd, pids) |
|
|
|
|
|
if pvd == md.PVD_WPHUNIONOWN { //判断下 |
|
|
|
|
|
pvd = md.PVD_VIP |
|
|
|
|
|
} |
|
|
|
|
|
pidToUser := map[string]*md.UserPid{} |
|
|
|
|
|
for _, vv := range userInfo { |
|
|
|
|
|
if pvd == md.PVD_TB { |
|
|
|
|
|
prefix := "self_" |
|
|
|
|
|
if vv.OrderType == md.OrderTypeShare { |
|
|
|
|
|
prefix = "share_" |
|
|
|
|
|
} |
|
|
|
|
|
if vv.OrderType == md.OrderTypeFree { |
|
|
|
|
|
prefix = "free_" |
|
|
|
|
|
} |
|
|
|
|
|
if vv.OrderType == 15 { |
|
|
|
|
|
prefix = "relationfree_" |
|
|
|
|
|
} |
|
|
|
|
|
if vv.OrderType == 20 { |
|
|
|
|
|
prefix = "fourfree_" |
|
|
|
|
|
} |
|
|
|
|
|
if vv.OrderType == md.OrderTypeTljFree { |
|
|
|
|
|
prefix = "tljfree_" |
|
|
|
|
|
} |
|
|
|
|
|
if vv.OrderType == 16 { |
|
|
|
|
|
prefix = "ttljfree_" |
|
|
|
|
|
} |
|
|
|
|
|
if vv.OrderType == 10 { |
|
|
|
|
|
prefix = "cloud_" |
|
|
|
|
|
} |
|
|
|
|
|
if vv.OrderType == md.OrderTypeTljRelationFree { |
|
|
|
|
|
prefix = "tljrelationfree_" |
|
|
|
|
|
} |
|
|
|
|
|
if vv.OrderType == md.OrderTypeActSelf { |
|
|
|
|
|
prefix = "actself_" |
|
|
|
|
|
} |
|
|
|
|
|
if vv.OrderType == md.OrderTypeWechatActShare { |
|
|
|
|
|
prefix = "wechatactshare_" |
|
|
|
|
|
} |
|
|
|
|
|
if vv.OrderType == md.OrderTypeWechatActSelf { |
|
|
|
|
|
prefix = "wechatactself_" |
|
|
|
|
|
} |
|
|
|
|
|
if vv.OrderType == md.OrderTypeWechatActSelfNew { |
|
|
|
|
|
prefix = "wechatactselfnew_" |
|
|
|
|
|
} |
|
|
|
|
|
pidToUser[prefix+vv.Pid] = vv |
|
|
|
|
|
} else { |
|
|
|
|
|
if len(vv.Pids) > 0 { |
|
|
|
|
|
for _, v1 := range vv.Pids { |
|
|
|
|
|
pidToUser[v1] = vv |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
pidToUser[vv.Pid] = vv |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
now := int(time.Now().Unix()) |
|
|
|
|
|
existOrds, _ := db.DbsOrderFindByIdsNew(eg, pvd, allOrdIds) |
|
|
|
|
|
fmt.Println(existOrds) |
|
|
|
|
|
|
|
|
|
|
|
// 更新订单 |
|
|
|
|
|
if existOrds != nil { |
|
|
|
|
|
var commissionReqList = make([]md.CommissionFirstParam, 0) |
|
|
|
|
|
var tikTokOrdMap = make(map[string]model.OrdList, 0) |
|
|
|
|
|
var returnMoneyReqList = make([]map[string]string, 0) |
|
|
|
|
|
|
|
|
|
|
|
for _, v := range *existOrds { |
|
|
|
|
|
if v.State == 4 { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
v.BenefitAll = utils.FloatFormat(v.BenefitAll, 3) |
|
|
|
|
|
allStationOrdIds = append(allStationOrdIds, v.OrdId) |
|
|
|
|
|
if v.ConfirmAt == 0 { |
|
|
|
|
|
if int(ords[v.PvdOid].ConfirmAt) > 0 { |
|
|
|
|
|
v.ConfirmAt = int(ords[v.PvdOid].ConfirmAt) |
|
|
|
|
|
_ = db.DbsOrderUpdate(eg, v.OrdId, &v) |
|
|
|
|
|
} else if v.PvdSettleAt > 0 { |
|
|
|
|
|
v.ConfirmAt = v.PvdSettleAt |
|
|
|
|
|
_ = db.DbsOrderUpdate(eg, v.OrdId, &v) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if int(ords[v.PvdOid].ConfirmAt) > 0 && v.ConfirmAt != int(ords[v.PvdOid].ConfirmAt) { |
|
|
|
|
|
v.ConfirmAt = int(ords[v.PvdOid].ConfirmAt) |
|
|
|
|
|
_ = db.DbsOrderUpdate(eg, v.OrdId, &v) |
|
|
|
|
|
} |
|
|
|
|
|
if v.OrderCompare == 0 && ords[v.PvdOid].IsCompare == 1 { |
|
|
|
|
|
v.OrderCompare = ords[v.PvdOid].IsCompare |
|
|
|
|
|
_ = db.DbsOrderUpdate(eg, v.OrdId, &v) |
|
|
|
|
|
} |
|
|
|
|
|
if v.CheckSuccessAt == 0 && int(ords[v.PvdOid].CheckSuccessAt) > 0 { |
|
|
|
|
|
v.CheckSuccessAt = int(ords[v.PvdOid].CheckSuccessAt) |
|
|
|
|
|
_ = db.DbsOrderUpdate(eg, v.OrdId, &v) |
|
|
|
|
|
} |
|
|
|
|
|
//更新下父级订单号 |
|
|
|
|
|
if v.ParentOrdId == 0 && v.Pvd == md.PVD_TB && ords[v.PvdOid].ParentOrdId != 0 { |
|
|
|
|
|
v.ParentOrdId = ords[v.PvdOid].ParentOrdId |
|
|
|
|
|
_ = db.DbsOrderUpdate(eg, v.OrdId, &v) |
|
|
|
|
|
} |
|
|
|
|
|
//拼多多的有些读错价格了 |
|
|
|
|
|
if v.PaidPrice != ords[v.PvdOid].PaidPrice && v.Pvd == md.PVD_PDD { |
|
|
|
|
|
v.PaidPrice = ords[v.PvdOid].PaidPrice |
|
|
|
|
|
fmt.Println("拼多多改价格") |
|
|
|
|
|
_ = db.DbsOrderUpdate(eg, v.OrdId, &v) |
|
|
|
|
|
} |
|
|
|
|
|
if ords[v.PvdOid].State == 4 { |
|
|
|
|
|
// 加锁 防止并发退款 |
|
|
|
|
|
mutexKey := fmt.Sprintf("%s:all_order_refund:%d:pvd:%s", dbName, v.OrdId, v.Pvd) |
|
|
|
|
|
available, err := cache.Do("SET", mutexKey, 1, "EX", 5, "NX") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
if available != "OK" { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
if v.SettleAt > 0 || v.State == 5 { |
|
|
|
|
|
RefundDoing(eg, returnMoneyType, &v, "", dbName) |
|
|
|
|
|
continue |
|
|
|
|
|
} else { |
|
|
|
|
|
NotSettleDeduct(eg, &v, dbName) |
|
|
|
|
|
} |
|
|
|
|
|
if v.State != 4 && v.FourPriceType > 0 { |
|
|
|
|
|
m, _ := db.FourFreeProductByID(eg, v.ItemId, v.NumItemId, v.Pvd) |
|
|
|
|
|
if m != nil { |
|
|
|
|
|
var tmp model.FourNewcomersFreeStock |
|
|
|
|
|
eg.Where("lid=? and uid=? and is_buy=1 and is_back=0", m.Id, v.Uid).Get(&tmp) |
|
|
|
|
|
if tmp.Id > 0 { |
|
|
|
|
|
tmp.IsBuy = 0 |
|
|
|
|
|
eg.Where("id=?", tmp.Id).Cols("is_buy").Update(&tmp) |
|
|
|
|
|
m.Stock++ |
|
|
|
|
|
m.Sale-- |
|
|
|
|
|
if m.Sale < 0 { |
|
|
|
|
|
m.Sale = 0 |
|
|
|
|
|
} |
|
|
|
|
|
eg.Where("id=?", m.Id).Cols("sale,stock").Update(m) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
if ords[v.PvdOid].State == 3 && utils.InArr(utils.IntToStr(v.State), []string{"3", "4", "5"}) == false && v.PvdSettleAt > 0 { |
|
|
|
|
|
v.State = 3 |
|
|
|
|
|
if v.IsTikTokTeamOrder == 1 { |
|
|
|
|
|
isRe := 0 |
|
|
|
|
|
TikTokTeamCommission := utils.StrToFloat64(v.TikTokTeamRealCommission) |
|
|
|
|
|
if TikTokTeamCommission != utils.StrToFloat64(ords[v.PvdOid].TikTokTeamRealCommission) && TikTokTeamCommission > 0 { |
|
|
|
|
|
isRe = 1 |
|
|
|
|
|
v.TikTokTeamRealCommission = ords[v.PvdOid].TikTokTeamRealCommission |
|
|
|
|
|
} |
|
|
|
|
|
if utils.StrToFloat64(ords[v.PvdOid].TikTokTeamCommission) != utils.StrToFloat64(v.TikTokTeamCommission) { |
|
|
|
|
|
if TikTokTeamCommission == 0 { |
|
|
|
|
|
isRe = 1 |
|
|
|
|
|
TikTokTeamCommission = utils.StrToFloat64(ords[v.PvdOid].TikTokTeamCommission) |
|
|
|
|
|
} |
|
|
|
|
|
v.TikTokTeamCommission = ords[v.PvdOid].TikTokTeamCommission |
|
|
|
|
|
} |
|
|
|
|
|
if isRe == 1 { |
|
|
|
|
|
isShare := 0 |
|
|
|
|
|
if v.OrderType == md.OrderTypeShare || v.OrderType == md.OrderTypeWechatActShare { |
|
|
|
|
|
isShare = 1 |
|
|
|
|
|
} |
|
|
|
|
|
req := md.CommissionFirstParam{ |
|
|
|
|
|
CommissionParam: md.CommissionParam{ |
|
|
|
|
|
Commission: utils.Float64ToStr(v.BenefitAll), |
|
|
|
|
|
PaidPrice: utils.Float64ToStr(v.PaidPrice), |
|
|
|
|
|
OldPrice: utils.Float64ToStr(v.PaidPrice), |
|
|
|
|
|
TikTokTeamCommission: utils.Float64ToStr(TikTokTeamCommission), |
|
|
|
|
|
IsTikTokTeamOrder: utils.IntToStr(v.IsTikTokTeamOrder), |
|
|
|
|
|
}, |
|
|
|
|
|
Uid: utils.IntToStr(v.Uid), |
|
|
|
|
|
IsShare: isShare, |
|
|
|
|
|
Provider: v.Pvd, |
|
|
|
|
|
IsAllLevelReturn: 0, |
|
|
|
|
|
Oid: v.PvdOid, |
|
|
|
|
|
} |
|
|
|
|
|
tikTokOrdMap[v.PvdOid] = v |
|
|
|
|
|
commissionReqList = append(commissionReqList, req) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
_ = db.DbsOrderUpdate(eg, v.OrdId, &v) |
|
|
|
|
|
} |
|
|
|
|
|
if v.State == 4 && ords[v.PvdOid].Reason != "" && v.Reason == "" { |
|
|
|
|
|
v.Reason = ords[v.PvdOid].Reason |
|
|
|
|
|
_ = db.DbsOrderUpdate(eg, v.OrdId, &v) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
//处理下没有分佣明细的订单 |
|
|
|
|
|
existRelateOrds, _ := db.DbsOrderRelateFindByIds(eg, pvd, allStationOrdIds) |
|
|
|
|
|
if existRelateOrds != nil { |
|
|
|
|
|
for _, v := range *existRelateOrds { |
|
|
|
|
|
stationOrdIds = append(stationOrdIds, v.Oid) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
for _, v := range *existOrds { |
|
|
|
|
|
v.BenefitAll = utils.FloatFormat(v.BenefitAll, 3) |
|
|
|
|
|
result := in(v.OrdId, stationOrdIds) |
|
|
|
|
|
if result == false { |
|
|
|
|
|
//如果没有用户这里要做处理 仅针对淘宝 或美团联盟没有佣金的情况 |
|
|
|
|
|
commCheckUser(eg, v, ords, pvd, pidToUser, opts, secondOpts, dbName, true, returnMoneyType) |
|
|
|
|
|
} |
|
|
|
|
|
// 去除已存在订单 |
|
|
|
|
|
delete(ords, v.PvdOid) |
|
|
|
|
|
} |
|
|
|
|
|
if len(commissionReqList) > 0 { //处理抖音团长结算的订单 |
|
|
|
|
|
commissionListArr, _ := GetMoreRebateResult(eg, dbName, returnMoneyType, commissionReqList, returnMoneyReqList) |
|
|
|
|
|
for k, v := range commissionListArr { |
|
|
|
|
|
ord, ok := tikTokOrdMap[k] |
|
|
|
|
|
if ok && v.LvUser != nil && v.LvUser.TikTokOwnSubsidyFeeList != nil { |
|
|
|
|
|
db.TikTokTeamOrderRelateDeleteByOid(eg, ord.OrdId, pvd) |
|
|
|
|
|
var teamData []model.TikTokTeamOrderRelate |
|
|
|
|
|
TikTokTeamCommission := ord.TikTokTeamCommission |
|
|
|
|
|
if utils.StrToFloat64(ord.TikTokTeamRealCommission) > 0 { |
|
|
|
|
|
TikTokTeamCommission = ord.TikTokTeamRealCommission |
|
|
|
|
|
} |
|
|
|
|
|
for k1, v1 := range v.LvUser.TikTokOwnSubsidyFeeList { |
|
|
|
|
|
tmp := model.TikTokTeamOrderRelate{ |
|
|
|
|
|
CoinId: utils.StrToInt(k1), |
|
|
|
|
|
Uid: ord.Uid, |
|
|
|
|
|
Amount: utils.Float64ToStrByPrec(v1, 8), |
|
|
|
|
|
Oid: utils.Int64ToStr(ord.OrdId), |
|
|
|
|
|
Time: time.Now(), |
|
|
|
|
|
Commission: TikTokTeamCommission, |
|
|
|
|
|
Pvd: pvd, |
|
|
|
|
|
} |
|
|
|
|
|
teamData = append(teamData, tmp) |
|
|
|
|
|
} |
|
|
|
|
|
db.DbInsertBatch(eg, &teamData) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//判断饿了么的 |
|
|
|
|
|
if pvd == md.PVD_TB { |
|
|
|
|
|
eleExistOrds, _ := db.DbsOrderFindByIds(eg, "ele", allOrdIds) |
|
|
|
|
|
// 更新订单 |
|
|
|
|
|
if eleExistOrds != nil { |
|
|
|
|
|
for _, v := range *eleExistOrds { |
|
|
|
|
|
if v.State != ords[v.PvdOid].State { |
|
|
|
|
|
v.Reason = ords[v.PvdOid].Reason |
|
|
|
|
|
v.State = ords[v.PvdOid].State |
|
|
|
|
|
v.UpdateAt = now |
|
|
|
|
|
if v.State == md.OrderStateSucc { |
|
|
|
|
|
v.ConfirmAt = v.UpdateAt |
|
|
|
|
|
} |
|
|
|
|
|
// 供应商结算时间 |
|
|
|
|
|
if v.State == md.OrderStatePvdSettle { |
|
|
|
|
|
v.PvdSettleAt = v.UpdateAt |
|
|
|
|
|
if ords[v.PvdOid].EndTime > 0 { |
|
|
|
|
|
v.PvdSettleAt = int(ords[v.PvdOid].EndTime) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
_ = db.DbsOrderUpdate(eg, v.OrdId, &v) |
|
|
|
|
|
} |
|
|
|
|
|
//如果没有用户这里要做处理 仅针对淘宝 |
|
|
|
|
|
commCheckUser(eg, v, ords, pvd, pidToUser, opts, secondOpts, dbName, false, returnMoneyType) |
|
|
|
|
|
// 去除已存在订单 |
|
|
|
|
|
delete(ords, v.PvdOid) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if len(ords) == 0 { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
var commissionReqList = make([]md.CommissionFirstParam, 0) |
|
|
|
|
|
var returnMoneyReqList = make([]map[string]string, 0) |
|
|
|
|
|
var secondCommissionReqList = make([]md.CommissionFirstParam, 0) |
|
|
|
|
|
|
|
|
|
|
|
for k, v := range ords { |
|
|
|
|
|
if v.StartTime < syncTime && syncTime > 0 { //根据后台的时间配置来 |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
var oneOrd = v |
|
|
|
|
|
var user *md.UserPid |
|
|
|
|
|
if utils.InArr(pvd, []string{md.PVD_TB, "ele", md.PVD_TB12, md.PVD_TB13, md.PVD_TB14, md.PVD_TB3, md.PVD_TBBYPAY, md.PVD_TBBYCREATETIME, md.PVD_TBBYSETTLE}) { |
|
|
|
|
|
//如果是淘宝要处理下类型拿用户 |
|
|
|
|
|
for k1 := range pidToUser { |
|
|
|
|
|
pidTmp := strings.Split(v.Pid, "_") |
|
|
|
|
|
if len(pidTmp) == 2 { |
|
|
|
|
|
if strings.Contains(k1, pidTmp[1]) && pidTmp[1] != "" { |
|
|
|
|
|
v.Pid = k1 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if v.Pid != "" { |
|
|
|
|
|
if pidToUser[v.Pid] != nil { |
|
|
|
|
|
user = pidToUser[v.Pid] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if v.Pid == "" && (v.Pvd == md.PVD_TB || v.Pvd == "ele") { |
|
|
|
|
|
v.Pid = "self" |
|
|
|
|
|
} |
|
|
|
|
|
newPvd := pvd |
|
|
|
|
|
//判断是饿了么的 |
|
|
|
|
|
if v.Pvd == "ele" { |
|
|
|
|
|
newPvd = "ele" |
|
|
|
|
|
} |
|
|
|
|
|
//判断是否美团 |
|
|
|
|
|
if strings.Contains(pvd, "meituan_") { |
|
|
|
|
|
newPvd = "meituan" |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == "hw_movie" { |
|
|
|
|
|
newPvd = "cinema" |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_PDDBYCREATETIME || pvd == md.PVD_PDDBYAGOTIME || pvd == md.PVD_PDDBYSTATUS || pvd == md.PVD_PDDBYSTATUSSUCCESS || pvd == md.PVD_PDDBYSTATUSFAIL { //判断下拼多多 |
|
|
|
|
|
newPvd = md.PVD_PDD |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_JDUNIONOWN || pvd == md.PVD_JDUNIONOWNUPDATE || pvd == md.PVD_JDBYCREATETIME || pvd == md.PVD_JDBYSUCCESS || pvd == md.PVD_JDFAILBYCREATETIME || pvd == md.PVD_JDBYSTATUS { //判断下京东 |
|
|
|
|
|
newPvd = md.PVD_JD |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{"csjp_create", "own_csjp", "own_csjp_activity"}) { |
|
|
|
|
|
newPvd = "csjp" |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{"own_csjp_live"}) { |
|
|
|
|
|
newPvd = "csjp_live" |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{md.PVD_TB12, md.PVD_TB13, md.PVD_TB14, md.PVD_TB3, md.PVD_TBBYPAY, md.PVD_TBBYCREATETIME, md.PVD_TBBYSETTLE}) { |
|
|
|
|
|
newPvd = md.PVD_TB |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_TO_KFC { //判断下 |
|
|
|
|
|
newPvd = md.PVD_KFC |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{md.PVD_TIKTOKOwn, md.PVD_TIKTOKOwnCreate, md.PVD_TIKTOKOwnActivity, md.PVD_TIKTOKOwnMix}) { //判断下 |
|
|
|
|
|
newPvd = md.PVD_TIKTOK |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{md.PVD_KuaishouOwn, md.PVD_KuaishouOwnCreate}) { //判断下 |
|
|
|
|
|
newPvd = md.PVD_KUAISHOU |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_TIKTOKOWNLIVE { //判断下 |
|
|
|
|
|
newPvd = md.PVD_TIKTOKLIVE |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_DIDI_ENERGY { //判断下 |
|
|
|
|
|
newPvd = "oil" |
|
|
|
|
|
} |
|
|
|
|
|
if v.Pvd == md.PVD_JDOwn { |
|
|
|
|
|
newPvd = md.PVD_JDOwn |
|
|
|
|
|
pvd = md.PVD_JD |
|
|
|
|
|
} |
|
|
|
|
|
optPvd := newPvd |
|
|
|
|
|
if newPvd == "oil" { |
|
|
|
|
|
optPvd = "oilstation" |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{md.PVD_KuaishouOwn, md.PVD_KuaishouOwnCreate}) { |
|
|
|
|
|
if v.Pvd == "Live" { |
|
|
|
|
|
optPvd = md.PVD_KUAISHOULIVE |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if !strings.Contains(v.Pid, "fourFree") && !strings.Contains(v.Pid, "moreFree") && !strings.Contains(v.Pid, "shareSeFree") && !strings.Contains(v.Pid, "seFree") && !strings.Contains(v.Pid, "cloud") && !strings.Contains(v.Pid, "share") && !strings.Contains(v.Pid, "self") && !strings.Contains(v.Pid, "free") && !strings.Contains(v.Pid, "actself") && !strings.Contains(v.Pid, "wechatactself") && !strings.Contains(v.Pid, "wechatactselfnew") && !strings.Contains(v.Pid, "wechatactshare") { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
var oid int64 |
|
|
|
|
|
if user != nil { //用户不为空才判断 |
|
|
|
|
|
oid = utils.StrToInt64(utils.OrderUUID(user.Uid)) |
|
|
|
|
|
} |
|
|
|
|
|
if v.OrderType == 15 { |
|
|
|
|
|
v.OrderType = 2 |
|
|
|
|
|
} |
|
|
|
|
|
if v.OrderType == 16 { |
|
|
|
|
|
v.OrderType = 6 |
|
|
|
|
|
} |
|
|
|
|
|
oneOrd.Oid = oid |
|
|
|
|
|
ords[k] = oneOrd |
|
|
|
|
|
ownbuyReturnType := 0 //自购返利 0返利 1不返利 |
|
|
|
|
|
if v.OrderType == 20 { //多方案 |
|
|
|
|
|
if user == nil || user.Uid == 0 { //判断免单的如果没有用户不跟这个订单 |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
freeOrder := orderFourFreeCheck(eg, &v, oid, user.Uid, 0) |
|
|
|
|
|
if freeOrder != nil { |
|
|
|
|
|
optPvd = "fourFree_" + utils.IntToStr(freeOrder.PriceType) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var uid = 0 |
|
|
|
|
|
|
|
|
|
|
|
if user != nil { |
|
|
|
|
|
user.OwnbuyReturnType = ownbuyReturnType //是否有自购奖励 |
|
|
|
|
|
uid = user.Uid |
|
|
|
|
|
isShare := 0 |
|
|
|
|
|
if v.OrderType == md.OrderTypeShare || v.OrderType == md.OrderTypeWechatActShare { |
|
|
|
|
|
isShare = 1 |
|
|
|
|
|
} |
|
|
|
|
|
//调用公共的分佣 |
|
|
|
|
|
pvdOid := v.PvdOid |
|
|
|
|
|
//if v.ParentOrdId > 0 { |
|
|
|
|
|
// pvdOid = utils.Int64ToStr(v.ParentOrdId) |
|
|
|
|
|
//} |
|
|
|
|
|
TikTokTeamCommission := v.TikTokTeamCommission |
|
|
|
|
|
if utils.StrToFloat64(v.TikTokTeamRealCommission) > 0 { |
|
|
|
|
|
TikTokTeamCommission = v.TikTokTeamRealCommission |
|
|
|
|
|
} |
|
|
|
|
|
req := md.CommissionFirstParam{ |
|
|
|
|
|
CommissionParam: md.CommissionParam{ |
|
|
|
|
|
Commission: utils.Float64ToStr(v.Commission), |
|
|
|
|
|
PaidPrice: utils.Float64ToStr(v.PaidPrice), |
|
|
|
|
|
OldPrice: utils.Float64ToStr(v.PaidPrice), |
|
|
|
|
|
TikTokTeamCommission: TikTokTeamCommission, |
|
|
|
|
|
IsTikTokTeamOrder: utils.IntToStr(v.IsTikTokTeamOrder), |
|
|
|
|
|
}, |
|
|
|
|
|
Uid: utils.IntToStr(uid), |
|
|
|
|
|
IsShare: isShare, |
|
|
|
|
|
Provider: optPvd, |
|
|
|
|
|
IsAllLevelReturn: 1, |
|
|
|
|
|
OwnbuyReturnType: ownbuyReturnType, |
|
|
|
|
|
Oid: pvdOid, |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(optPvd, []string{md.PVD_TB, md.PVD_TM, md.PVD_PDD, md.PVD_SN, md.PVD_KL, md.PVD_JD, md.PVD_JDOwn, md.PVD_VIP}) == false { |
|
|
|
|
|
req.CommissionParam.GoodsPrice = utils.Float64ToStr(v.PaidPrice) |
|
|
|
|
|
} |
|
|
|
|
|
commissionReqList = append(commissionReqList, req) |
|
|
|
|
|
if secondOpts[req.Provider] != nil && opts[req.Provider].PlanCommissionId > 0 { |
|
|
|
|
|
req.ServiceUid = "" |
|
|
|
|
|
NewServiceAwardDividendRelationDb := implement.NewServiceAwardDividendRelationDb(eg) |
|
|
|
|
|
relation, _ := NewServiceAwardDividendRelationDb.GetServiceAwardDividendRelationByUid(uid) |
|
|
|
|
|
if relation != nil { |
|
|
|
|
|
req.ServiceUid = utils.IntToStr(relation.BindUid) |
|
|
|
|
|
} |
|
|
|
|
|
if utils.StrToInt(req.ServiceUid) > 0 { |
|
|
|
|
|
secondCommissionReqList = append(secondCommissionReqList, req) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
returnMoneyReq := map[string]string{ |
|
|
|
|
|
"commission": utils.Float64ToStr(v.Commission), |
|
|
|
|
|
"goods_price": utils.Float64ToStr(v.PaidPrice), |
|
|
|
|
|
"uid": utils.IntToStr(uid), |
|
|
|
|
|
"provider": optPvd, |
|
|
|
|
|
"is_share": utils.IntToStr(isShare), |
|
|
|
|
|
"is_return_all": "1", |
|
|
|
|
|
"key_value": pvdOid, |
|
|
|
|
|
} |
|
|
|
|
|
returnMoneyReqList = append(returnMoneyReqList, returnMoneyReq) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
commissionListArr, returnListArr := GetMoreRebateResult(eg, dbName, returnMoneyType, commissionReqList, returnMoneyReqList) |
|
|
|
|
|
secondCommissionListArr, _ := GetMoreRebateResultService(eg, dbName, returnMoneyType, secondCommissionReqList, returnMoneyReqList) |
|
|
|
|
|
|
|
|
|
|
|
// 如果不存在的订单, 则进行计算更新 |
|
|
|
|
|
for _, v := range ords { |
|
|
|
|
|
utils.FilePutContents("order", v.PvdOid) |
|
|
|
|
|
if v.StartTime < syncTime && syncTime > 0 { //根据后台的时间配置来 |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
var user *md.UserPid |
|
|
|
|
|
if pvd == md.PVD_TB12 || pvd == md.PVD_TB13 || pvd == md.PVD_TB14 || pvd == md.PVD_TB3 || pvd == md.PVD_TB || pvd == "ele" || pvd == md.PVD_TBBYCREATETIME || pvd == md.PVD_TBBYPAY || pvd == md.PVD_TBBYSETTLE { |
|
|
|
|
|
//如果是淘宝要处理下类型拿用户 |
|
|
|
|
|
for k1 := range pidToUser { |
|
|
|
|
|
pidTmp := strings.Split(v.Pid, "_") |
|
|
|
|
|
if len(pidTmp) == 2 { |
|
|
|
|
|
if strings.Contains(k1, pidTmp[1]) && pidTmp[1] != "" { |
|
|
|
|
|
v.Pid = k1 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if v.Pid != "" { |
|
|
|
|
|
if pidToUser[v.Pid] != nil { |
|
|
|
|
|
user = pidToUser[v.Pid] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
fmt.Println("================", v.PvdOid, v.Pid, utils.SerializeStr(user)) |
|
|
|
|
|
|
|
|
|
|
|
if v.Pid == "" && (v.Pvd == md.PVD_TB || v.Pvd == "ele") { |
|
|
|
|
|
v.Pid = "self" |
|
|
|
|
|
} |
|
|
|
|
|
v.Pid = strings.ReplaceAll(v.Pid, "relationfree_", "free_") |
|
|
|
|
|
|
|
|
|
|
|
allCommission := v.Commission |
|
|
|
|
|
newPvd := pvd |
|
|
|
|
|
//判断是饿了么的 |
|
|
|
|
|
if v.Pvd == "ele" { |
|
|
|
|
|
newPvd = "ele" |
|
|
|
|
|
} |
|
|
|
|
|
//判断是否美团 |
|
|
|
|
|
if strings.Contains(pvd, "meituan_") { |
|
|
|
|
|
newPvd = "meituan" |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == "hw_movie" { |
|
|
|
|
|
newPvd = "cinema" |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_PDDBYCREATETIME || pvd == md.PVD_PDDBYAGOTIME || pvd == md.PVD_PDDBYSTATUS || pvd == md.PVD_PDDBYSTATUSSUCCESS || pvd == md.PVD_PDDBYSTATUSFAIL { //判断下拼多多 |
|
|
|
|
|
newPvd = md.PVD_PDD |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{"csjp_create", "own_csjp", "own_csjp_activity"}) { |
|
|
|
|
|
newPvd = "csjp" |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{"own_csjp_live"}) { |
|
|
|
|
|
newPvd = "csjp_live" |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_JDUNIONOWN || pvd == md.PVD_JDUNIONOWNUPDATE || pvd == md.PVD_JDBYCREATETIME || pvd == md.PVD_JDBYSUCCESS || pvd == md.PVD_JDFAILBYCREATETIME || pvd == md.PVD_JDBYSTATUS { //判断下京东 |
|
|
|
|
|
newPvd = md.PVD_JD |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{md.PVD_TB12, md.PVD_TB13, md.PVD_TB14, md.PVD_TB3, md.PVD_TBBYPAY, md.PVD_TBBYCREATETIME, md.PVD_TBBYSETTLE}) { |
|
|
|
|
|
newPvd = md.PVD_TB |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_TO_KFC { //判断下 |
|
|
|
|
|
newPvd = md.PVD_KFC |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(pvd, []string{md.PVD_TIKTOKOwn, md.PVD_TIKTOKOwnCreate, md.PVD_TIKTOKOwnActivity, md.PVD_TIKTOKOwnMix}) { //判断下 |
|
|
|
|
|
newPvd = md.PVD_TIKTOK |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_TIKTOKOWNLIVE { //判断下 |
|
|
|
|
|
newPvd = md.PVD_TIKTOKLIVE |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == md.PVD_DIDI_ENERGY { //判断下 |
|
|
|
|
|
newPvd = "oil" |
|
|
|
|
|
} |
|
|
|
|
|
if v.Pvd == md.PVD_JDOwn { |
|
|
|
|
|
newPvd = md.PVD_JDOwn |
|
|
|
|
|
pvd = md.PVD_JD |
|
|
|
|
|
} |
|
|
|
|
|
optPvd := newPvd |
|
|
|
|
|
opt := opts[newPvd] |
|
|
|
|
|
if v.Pvd == md.PVD_JDOwn && (opt == nil || (opt != nil && opt.PlanCommissionId == 0)) { |
|
|
|
|
|
opt = opts[md.PVD_JD] |
|
|
|
|
|
} |
|
|
|
|
|
//判断是否加油 |
|
|
|
|
|
if newPvd == "oil" { |
|
|
|
|
|
var ok = true |
|
|
|
|
|
optPvd = "oilstation" |
|
|
|
|
|
opt, ok = opts["oilstation"] |
|
|
|
|
|
if ok == false { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
} else if opt == nil { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
if (pvd == "tikTok" || pvd == "csjp") && v.IsTikTokTeamOrder == 1 && opts["tikTokTeam"] != nil && opts["tikTokTeam"].PlanCommissionId > 0 { |
|
|
|
|
|
opt = opts["tikTokTeam"] |
|
|
|
|
|
} |
|
|
|
|
|
if pvd == "kuaishou" && v.IsTikTokTeamOrder == 1 && opts["kuaishouTeam"] != nil && opts["kuaishouTeam"].PlanCommissionId > 0 { |
|
|
|
|
|
opt = opts["kuaishouTeam"] |
|
|
|
|
|
} |
|
|
|
|
|
priceType := 0 |
|
|
|
|
|
secondPriceType := 0 |
|
|
|
|
|
fourPriceType := 0 |
|
|
|
|
|
if !strings.Contains(v.Pid, "fourFree") && !strings.Contains(v.Pid, "moreFree") && !strings.Contains(v.Pid, "shareSeFree") && !strings.Contains(v.Pid, "seFree") && !strings.Contains(v.Pid, "cloud") && !strings.Contains(v.Pid, "share") && !strings.Contains(v.Pid, "self") && !strings.Contains(v.Pid, "free") && !strings.Contains(v.Pid, "actself") && !strings.Contains(v.Pid, "wechatactself") && !strings.Contains(v.Pid, "wechatactselfnew") && !strings.Contains(v.Pid, "wechatactshare") { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
var oid = v.Oid |
|
|
|
|
|
if user != nil && oid == 0 { //用户不为空才判断 |
|
|
|
|
|
oid = utils.StrToInt64(utils.OrderUUID(user.Uid)) |
|
|
|
|
|
} |
|
|
|
|
|
ownbuyReturnType := 0 //自购返利 0返利 1不返利 |
|
|
|
|
|
//免单逻辑处理 |
|
|
|
|
|
if v.OrderType == 15 { |
|
|
|
|
|
v.OrderType = md.OrderTypeFree |
|
|
|
|
|
} |
|
|
|
|
|
freeOrderType := v.OrderType |
|
|
|
|
|
if v.OrderType == 20 { |
|
|
|
|
|
if user == nil || user.Uid == 0 { //判断免单的如果没有用户不跟这个订单 |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
//TODO |
|
|
|
|
|
freeOrder := orderFourFreeCheck(eg, &v, oid, user.Uid, 1) |
|
|
|
|
|
if freeOrder != nil { |
|
|
|
|
|
fourPriceType = freeOrder.PriceType |
|
|
|
|
|
// 切换免单活动的分佣方案, 如1元购等 |
|
|
|
|
|
optPvd = "fourFree_" + utils.IntToStr(freeOrder.PriceType) |
|
|
|
|
|
opt = opts[optPvd] |
|
|
|
|
|
} else { |
|
|
|
|
|
v.State = 4 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
var lvUser *comm_plan.LvUser |
|
|
|
|
|
var pvdFee float64 |
|
|
|
|
|
var sysFee float64 |
|
|
|
|
|
var subsidyFee float64 |
|
|
|
|
|
var subsidyRate float64 |
|
|
|
|
|
var uid = 0 |
|
|
|
|
|
var profit float64 = 0 |
|
|
|
|
|
var returnProfit float64 = 0 |
|
|
|
|
|
var selfRate float64 = 0 |
|
|
|
|
|
var returnMoneyOne map[string]interface{} |
|
|
|
|
|
pvdOid := v.PvdOid |
|
|
|
|
|
if user != nil { |
|
|
|
|
|
user.OwnbuyReturnType = ownbuyReturnType //是否有自购奖励 |
|
|
|
|
|
uid = user.Uid |
|
|
|
|
|
userLv := user.Lv |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println(optPvd) |
|
|
|
|
|
if returnMoneyType == "0" { |
|
|
|
|
|
commissionList := commissionListArr[pvdOid] |
|
|
|
|
|
if commissionList != nil { |
|
|
|
|
|
pvdFee = commissionList.PvdFee |
|
|
|
|
|
sysFee = commissionList.SysFee |
|
|
|
|
|
subsidyFee = commissionList.SubsidyFee |
|
|
|
|
|
lvUser = commissionList.LvUser |
|
|
|
|
|
profit = commissionList.Profit |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
returnMoneyList := returnListArr[pvdOid] |
|
|
|
|
|
var ok = true |
|
|
|
|
|
returnMoneyOne, ok = returnMoneyList.(map[string]interface{}) |
|
|
|
|
|
if returnMoneyOne != nil && ok { |
|
|
|
|
|
returnProfit = utils.AnyToFloat64(returnMoneyOne["self_commission"]) |
|
|
|
|
|
if v.OrderType == 1 { |
|
|
|
|
|
returnProfit = utils.AnyToFloat64(returnMoneyOne["share_commission"]) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
fmt.Println(returnProfit) |
|
|
|
|
|
|
|
|
|
|
|
//判断下这个等级有么有设置 |
|
|
|
|
|
if opt.UserRate != nil { |
|
|
|
|
|
for k, item := range opt.UserRate { |
|
|
|
|
|
if k == 0 { |
|
|
|
|
|
selfRate = item.SelfRate |
|
|
|
|
|
subsidyRate = item.SubsidyShareRate |
|
|
|
|
|
if v.OrderType == 0 { |
|
|
|
|
|
subsidyRate = item.SubsidySelfRate |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if k == userLv { |
|
|
|
|
|
selfRate = item.SelfRate |
|
|
|
|
|
selfRate = item.SelfRate |
|
|
|
|
|
subsidyRate = item.SubsidyShareRate |
|
|
|
|
|
if v.OrderType == 0 { |
|
|
|
|
|
subsidyRate = item.SubsidySelfRate |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if v.OrderType == 20 || v.OrderType == 15 || v.OrderType == 11 || v.OrderType == md.OrderTypeFree || v.OrderType == md.OrderTypeWechatActSelf || v.OrderType == md.OrderTypeWechatActSelfNew || v.OrderType == md.OrderTypeActSelf { |
|
|
|
|
|
v.OrderType = md.OrderTypeSelf |
|
|
|
|
|
} |
|
|
|
|
|
if v.OrderType == 12 { |
|
|
|
|
|
v.OrderType = md.OrderTypeShare |
|
|
|
|
|
} |
|
|
|
|
|
if v.OrderType == md.OrderTypeTljFree || v.OrderType == md.OrderTypeTljRelationFree { |
|
|
|
|
|
v.OrderType = 3 //淘礼金免单 |
|
|
|
|
|
} |
|
|
|
|
|
if v.OrderType == md.OrderTypeWechatActShare { |
|
|
|
|
|
v.OrderType = md.OrderTypeShare |
|
|
|
|
|
} |
|
|
|
|
|
//如果没有商品id的用订单好代替 |
|
|
|
|
|
if v.ItemId == "" || v.ItemId == "0" { |
|
|
|
|
|
v.ItemId = v.PvdOid |
|
|
|
|
|
} |
|
|
|
|
|
orderFormType := 0 |
|
|
|
|
|
if newPvd == md.PVD_JDOwn { |
|
|
|
|
|
newPvd = md.PVD_JD |
|
|
|
|
|
orderFormType = 1 |
|
|
|
|
|
} |
|
|
|
|
|
ServiceUid := "" |
|
|
|
|
|
NewServiceAwardDividendRelationDb := implement.NewServiceAwardDividendRelationDb(eg) |
|
|
|
|
|
relation, _ := NewServiceAwardDividendRelationDb.GetServiceAwardDividendRelationByUid(uid) |
|
|
|
|
|
if relation != nil { |
|
|
|
|
|
ServiceUid = utils.IntToStr(relation.BindUid) |
|
|
|
|
|
} |
|
|
|
|
|
// 插入新订单 |
|
|
|
|
|
newOrd := &model.OrdList{ |
|
|
|
|
|
ServiceUid: utils.StrToInt(ServiceUid), |
|
|
|
|
|
WaitSettleAt: int(v.WaitSettleAt), |
|
|
|
|
|
NumItemId: v.SkuId, |
|
|
|
|
|
TaskType: v.TaskType, |
|
|
|
|
|
OrderFormType: orderFormType, |
|
|
|
|
|
OrdId: oid, |
|
|
|
|
|
Uid: uid, |
|
|
|
|
|
PvdOid: v.PvdOid, |
|
|
|
|
|
ParentOrdId: v.ParentOrdId, |
|
|
|
|
|
Pvd: newPvd, |
|
|
|
|
|
ItemId: v.ItemId, |
|
|
|
|
|
ItemNum: v.ItemNum, |
|
|
|
|
|
ItemPrice: v.ItemPrice, |
|
|
|
|
|
PaidPrice: v.PaidPrice, |
|
|
|
|
|
OrderType: v.OrderType, |
|
|
|
|
|
PriceType: priceType, |
|
|
|
|
|
SecondPriceType: secondPriceType, |
|
|
|
|
|
FourPriceType: fourPriceType, |
|
|
|
|
|
SubsidyFee: subsidyFee, |
|
|
|
|
|
SubsidyRate: subsidyRate, |
|
|
|
|
|
UserCommission: profit, |
|
|
|
|
|
UserReturnMoney: returnProfit, |
|
|
|
|
|
UserCommissionRate: selfRate, |
|
|
|
|
|
PvdCommission: pvdFee, |
|
|
|
|
|
PvdCommissionRate: opt.PvdRate, |
|
|
|
|
|
SysCommission: sysFee, |
|
|
|
|
|
SysCommissionRate: opt.SysRate, |
|
|
|
|
|
PlanCommissionId: opt.PlanCommissionId, |
|
|
|
|
|
Reason: v.Reason, |
|
|
|
|
|
State: v.State, |
|
|
|
|
|
CreateAt: int(v.StartTime), |
|
|
|
|
|
UpdateAt: now, |
|
|
|
|
|
ConfirmAt: 0, |
|
|
|
|
|
PvdSettleAt: 0, |
|
|
|
|
|
SettleAt: 0, |
|
|
|
|
|
BenefitList: SerializeLvUser(CalcLvUserFee(lvUser)), |
|
|
|
|
|
BenefitAll: allCommission, |
|
|
|
|
|
Data: "", |
|
|
|
|
|
UpdateFrom: 0, |
|
|
|
|
|
PvdPid: v.Pid, |
|
|
|
|
|
OrderCompare: v.IsCompare, |
|
|
|
|
|
CostPrice: v.CostPrice, |
|
|
|
|
|
IsTikTokTeamOrder: v.IsTikTokTeamOrder, |
|
|
|
|
|
TikTokTeamCommission: v.TikTokTeamCommission, |
|
|
|
|
|
TikTokTeamRealCommission: v.TikTokTeamRealCommission, |
|
|
|
|
|
} |
|
|
|
|
|
if v.State == md.OrderStateSucc && v.ConfirmAt == 0 { |
|
|
|
|
|
newOrd.ConfirmAt = now |
|
|
|
|
|
} |
|
|
|
|
|
if utils.InArr(utils.IntToStr(v.State), []string{"1", "2"}) && v.ConfirmAt > 0 { |
|
|
|
|
|
newOrd.ConfirmAt = int(v.ConfirmAt) |
|
|
|
|
|
} |
|
|
|
|
|
// 供应商结算时间 |
|
|
|
|
|
if v.State == md.OrderStatePvdSettle { |
|
|
|
|
|
newOrd.PvdSettleAt = now |
|
|
|
|
|
if v.EndTime > 0 { |
|
|
|
|
|
newOrd.PvdSettleAt = int(v.EndTime) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
db.DbsOrderInsert(eg, newOrd) |
|
|
|
|
|
// 塞入订单商品对应图片 |
|
|
|
|
|
thumbnail := v.Thumbnail |
|
|
|
|
|
if len(v.Thumbnail) > 3 && v.Thumbnail[0:2] == "//" { |
|
|
|
|
|
thumbnail = "http:" + v.Thumbnail |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
db.DbsOrderItemInfoInsert(eg, &model.OrdItemInfo{ |
|
|
|
|
|
ItemId: v.ItemId, |
|
|
|
|
|
Pvd: newPvd, |
|
|
|
|
|
Thumbnail: thumbnail, |
|
|
|
|
|
ItemTitle: v.ItemTitle, |
|
|
|
|
|
ItemLink: v.ItemLink, |
|
|
|
|
|
NumItemId: v.SkuId, |
|
|
|
|
|
}) |
|
|
|
|
|
mode := "" |
|
|
|
|
|
if opt != nil { |
|
|
|
|
|
mode = opt.Mode |
|
|
|
|
|
} |
|
|
|
|
|
// TODO 塞入对应订单关系 |
|
|
|
|
|
if lvUser != nil && returnMoneyType == "0" { |
|
|
|
|
|
//if optPvd == md.PVD_FREE && freeNewType == "1" { |
|
|
|
|
|
// lvUser.AdditionalSubsidy = v.Commission |
|
|
|
|
|
//} |
|
|
|
|
|
OrderRelateInsert(eg, oid, newPvd, newOrd.CreateAt, lvUser, newOrd, dbName, false, mode, "1") |
|
|
|
|
|
} else if returnMoneyOne != nil && returnMoneyType == "1" { |
|
|
|
|
|
OrderReturnMoneyRelateInsert(eg, oid, newPvd, newOrd.CreateAt, returnMoneyOne, newOrd, dbName, false) |
|
|
|
|
|
} |
|
|
|
|
|
secondCommissionList := secondCommissionListArr[pvdOid] |
|
|
|
|
|
if secondCommissionList != nil { |
|
|
|
|
|
secondLvUser := secondCommissionList.LvUser |
|
|
|
|
|
if secondLvUser != nil && returnMoneyType == "0" { |
|
|
|
|
|
OrderRelateInsertService(eg, oid, newPvd, newOrd.CreateAt, secondLvUser, newOrd, dbName, false, mode, "1") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
AcquisitionHookFirstOrder(eg, dbName, newOrd) |
|
|
|
|
|
if uid > 0 { |
|
|
|
|
|
//商家分佣 |
|
|
|
|
|
args := map[string]string{ |
|
|
|
|
|
"commission": utils.Float64ToStr(utils.FloatFormat(allCommission, 6)), // 总佣金 |
|
|
|
|
|
"bili": utils.Float64ToStrByPrec(opt.MerchantRate, 4), // 抽成 除以100之后的 |
|
|
|
|
|
"uid": utils.IntToStr(uid), // 用户id |
|
|
|
|
|
"oid": utils.Int64ToStr(oid), // 订单号 |
|
|
|
|
|
"pvd": newPvd, // 渠道 |
|
|
|
|
|
} |
|
|
|
|
|
o2o.AddStoreCommission(eg, args) |
|
|
|
|
|
//写入区域代理订单 |
|
|
|
|
|
var req = &md.InsertRegionalAgentOrdBelongData{ |
|
|
|
|
|
Uid: uid, |
|
|
|
|
|
Pvd: md.PVD_GUIDE, |
|
|
|
|
|
CommPvd: md.PVD_COMMON, |
|
|
|
|
|
Commission: utils.Float64ToStr(utils.FloatFormat(allCommission, 6)), |
|
|
|
|
|
OrderId: oid, |
|
|
|
|
|
RegionRate: opt.RegionRate, |
|
|
|
|
|
GlobalRate: opt.GlobalRate, |
|
|
|
|
|
RegionSubRate: opt.RegionSubRate, |
|
|
|
|
|
|
|
|
|
|
|
Status: "0", |
|
|
|
|
|
} |
|
|
|
|
|
//if opt.Mode == "lv_ds_check" && lvUser != nil { |
|
|
|
|
|
// req.Commission = utils.Float64ToStrByPrec(lvUser.MinProfit, 8) |
|
|
|
|
|
//} |
|
|
|
|
|
go SaveOrderByCommApi(eg, dbName, req) |
|
|
|
|
|
commCheckCoupon(eg, uid, v.ItemId, 0, 1, newOrd.Pvd, utils.Int64ToStr(v.Oid)) //导购的判断 |
|
|
|
|
|
|
|
|
|
|
|
if v.State != 4 { |
|
|
|
|
|
//加油扣除优惠券额度 查询优惠券使用记录 |
|
|
|
|
|
if v.Pvd == md.PVD_OILSTATION { |
|
|
|
|
|
profits := v.CostPrice - v.PaidPrice |
|
|
|
|
|
profits = utils.FloatFormat(profits, 2) |
|
|
|
|
|
if profits > 0 { |
|
|
|
|
|
bools := ReduceCoupon(eg, dbName, utils.Float64ToStr(profits), uid, v.ItemId, md.PVD_OILSTATION, "OIL", newOrd.CreateAt, v.ItemTitle, utils.Int64ToStr(v.Oid)) |
|
|
|
|
|
//加入公告栏明细 |
|
|
|
|
|
if bools == 1 { |
|
|
|
|
|
AddPlacardRecord(eg, uid, "", "", md.PVD_OILSTATION, utils.Float64ToStr(profits), "") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
commCheckCoupon(eg, uid, v.ItemId, 0, 1, newOrd.Pvd, utils.Int64ToStr(v.Oid)) //导购的判断 |
|
|
|
|
|
} |
|
|
|
|
|
//定制 抽奖加入付款订单 |
|
|
|
|
|
req := md3.DayLuckDrawOrderJackpotReq{ |
|
|
|
|
|
Uid: utils.IntToStr(uid), |
|
|
|
|
|
Oid: utils.Int64ToStr(newOrd.OrdId), |
|
|
|
|
|
Pvd: newOrd.Pvd, |
|
|
|
|
|
Amount: utils.Float64ToStrByPrec(newOrd.PaidPrice, 7), |
|
|
|
|
|
Commission: utils.Float64ToStrByPrec(newOrd.BenefitAll, 7), |
|
|
|
|
|
} |
|
|
|
|
|
svc.AddOrderJackpot(eg, req) |
|
|
|
|
|
if cfg.Prd { |
|
|
|
|
|
CheckValid(eg, dbName, uid, 1, ch) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
if freeOrderType == 13 || freeOrderType == md.OrderTypeFree || freeOrderType == md.OrderTypeTljFree || freeOrderType == md.OrderTypeTljRelationFree { |
|
|
|
|
|
mutexKey := fmt.Sprintf("%s:all_order_to_store:%s:pvd:%s", dbName, v.PvdOid, v.Pvd) |
|
|
|
|
|
available, err := cache.Do("SET", mutexKey, 1, "EX", 5, "NX") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
if available != "OK" { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
arg := md.ZhiosOrderFree{ |
|
|
|
|
|
ItemId: newOrd.ItemId, |
|
|
|
|
|
SkuId: newOrd.NumItemId, |
|
|
|
|
|
OptPvd: newPvd, |
|
|
|
|
|
OrderType: utils.IntToStr(freeOrderType), |
|
|
|
|
|
Pid: v.Pid, |
|
|
|
|
|
Uid: utils.IntToStr(newOrd.Uid), |
|
|
|
|
|
Mid: dbName, |
|
|
|
|
|
Oid: utils.Int64ToStr(newOrd.OrdId), |
|
|
|
|
|
} |
|
|
|
|
|
if cfg.Prd { |
|
|
|
|
|
ch.Publish(md.OrderFree, utils.SerializeStr(arg), md.OrderFreeRoutKeyForOrder) |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
ch.Publish(md.OrderFree, utils.SerializeStr(arg), md.OrderFreeRoutKeyForOrderdev) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return nil |
|
|
|
|
|
} |