diff --git a/business/jxcallback/auto_delivery/auto_delivery.go b/business/jxcallback/auto_delivery/auto_delivery.go index 1e1a9e991..899e02e23 100644 --- a/business/jxcallback/auto_delivery/auto_delivery.go +++ b/business/jxcallback/auto_delivery/auto_delivery.go @@ -3,15 +3,15 @@ package auto_delivery import ( "crypto/rand" "encoding/json" + "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch" + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + "git.rosy.net.cn/jx-callback/business/partner" "math/big" "strings" "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch" - "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model/dao" - "git.rosy.net.cn/jx-callback/business/partner" "git.rosy.net.cn/jx-callback/globals" ) @@ -91,86 +91,79 @@ func AutoSettingFakeDelivery() { return } - // todo 修改刷单门店配置 storeId-vendorId 指定刷单门店和平台 0京东/1美团/3饿了么/14抖音/99全部平台 - // 获取刷单门店订单 - orderList, err := dao.GetOrderListByStoreList(db, utils.StringSlice2Int64(strings.Split(configList[0].Value, ","))) - if err != nil { - globals.SugarLogger.Errorf("获取门店刷单记录错误") - return - } - if len(orderList) == model.NO { - return - } + storeList := strings.Split(configList[0].Value, ",") + for _, v := range storeList { + storeIdAndVendorId := strings.Split(v, "-") + orderList, err := dao.GetOrderListByStoreList(db, []int64{utils.Str2Int64(storeIdAndVendorId[0])}, utils.Str2Int(storeIdAndVendorId[1])) + if err != nil { + globals.SugarLogger.Errorf("获取门店刷单记录错误") + continue + } + if len(orderList) == model.NO { + return + } - for _, v := range orderList { // 1.根据订单客户地址获取骑手列表 riderKey := "" - if strings.Contains(v.ConsigneeAddress, "重庆") || strings.Contains(v.ConsigneeAddress, "上海") || strings.Contains(v.ConsigneeAddress, "北京") || strings.Contains(v.ConsigneeAddress, "天津") { - riderKey = strings.Split(v.ConsigneeAddress, "市")[0] - } else if strings.Contains(v.ConsigneeAddress, "省") { - riderKey = strings.Split(v.ConsigneeAddress, "省")[0] + storeDetail, _ := dao.GetStoreDetail(db, utils.Str2Int(storeIdAndVendorId[0]), 0, "") + place, err := dao.GetParentCodeByCode(db, storeDetail.CityCode) + if err != nil { + globals.SugarLogger.Debugf("根据门店的城市code获取省份code错误: %s", err) + return + } + if strings.Contains(place.Name, "省") { + riderKey = strings.Split(place.Name, "省")[0] } else { - storeDetail, _ := dao.GetStoreDetail(db, v.JxStoreID, 0, "") - if strings.Contains(storeDetail.Address, "重庆") || strings.Contains(storeDetail.Address, "上海") || strings.Contains(storeDetail.Address, "北京") || strings.Contains(storeDetail.Address, "天津") { - riderKey = strings.Split(storeDetail.Address, "市")[0] - } else { - riderKey = strings.Split(storeDetail.Address, "省")[0] - if riderKey == "" { - place, err := dao.GetParentCodeByCode(db, storeDetail.CityCode) - if err != nil { - globals.SugarLogger.Debugf("根据门店的城市code获取省份code错误: %s", err) - return - } - riderKey = place.Name[0 : len(place.Name)-3] + riderKey = strings.Split(place.Name, "市")[0] + } + + for _, v := range orderList { + if len(riderListInfo[riderKey]) == model.NO { + // 骑手列表 + configRiderList, err := dao.QueryConfigs(db, "riderList", "Sys", "") + if err != nil { + globals.SugarLogger.Errorf("抖音自动刷单获取骑手列表错误:%v", err) + return + } + if err := json.Unmarshal([]byte(configRiderList[0].Value), &riderListInfo); err != nil { + globals.SugarLogger.Errorf("抖音自动刷单获取骑手列表错误:%v", err) + return + } + } + randNumber, _ := rand.Int(rand.Reader, big.NewInt(int64(len(riderListInfo[riderKey])))) + randTime := randNumber.Int64() + if randTime < 0 { + randTime = 1 + } + if randTime >= int64(len(riderListInfo[riderKey])) { + randTime = int64(len(riderListInfo[riderKey])) - 1 + } + if (v.PhoneAscription == "" || strings.Split(v.PhoneAscription, "-")[0] != model.PhoneAscriptionAddressYes) && v.VendorID == model.VendorIDDD { + continue + } + // 自动拣货 + if v.Status < model.OrderStatusFinishedPickup { // 未拣货 + handler := partner.GetPurchaseOrderHandlerFromVendorID(v.VendorID) + flag := model.IsOrderDeliveryByStore(v) || model.IsOrderDeliveryBySelf(v) + if err := handler.PickupGoods(v, flag, jxcontext.AdminCtx.GetUserName()); err != nil { + globals.SugarLogger.Errorf("自动拣货错误:[%v]", err) + break + } + } + //自动发单 + if len(riderListInfo[riderKey]) == 0 { + globals.SugarLogger.Errorf("riderListInfo[riderKey][randTime] :%s,%s,%d", riderListInfo[riderKey][randTime], riderKey, randTime) + break + } + for riderName, riderPhone := range riderListInfo[riderKey][randTime] { + if err := defsch.FixedScheduler.SelfDeliveringAndUpdateStatus(jxcontext.AdminCtx, v.VendorOrderID, v.VendorID, jxcontext.AdminCtx.GetUserName(), riderName, riderPhone); err != nil { + globals.SugarLogger.Errorf("自动发货错误:[%v]", err) + break } } } - if len(riderListInfo[riderKey]) == model.NO { - // 骑手列表 - configRiderList, err := dao.QueryConfigs(db, "riderList", "Sys", "") - if err != nil { - globals.SugarLogger.Errorf("抖音自动刷单获取骑手列表错误:%v", err) - return - } - if err := json.Unmarshal([]byte(configRiderList[0].Value), &riderListInfo); err != nil { - globals.SugarLogger.Errorf("抖音自动刷单获取骑手列表错误:%v", err) - return - } - } - globals.SugarLogger.Debug("==========%s,%d", riderKey, len(riderListInfo[riderKey])) - globals.SugarLogger.Debug("==========%s", utils.Format4Output(riderListInfo[riderKey], false)) - randNumber, _ := rand.Int(rand.Reader, big.NewInt(int64(len(riderListInfo[riderKey])))) - randTime := randNumber.Int64() - if randTime < 0 { - randTime = 1 - } - if randTime >= int64(len(riderListInfo[riderKey])) { - randTime = int64(len(riderListInfo[riderKey])) - 1 - } - if (v.PhoneAscription == "" || strings.Split(v.PhoneAscription, "-")[0] != model.PhoneAscriptionAddressYes) && v.VendorID == model.VendorIDDD { - continue - } - // 自动拣货 - if v.Status < model.OrderStatusFinishedPickup { // 未拣货 - handler := partner.GetPurchaseOrderHandlerFromVendorID(v.VendorID) - flag := model.IsOrderDeliveryByStore(v) || model.IsOrderDeliveryBySelf(v) - if err := handler.PickupGoods(v, flag, jxcontext.AdminCtx.GetUserName()); err != nil { - globals.SugarLogger.Errorf("自动拣货错误:[%v]", err) - break - } - } - //自动发单 - if len(riderListInfo[riderKey]) == 0 { - globals.SugarLogger.Errorf("riderListInfo[riderKey][randTime] :%s,%s,%d", riderListInfo[riderKey][randTime], riderKey, randTime) - break - } - for riderName, riderPhone := range riderListInfo[riderKey][randTime] { - if err := defsch.FixedScheduler.SelfDeliveringAndUpdateStatus(jxcontext.AdminCtx, v.VendorOrderID, v.VendorID, jxcontext.AdminCtx.GetUserName(), riderName, riderPhone); err != nil { - globals.SugarLogger.Errorf("自动发货错误:[%v]", err) - break - } - } } + } diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index dd539dc81..3274713a8 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -210,9 +210,7 @@ func Init() { // 抖音自动刷单(自动发单拣货,设置骑手) ScheduleTimerFuncByInterval(func() { - if beego.BConfig.RunMode != "jxgy" { - auto_delivery.AutoSettingFakeDelivery() - } + auto_delivery.AutoSettingFakeDelivery() }, 10*time.Second, 3*time.Minute) // 定时任务更新负责人信息 diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index deccb62cd..1090193bf 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -1906,9 +1906,9 @@ func GetOrderStoreIDs(db *DaoDB, beginAt, endAt time.Time, vendorID int) (storeI } // GetOrderListByStoreList 根据门店id获取正在刷单的门店商品 -func GetOrderListByStoreList(db *DaoDB, storeId []int64) (order []*model.GoodsOrder, err error) { +func GetOrderListByStoreList(db *DaoDB, storeId []int64, vendorId int) (order []*model.GoodsOrder, err error) { sql := `SELECT * FROM goods_order g WHERE g.order_created_at >= ? AND g.order_created_at <= ? AND g.jx_store_id IN (` + GenQuestionMarks(len(storeId)) + `)` + `AND g.vendor_id IN (` + GenQuestionMarks(2) + `)` + `AND g.status < ?` - sqlParam := []interface{}{time.Now().AddDate(0, 0, -5), time.Now().AddDate(0, 0, 1), storeId, []int{model.VendorIDDD, model.VendorIDEBAI}, model.OrderStatusDelivering} + sqlParam := []interface{}{time.Now().AddDate(0, 0, -5), time.Now().AddDate(0, 0, 1), storeId, []int{vendorId}, model.OrderStatusDelivering} if err := GetRows(db, &order, sql, sqlParam...); err != nil { return nil, err