From 31bab26d1e7feffd26029ab0750b5dd9e2e3c589 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 16 May 2024 10:15:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/md/provider.go | 1 + app/svc/svc_order_track_parse_pid.go | 2 +- app/svc/svc_order_track_save_create_update.go | 1045 +++++++++++++++++ app/svc/svc_order_track_save_update.go | 4 +- consume/init.go | 5 +- consume/md/consume_key.go | 10 + ...hios_order_track_create_for_pdd_consume.go | 90 ++ 7 files changed, 1153 insertions(+), 4 deletions(-) create mode 100644 app/svc/svc_order_track_save_create_update.go create mode 100644 consume/zhios_order_track_create_for_pdd_consume.go diff --git a/app/md/provider.go b/app/md/provider.go index dfaef66..5cf17e0 100644 --- a/app/md/provider.go +++ b/app/md/provider.go @@ -25,6 +25,7 @@ const ( PVD_JD = "jd" PVD_JDOwn = "jd_own" PVD_JDUNIONOWN = "jd_union_own" + PVD_PDDUNIONOWN = "pdd_union_own" PVD_JDUNIONOWNUPDATE = "jd_union_own_update" PVD_SN = "suning" PVD_VIP = "vip" diff --git a/app/svc/svc_order_track_parse_pid.go b/app/svc/svc_order_track_parse_pid.go index 711f4a0..22b2cf3 100644 --- a/app/svc/svc_order_track_parse_pid.go +++ b/app/svc/svc_order_track_parse_pid.go @@ -245,7 +245,7 @@ func parsePids(eg *xorm.Engine, masterId, pvd string, pids []string) map[int]*md orderType := md.OrderTypeSelf types := "self" isContinue := 1 - if len(s) == 2 && (pvd == md.PVD_JD || pvd == md.PVD_JDOwn) { + if len(s) == 2 { id = utils.StrToInt(s[1]) types = s[0] isContinue = 0 diff --git a/app/svc/svc_order_track_save_create_update.go b/app/svc/svc_order_track_save_create_update.go new file mode 100644 index 0000000..1bd0912 --- /dev/null +++ b/app/svc/svc_order_track_save_create_update.go @@ -0,0 +1,1045 @@ +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" + "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 OrderSaveCreateUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts 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) + + 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 == 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 { + 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 v.PriceType > 0 || v.ThirdPriceType > 0 { + //直接退回账号了 定制 + storeOrder := db.GuideStoreOrder(eg, v.OrdId) + if storeOrder != nil { + isSet := 0 + if v.State != ords[v.PvdOid].State { + storeOrder.State = ords[v.PvdOid].State + isSet = 1 + } + if v.SettleAt > 0 { + isSet = 1 + storeOrder.SettleAt = v.SettleAt + } + if isSet == 1 { + eg.Where("id=?", storeOrder.Id).Update(storeOrder) + } + } + } + + 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.PriceType > 0 { + m, _ := db.FreeProductByID(eg, v.ItemId, v.Pvd) + //直接退回账号了 定制 + storeOrder := db.GuideStoreOrder(eg, v.OrdId) + if m != nil { + if storeOrder == nil { + m.Stock++ + m.Sale-- + if m.Sale < 0 { + m.Sale = 0 + } + eg.Where("id=?", m.Id).Cols("sale,stock").Update(m) + } else if storeOrder != nil && utils.StrToFloat64(storeOrder.DeductPrice) > 0 && storeOrder.DeductState == 1 { + arg := md.ZhiosGuideStoreOrder{ + Uid: utils.IntToStr(v.Uid), + Mid: dbName, + Oid: utils.Int64ToStr(v.OrdId), + Pvd: v.Pvd, + ItemId: v.ItemId, + Type: "fail", + } + if cfg.Prd { + ch.Publish(md.GuideStoreOrder, utils.SerializeStr(arg), md.GuideStoreRoutKeyForOrder) + } else { + ch.Publish(md.GuideStoreOrder, utils.SerializeStr(arg), md.GuideStoreRoutKeyForOrderDev) + } + } + } + } + if v.State != 4 && v.SecondPriceType > 0 { + m, _ := db.SecondFreeProductByID(eg, v.ItemId, v.Pvd) + if m != nil { + m.Stock++ + m.Sale-- + if m.Sale < 0 { + m.Sale = 0 + } + eg.Where("id=?", m.Id).Cols("sale,stock").Update(m) + } + } + if v.State == 4 && v.PriceType > 0 { + m, _ := db.FreeProductByID(eg, v.ItemId, v.Pvd) + //直接退回账号了 定制 + storeOrder := db.GuideStoreOrder(eg, v.OrdId) + if m != nil { + if storeOrder != nil && utils.StrToFloat64(storeOrder.DeductPrice) > 0 && storeOrder.DeductState == 1 { + arg := md.ZhiosGuideStoreOrder{ + Uid: utils.IntToStr(v.Uid), + Mid: dbName, + Oid: utils.Int64ToStr(v.OrdId), + Pvd: v.Pvd, + ItemId: v.ItemId, + Type: "fail", + } + if cfg.Prd { + ch.Publish(md.GuideStoreOrder, utils.SerializeStr(arg), md.GuideStoreRoutKeyForOrder) + } else { + ch.Publish(md.GuideStoreOrder, utils.SerializeStr(arg), md.GuideStoreRoutKeyForOrderDev) + } + } + } + + } + if v.State == 4 && v.ThirdPriceType > 0 { + m, _ := db.MoreFreeProductByID(eg, v.ItemId, v.Pvd) + //直接退回账号了 定制 + storeOrder := db.GuideStoreOrder(eg, v.OrdId) + if m != nil { + if storeOrder != nil && utils.StrToFloat64(storeOrder.DeductPrice) > 0 && storeOrder.DeductState == 1 { + arg := md.ZhiosGuideStoreOrder{ + Uid: utils.IntToStr(v.Uid), + Mid: dbName, + Oid: utils.Int64ToStr(v.OrdId), + Pvd: v.Pvd, + ItemId: v.ItemId, + Type: "fail", + } + if cfg.Prd { + ch.Publish(md.GuideStoreOrder, utils.SerializeStr(arg), md.GuideStoreRoutKeyForOrder) + } else { + ch.Publish(md.GuideStoreOrder, utils.SerializeStr(arg), md.GuideStoreRoutKeyForOrderDev) + } + } + } + } + + } + 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 != ords[v.PvdOid].State && (v.State != 4 || v.Pvd == md.PVD_JD || v.Pvd == md.PVD_JDOwn || v.Pvd == md.PVD_ELM) { + if ords[v.PvdOid].Reason != "" { + v.Reason = ords[v.PvdOid].Reason + } + v.State = ords[v.PvdOid].State + if ords[v.PvdOid].State != 4 && (v.State == 5 || v.SettleAt > 0) { //如果不是失效 平台结算状态都不改了 + v.State = 5 + } + v.UpdateAt = now + if utils.InArr(utils.IntToStr(v.State), []string{"1", "2"}) && v.ConfirmAt == 0 { + if ords[v.PvdOid].ConfirmAt > 0 { + v.ConfirmAt = int(ords[v.PvdOid].ConfirmAt) + } else { + v.ConfirmAt = v.UpdateAt + } + } + // 供应商结算时间 + if v.State == md.OrderStatePvdSettle { + if ords[v.PvdOid].EndTime > 0 { + v.PvdSettleAt = int(ords[v.PvdOid].EndTime) + } else { + v.PvdSettleAt = v.UpdateAt + } + } + _ = db.DbsOrderUpdate(eg, v.OrdId, &v) + //查询优惠券使用记录 + if v.State == 4 { + //commCheckCoupon(eg, v.Uid, v.ItemId, 1, 0, v.Pvd) + commRefundCoupon(eg, v.Uid, v.ItemId, 1, 0, v.Pvd) + } + //如果是光汇加油的 要改下另一个表 + if ords[v.PvdOid].Source == "5" { + state := 1 + if v.State == 4 { + state = 2 + } + db.BrightOilUpdate(eg, ords[v.PvdOid].PvdOid, state) + } + // newOrder hook + } + if v.State != 4 && ords[v.PvdOid].State != 4 { + AcquisitionHookFirstOrder(eg, dbName, &v) + } + if v.State == 4 && (v.Pvd == md.PVD_JD || v.Pvd == md.PVD_JDOwn) && ords[v.PvdOid].State != 4 { + v.State = ords[v.PvdOid].State + _ = db.DbsOrderUpdate(eg, v.OrdId, &v) + } + //如果没有用户这里要做处理 仅针对淘宝 或美团联盟没有佣金的情况 + commCheckUser(eg, v, ords, pvd, pidToUser, opts, dbName, false, returnMoneyType) + + } + //处理下没有分佣明细的订单 + 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, 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, 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) + 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, "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 == 13 || v.OrderType == md.OrderTypeFree || v.OrderType == md.OrderTypeTljFree || v.OrderType == md.OrderTypeTljRelationFree { + if user == nil || user.Uid == 0 { //判断免单的如果没有用户不跟这个订单 + continue + } + v.OptPvd = newPvd + v.OrderType = 0 + } + //TODO 多方案 + if v.OrderType == 11 || v.OrderType == 12 { //多方案 + if user == nil || user.Uid == 0 { //判断免单的如果没有用户不跟这个订单 + continue + } + freeOrder := orderSecondFreeCheck(eg, &v, oid, user.Uid, 0) + if freeOrder != nil { + optPvd = "seFree_" + 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) + 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) + // 如果不存在的订单, 则进行计算更新 + 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 + if !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 == 15 || v.OrderType == md.OrderTypeFree || v.OrderType == md.OrderTypeTljFree || v.OrderType == md.OrderTypeTljRelationFree { + if user == nil || user.Uid == 0 { //判断免单的如果没有用户不跟这个订单 + continue + } + v.OptPvd = newPvd + v.OrderType = 0 + } + if v.OrderType == 13 { + if user == nil || user.Uid == 0 { //判断免单的如果没有用户不跟这个订单 + continue + } + v.OptPvd = newPvd + v.OrderType = 0 + } + if v.OrderType == 11 || v.OrderType == 12 { + if user == nil || user.Uid == 0 { //判断免单的如果没有用户不跟这个订单 + continue + } + //TODO + freeOrder := orderSecondFreeCheck(eg, &v, oid, user.Uid, 1) + if freeOrder != nil { + secondPriceType = freeOrder.PriceType + // 切换免单活动的分佣方案, 如1元购等 + optPvd = "seFree_" + utils.IntToStr(freeOrder.PriceType) + opt = opts[optPvd] + } + } + 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{} + if user != nil { + user.OwnbuyReturnType = ownbuyReturnType //是否有自购奖励 + uid = user.Uid + userLv := user.Lv + pvdOid := v.PvdOid + 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 == 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 + } + // 插入新订单 + newOrd := &model.OrdList{ + 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, + 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, + }) + 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) + } + 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, + 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 +} diff --git a/app/svc/svc_order_track_save_update.go b/app/svc/svc_order_track_save_update.go index 7e25147..f0df1a1 100644 --- a/app/svc/svc_order_track_save_update.go +++ b/app/svc/svc_order_track_save_update.go @@ -348,7 +348,9 @@ func OrderSaveUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts _ = db.DbsOrderUpdate(eg, v.OrdId, &v) } if v.State != ords[v.PvdOid].State && (v.State != 4 || v.Pvd == md.PVD_JD || v.Pvd == md.PVD_JDOwn || v.Pvd == md.PVD_ELM) { - v.Reason = ords[v.PvdOid].Reason + if ords[v.PvdOid].Reason != "" { + v.Reason = ords[v.PvdOid].Reason + } v.State = ords[v.PvdOid].State if ords[v.PvdOid].State != 4 && (v.State == 5 || v.SettleAt > 0) { //如果不是失效 平台结算状态都不改了 v.State = 5 diff --git a/consume/init.go b/consume/init.go index e9a130a..047095d 100644 --- a/consume/init.go +++ b/consume/init.go @@ -22,8 +22,9 @@ func initConsumes() { //jobs[consumeMd.ZhiosOrderTrackRefundForTbAllConsumeFunName] = ZhiosOrderTrackRefundForTbAllConsume //淘宝-全部退款 //jobs[consumeMd.ZhiosOrderTrackRefundForTbPartConsumeFunName] = ZhiosOrderTrackRefundForTbPartConsume //淘宝-部分退款 - jobs[consumeMd.ZhiosOrderTrackCreateForJdConsumeFunName] = ZhiosOrderTrackCreateForJdConsume //京东-创建订单 - jobs[consumeMd.ZhiosOrderTrackUpdateForJdConsumeFunName] = ZhiosOrderTrackUpdateForJdConsume //京东-更新订单 + jobs[consumeMd.ZhiosOrderTrackCreateForJdConsumeFunName] = ZhiosOrderTrackCreateForJdConsume //京东-创建订单 + jobs[consumeMd.ZhiosOrderTrackUpdateForJdConsumeFunName] = ZhiosOrderTrackUpdateForJdConsume //京东-更新订单 + jobs[consumeMd.ZhiosOrderTrackCreateForPddConsumeFunName] = ZhiosOrderTrackCreateForPddConsume //拼多多-全部订单 } diff --git a/consume/md/consume_key.go b/consume/md/consume_key.go index 38e08ff..61e76cb 100644 --- a/consume/md/consume_key.go +++ b/consume/md/consume_key.go @@ -47,6 +47,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ BindKey: "", ConsumeFunName: "ZhiosOrderTrackCreateForJdConsume", }, + { + ExchangeName: "zhios.order_track_create.exchange", + Name: "order_track_create_for_pdd", + Type: DirectQueueType, + IsPersistent: false, + RoutKey: "pdd", + BindKey: "", + ConsumeFunName: "ZhiosOrderTrackCreateForPddConsume", + }, { ExchangeName: "zhios.order_track_refund.exchange", Name: "order_track_refund_for_tb_all", @@ -71,6 +80,7 @@ const ( ZhiosOrderTrackUpdateForTbConsumeFunName = "ZhiosOrderTrackUpdateForTbConsume" ZhiosOrderTrackCreateForTbConsumeFunName = "ZhiosOrderTrackCreateForTbConsume" ZhiosOrderTrackCreateForJdConsumeFunName = "ZhiosOrderTrackCreateForJdConsume" + ZhiosOrderTrackCreateForPddConsumeFunName = "ZhiosOrderTrackCreateForPddConsume" ZhiosOrderTrackUpdateForJdConsumeFunName = "ZhiosOrderTrackUpdateForJdConsume" ZhiosOrderTrackRefundForTbAllConsumeFunName = "ZhiosOrderTrackRefundForTbAllConsume" ZhiosOrderTrackRefundForTbPartConsumeFunName = "ZhiosOrderTrackRefundForTbPartConsume" diff --git a/consume/zhios_order_track_create_for_pdd_consume.go b/consume/zhios_order_track_create_for_pdd_consume.go new file mode 100644 index 0000000..6b7ae68 --- /dev/null +++ b/consume/zhios_order_track_create_for_pdd_consume.go @@ -0,0 +1,90 @@ +package consume + +import ( + "applet/app/cfg" + "applet/app/db" + md2 "applet/app/md" + svc2 "applet/app/svc" + "applet/app/utils" + "applet/app/utils/logx" + "applet/consume/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles" + "encoding/json" + "errors" + "fmt" + "github.com/streadway/amqp" + "time" +) + +func ZhiosOrderTrackCreateForPddConsume(queue md.MqQueue) { + fmt.Println(">>>>>>>>>>>>ZhiosOrderTrackCreateForPddConsume>>>>>>>>>>>>") + 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(1) + delivery := ch.Consume(queue.Name, false) + + one_circles.Init(cfg.RedisAddr) + + var res amqp.Delivery + var ok bool + for { + res, ok = <-delivery + if ok == true { + err = handleZhiosOrderTrackCreateForPddConsume(res.Body) + fmt.Println("err ::: ", err) + if err != nil { + fmt.Println("ZhiosOrderTrackCreateForPddConsume_ERR:::::", err.Error()) + _ = res.Reject(true) //TODO::拒绝 Ack + //_ = res.Reject(false) + var msg interface{} + json.Unmarshal(res.Body, &msg) + if err.Error() == "Connection timed out" { + //TODO::重新推回队列末尾,避免造成队列堵塞 + ch.Publish(queue.ExchangeName, msg, queue.RoutKey) + } else { + //TODO::推入新的队列中备份 + utils.FilePutContents("ZhiosOrderTrackCreateForPddConsume_ERR", utils.SerializeStr(err.Error())) + ch.Publish("zhios.order_track_create_exception.exchange", map[string]interface{}{ + "msg": msg, + "err": err.Error(), + }, "pdd") + } + } else { + err = res.Ack(true) + } + } else { + panic(errors.New("error getting message")) + } + } + fmt.Println("get msg done") +} + +func handleZhiosOrderTrackCreateForPddConsume(msgData []byte) error { + //1、解析mq中queue的数据结构体 + var msg md2.ZhiosOrderTrackCreateRoutKeyForTb + err := json.Unmarshal(msgData, &msg) + if err != nil { + return err + } + time.Sleep(time.Microsecond * 100) // 等待100毫秒 + fmt.Println("order_track_create_for_Pdd_message:::::::::::>>>>>>>>>") + fmt.Println(msg) + if db.DBs[msg.DbName] == nil { + return nil + } + engine := db.DBs[msg.DbName] + err = svc2.OrderSaveCreateUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.DbName) + if err != nil { + fmt.Println("order_track_create_for_Pdd_ERR:::::::::::>>>>>>>>>", err.Error()) + return err + } + return nil +}