1
This commit is contained in:
@@ -2,6 +2,7 @@ package auto_delivery
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
@@ -14,9 +15,62 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var riderListInfo = make(map[string][]map[string]string, 0)
|
||||
|
||||
func Init() {
|
||||
db := dao.GetDB()
|
||||
// 骑手列表
|
||||
configRiderList, err := dao.QueryConfigs(db, "riderList", "AutoRiderList", "")
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("抖音自动刷单获取骑手列表错误:%v", err)
|
||||
return
|
||||
}
|
||||
list := make(map[string][]map[string]string, 0)
|
||||
if err := json.Unmarshal([]byte(configRiderList[0].Value), &list); err != nil {
|
||||
globals.SugarLogger.Errorf("抖音自动刷单获取骑手列表错误:%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range []string{"四川", "广东", "西安", "重庆"} {
|
||||
if _, ok := list[v]; ok && len(list[v]) >= 200 {
|
||||
continue
|
||||
}
|
||||
riderList, err := dao.GetAddressRiderInfo(db, v)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("初始化各省份骑手信息错误:[%v]", err)
|
||||
return
|
||||
}
|
||||
addressRiderList := make([]map[string]string, 0)
|
||||
for i := 0; i < len(riderList); i++ {
|
||||
if len(riderList[i].CourierMobile) == 11 {
|
||||
riderMap := make(map[string]string, 1)
|
||||
riderMap[riderList[i].CourierName] = riderList[i].CourierMobile
|
||||
addressRiderList = append(addressRiderList, riderMap)
|
||||
}
|
||||
if len(addressRiderList) >= 200 {
|
||||
list[v] = addressRiderList
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
listStr, err := json.Marshal(list)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("Marshal 骑手信息错误:[%v]", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := dao.UpdateOperatorConfig(string(listStr), "AutoRiderList", "riderList"); err != nil {
|
||||
globals.SugarLogger.Errorf("UpdateOperatorConfig 骑手配置信息错误:[%v]", err)
|
||||
return
|
||||
}
|
||||
riderListInfo = list
|
||||
}
|
||||
|
||||
// AutoSettingFakeDelivery 抖音自动设置骑手, 推送假订单
|
||||
func AutoSettingFakeDelivery() {
|
||||
db := dao.GetDB()
|
||||
|
||||
// 查询需要刷单的门店
|
||||
configList, err := dao.QueryConfigs(db, "storeIdList", "AutoDelivery", "")
|
||||
if err != nil {
|
||||
@@ -34,16 +88,34 @@ func AutoSettingFakeDelivery() {
|
||||
globals.SugarLogger.Errorf("获取门店刷单记录错误")
|
||||
return
|
||||
}
|
||||
if len(orderList) == model.NO {
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range orderList {
|
||||
jxutils.CallMsgHandler(func() {
|
||||
// 1.根据订单客户地址获取骑手列表
|
||||
randNumber, _ := rand.Int(rand.Reader, big.NewInt(200))
|
||||
riderKey := strings.Split(v.ConsigneeAddress, "省")[0]
|
||||
if len(riderListInfo[riderKey]) == model.NO {
|
||||
// 骑手列表
|
||||
configRiderList, err := dao.QueryConfigs(db, "riderList", "AutoRiderList", "")
|
||||
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()
|
||||
riderInfo, err := dao.GetAddressRiderInfo(db, strings.Split(v.ConsigneeAddress, "市")[0], randTime)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("自动获取骑手信息错误:[%v]", err)
|
||||
return
|
||||
if randTime < 0 {
|
||||
randTime = 1
|
||||
}
|
||||
if randTime > int64(len(riderListInfo[riderKey])) {
|
||||
randTime = int64(len(riderListInfo[riderKey])) - 1
|
||||
}
|
||||
|
||||
// 自动拣货
|
||||
@@ -54,11 +126,12 @@ func AutoSettingFakeDelivery() {
|
||||
return
|
||||
}
|
||||
//自动发单
|
||||
if err := defsch.FixedScheduler.SelfDeliveringAndUpdateStatus(jxcontext.AdminCtx, v.VendorOrderID, v.VendorID, jxcontext.AdminCtx.GetUserName(), riderInfo.CourierName, riderInfo.CourierMobile); err != nil {
|
||||
globals.SugarLogger.Errorf("自动发货错误:[%v]", err)
|
||||
return
|
||||
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)
|
||||
return
|
||||
}
|
||||
}
|
||||
}, jxutils.ComposeUniversalOrderID(v.VendorOrderID, model.VendorIDDD))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func UpdateStoreOperatorConfig() {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := dao.UpdateOperatorConfig(string(byteData)); err != nil {
|
||||
if err := dao.UpdateOperatorConfig(string(byteData), "Sys", "FZR"); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -1837,24 +1836,17 @@ type CourierInfo struct {
|
||||
CourierMobile string `json:"courier_mobile"`
|
||||
}
|
||||
|
||||
// 获取同区域的骑手信息
|
||||
func GetAddressRiderInfo(db *DaoDB, address string, randNumber int64) (*CourierInfo, error) {
|
||||
// GetAddressRiderInfo 获取同区域的骑手信息
|
||||
func GetAddressRiderInfo(db *DaoDB, address string) ([]*CourierInfo, error) {
|
||||
sql := `
|
||||
SELECT w.courier_name,w.courier_mobile FROM goods_order s
|
||||
SELECT DISTINCT w.courier_mobile,w.courier_name FROM goods_order s
|
||||
LEFT JOIN waybill w ON s.vendor_order_id = w.vendor_order_id AND w.courier_name <>"" AND w.courier_mobile <>""
|
||||
WHERE s.order_created_at >= ? AND s.status = ? AND s.delivery_type = ? AND s.consignee_address LIKE ?
|
||||
LIMIT ?,? `
|
||||
param := []interface{}{time.Now().AddDate(-1, 0, 0), model.OrderStatusFinished, model.OrderDeliveryTypePlatform, "%" + fmt.Sprintf("%s", address) + "%", randNumber, 1}
|
||||
WHERE s.order_created_at >= ? AND s.consignee_address LIKE ? `
|
||||
param := []interface{}{time.Now().AddDate(-2, 0, 0), "%" + fmt.Sprintf("%s", address) + "%"}
|
||||
|
||||
courier := &CourierInfo{}
|
||||
err := GetRow(db, courier, sql, param)
|
||||
|
||||
if (err != nil && strings.Contains(err.Error(), "no row found")) || courier.CourierName == "" || courier.CourierMobile == "" || len(courier.CourierMobile) != 11 {
|
||||
info, err := GetAddressRiderInfo(db, address, randNumber-1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return info, err
|
||||
var courier []*CourierInfo
|
||||
if err := GetRows(db, &courier, sql, param); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return courier, nil
|
||||
|
||||
@@ -62,8 +62,8 @@ func GetSysConfigAsInt64(db *DaoDB, key string) (value int64, err error) {
|
||||
}
|
||||
|
||||
// 修改配置
|
||||
func UpdateOperatorConfig(param string) error {
|
||||
func UpdateOperatorConfig(param string, types, key string) error {
|
||||
sql := `UPDATE new_config c SET c.value = ?,c.updated_at = ? WHERE c.type = ? AND c.key = ?`
|
||||
_, err := ExecuteSQL(GetDB(), sql, []interface{}{param, time.Now(), "Sys", "FZR"})
|
||||
_, err := ExecuteSQL(GetDB(), sql, []interface{}{param, time.Now(), types, key})
|
||||
return err
|
||||
}
|
||||
|
||||
8
main.go
8
main.go
@@ -4,6 +4,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/jx-callback/business/enterprise"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/auto_delivery"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
@@ -46,6 +47,8 @@ import (
|
||||
_ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/password"
|
||||
_ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
_ "git.rosy.net.cn/jx-callback/business/enterprise"
|
||||
_ "git.rosy.net.cn/jx-callback/business/jxcallback/auto_delivery"
|
||||
_ "git.rosy.net.cn/jx-callback/business/jxstore/act"
|
||||
_ "git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
@@ -53,8 +56,6 @@ import (
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/weimob/wsc"
|
||||
|
||||
_ "git.rosy.net.cn/jx-callback/business/jxstore/act"
|
||||
|
||||
_ "git.rosy.net.cn/jx-callback/routers"
|
||||
)
|
||||
|
||||
@@ -87,7 +88,8 @@ func Init() {
|
||||
jdshop.CurPurchaseHandler.StartRefreshComment()
|
||||
}
|
||||
misc.Init()
|
||||
enterprise.Init() // 初始化enterprise key
|
||||
enterprise.Init() // 初始化enterprise key
|
||||
auto_delivery.Init() // 初始化骑手列表
|
||||
}
|
||||
|
||||
// 返回true表示非运行服务
|
||||
|
||||
Reference in New Issue
Block a user