yuliang1112 2 éve
szülő
commit
59a4269f10

+ 3 - 0
.idea/watcherTasks.xml

@@ -25,5 +25,8 @@
         <env name="PATH" value="$GoBinDirs$" />
       </envs>
     </TaskOptions>
+    <enabled-global>
+      <option value="go fmt" />
+    </enabled-global>
   </component>
 </project>

+ 34 - 0
consts/project.go

@@ -202,3 +202,37 @@ func GetRechargeMethod(method int64) string {
 	}
 	return "未知"
 }
+
+var KD100Flags = map[string]string{
+	"圆通":     "yuantong",
+	"韵达":     "yunda",
+	"申通":     "shentong",
+	"中通":     "zhongtong",
+	"顺丰":     "shunfeng",
+	"极兔":     "jtexpress",
+	"邮政":     "youzhengguonei",
+	"EMS":    "ems",
+	"京东":     "jd",
+	"邮政标准快递": "youzhengbk",
+	"丰网速运":   "fengwang",
+	"德邦快递":   "debangkuaidi",
+	"德邦":     "debangwuliu",
+	"丹鸟":     "danniao",
+	"飞豹快递":   "feibaokuaidi",
+	"中通快运":   "zhongtongkuaiyun",
+	"安能快运":   "annengwuliu",
+	"百世快递":   "huitongkuaidi",
+	"安得物流":   "annto",
+	"跨越速运":   "kuayue",
+	"特急送":    "lntjs",
+	"宅急送":    "zhaijisong",
+	"other":  "其它快递",
+}
+
+func GetKD(Kd string) string {
+	toast, contain := KD100Flags[Kd]
+	if contain {
+		return toast
+	}
+	return "未知"
+}

+ 2 - 2
db/finance.go

@@ -75,8 +75,8 @@ func GetWithdrawRecords(ctx context.Context, pageSize, pageNum int32, req *http_
 		withdrawRecordsData.WithdrawId = withdrawRecord.WithdrawID
 		withdrawRecordsData.TalentId = withdrawRecord.TalentID
 		withdrawRecordsData.TalentName = talentIdToTalentInfoMap[withdrawRecord.TalentID].TalentWxNickname
-		withdrawRecordsData.WithdrawAmount = float32(withdrawRecord.WithdrawAmount)
-		withdrawRecordsData.AmountPayable = float32(withdrawRecord.AmountPayable)
+		withdrawRecordsData.WithdrawAmount = withdrawRecord.WithdrawAmount
+		withdrawRecordsData.AmountPayable = withdrawRecord.AmountPayable
 		withdrawRecordsData.ReceiveInfo = withdrawRecord.ReceiveInfo
 		withdrawRecordsData.BankType = withdrawRecord.BankType
 		withdrawRecordsData.Phone = talentIdToTalentInfoMap[withdrawRecord.TalentID].TalentPhoneNumber

+ 33 - 0
db/number_info.go

@@ -2,6 +2,9 @@ package db
 
 import (
 	"context"
+	"fmt"
+	"strconv"
+	"time"
 	"youngee_m_api/model/gorm_model"
 	"youngee_m_api/model/http_model"
 
@@ -210,3 +213,33 @@ func GetFinishNumberInfo(ctx context.Context, projectId int64, strategyIds []int
 	}
 	return &FinishNumberInfoDataList, nil
 }
+
+func GetLogisticsNum() [][]string {
+	var logisticNumsInfos [][]string
+	db := GetReadDB(context.Background())
+	var logisticInfos []*gorm_model.YoungeeTaskLogistics
+	db.Model(gorm_model.YoungeeTaskLogistics{}).Where("things_type = 1 AND status = 0").Find(&logisticInfos)
+	for _, logisticInfo := range logisticInfos {
+		var logisticNumsInfo []string
+		logisticNumsInfo = append(logisticNumsInfo, logisticInfo.CompanyName, logisticInfo.LogisticsNumber, strconv.FormatInt(logisticInfo.LogisticsID, 10))
+		logisticNumsInfos = append(logisticNumsInfos, logisticNumsInfo)
+	}
+	fmt.Println("logisticNumsInfos:", logisticNumsInfos)
+	return logisticNumsInfos
+}
+
+func SignLogistic(logisticId int64) {
+	db := GetReadDB(context.Background())
+	var taskId, projectId, contentType int64
+	db.Model(gorm_model.YoungeeTaskLogistics{}).Select("task_id").Where("logistics_id = ?", logisticId).Find(&taskId)
+	db.Model(gorm_model.YoungeeTaskInfo{}).Select("project_id").Where("task_id = ?", taskId).Find(&projectId)
+	db.Model(gorm_model.ProjectInfo{}).Select("content_type").Where("project_id = ?", projectId).Find(&contentType)
+	db.Model(gorm_model.YoungeeTaskLogistics{}).Where("logistics_id = ?", logisticId).Updates(&gorm_model.YoungeeTaskLogistics{SignedTime: time.Now(), Status: 1})
+	if contentType == 1 {
+		db.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Updates(&gorm_model.YoungeeTaskInfo{LogisticsStatus: 3, TaskStage: 9})
+		fmt.Printf("任务 %v 物流状态为已签收,已更新任务状态为 待传初稿\n", taskId)
+	} else {
+		db.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Updates(&gorm_model.YoungeeTaskInfo{LogisticsStatus: 3, TaskStage: 7})
+		fmt.Printf("任务 %v 物流状态为已签收,已更新任务状态为 待传脚本\n", taskId)
+	}
+}

+ 1 - 1
db/operate.go

@@ -752,7 +752,7 @@ func GetAutoInvalidTask() error {
 		dd, _ := time.ParseDuration(conv.MustString(Invalid, "") + "h")
 		project.RecruitDdl.Add(dd)
 		t := project.RecruitDdl.Add(dd)
-		fmt.Println("已存在的失效时间是否跟要添加的相等", project.AutoFailAt.Equal(t))
+		//fmt.Println("已存在的失效时间是否跟要添加的相等", project.AutoFailAt.Equal(t))
 		if project.AutoFailAt != &t {
 			db3 := GetReadDB(context.Background())
 			db3.Model(gorm_model.ProjectInfo{}).Where("project_id = ?", projectId).Updates(&gorm_model.ProjectInfo{AutoFailAt: &t})

+ 1 - 0
model/gorm_model/task_logistic.go

@@ -20,4 +20,5 @@ type YoungeeTaskLogistics struct {
 	AutoSignAt            time.Time `gorm:"column:auto_sign_at"`                            // 自动签收时间
 	AutoScriptBreakAt     time.Time `gorm:"column:auto_script_break_at"`                    // 脚本违约自动处理时间
 	AutoSketchBreakAt     time.Time `gorm:"column:auto_sketch_break_at"`                    // 初稿违约自动处理时间
+	Status                int       `gorm:"column:status;default:0"`                        // 签收状态,0为未签收,1为已签收
 }

+ 2 - 2
model/gorm_model/withdraw_info.go

@@ -9,8 +9,8 @@ import (
 type YounggeeWithdrawRecord struct {
 	WithdrawID     string    `gorm:"column:withdraw_id;primary_key"`  // 提现订单ID
 	TalentID       string    `gorm:"column:talent_id;NOT NULL"`       // 达人id
-	WithdrawAmount int64     `gorm:"column:withdraw_amount;NOT NULL"` // 提现金额
-	AmountPayable  int64     `gorm:"column:amount_payable;NOT NULL"`  // 应付金额
+	WithdrawAmount float64   `gorm:"column:withdraw_amount;NOT NULL"` // 提现金额
+	AmountPayable  float64   `gorm:"column:amount_payable;NOT NULL"`  // 应付金额
 	TaskIDList     string    `gorm:"column:task_id_list;NOT NULL"`    // 该提现订单包含的task_id列表
 	ReceiveInfo    string    `gorm:"column:receive_info;NOT NULL"`    // 收款信息
 	Status         int       `gorm:"column:status;NOT NULL"`          // 提现状态:1为提现待确认,2为已提现

+ 2 - 2
model/http_model/WithDrawalRecordsRequest.go

@@ -14,8 +14,8 @@ type WithdrawalRecordsData struct {
 	WithdrawId     string  `json:"withdraw_id"`
 	TalentId       string  `json:"talent_id"`
 	TalentName     string  `json:"talent_name"`
-	WithdrawAmount float32 `json:"withdraw_amount"`
-	AmountPayable  float32 `json:"amount_payable"`
+	WithdrawAmount float64 `json:"withdraw_amount"`
+	AmountPayable  float64 `json:"amount_payable"`
 	ReceiveInfo    string  `json:"receive_info"`
 	BankType       int     `json:"bank_type"`
 	Phone          string  `json:"phone"`

+ 21 - 2
service/auto_task.go

@@ -2,10 +2,13 @@ package service
 
 import (
 	"context"
+	"fmt"
+	"github.com/caixw/lib.go/conv"
 	"github.com/robfig/cron/v3"
 	"github.com/sirupsen/logrus"
 	"log"
 	"time"
+	"youngee_m_api/consts"
 	"youngee_m_api/db"
 	"youngee_m_api/model/gorm_model"
 )
@@ -16,6 +19,18 @@ func AutoTask() error {
 	//crontab := cron.New()  默认从分开始进行时间调度
 	crontab := cron.New(cron.WithSeconds()) //精确到秒
 	//定义定时器调用的任务函数
+	taskKDStatus := func() {
+		logisticNums := db.GetLogisticsNum()
+		fmt.Println(len(logisticNums))
+		for i := 0; i < len(logisticNums); i++ {
+			logisticNum := logisticNums[i]
+			log.Println("logisticNum:", logisticNum)
+			status := GetKDStatus(consts.GetKD(logisticNum[0]), logisticNum[1])
+			if status == "1" {
+				db.SignLogistic(conv.MustInt64(logisticNum[2], 0))
+			}
+		}
+	}
 	//定时任务1 ,线下探店打卡的自动签收操作
 	task1 := func() {
 		DB := db.GetReadDB(context.Background())
@@ -185,10 +200,14 @@ func AutoTask() error {
 		log.Println("GetAutoCaseCloseDefaultTask is running ,Time :", time.Now())
 	}
 	//定时任务
-	spec := "*/30 * * * * ?" //cron表达式,每10秒一次
+	//spec := "*/30 * * * * ?" //cron表达式,每10秒一次
 	//spec := "0 */30 * * * ?" //cron表达式,每一分钟执行一次
-	//spec := "0 0 * * * *" //每小时执行
+	spec := "0 0 * * * *" //每小时执行
 	// 添加定时任务,
+	_, err := crontab.AddFunc("@midnight", taskKDStatus)
+	if err != nil {
+		return err
+	}
 	_, err1 := crontab.AddFunc(spec, task1)
 	if err1 != nil {
 		return err1

+ 98 - 0
service/kuaiDi100.go

@@ -0,0 +1,98 @@
+package service
+
+import (
+	"crypto/md5"
+	"encoding/hex"
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"net/url"
+	"strings"
+)
+
+type KdState struct {
+	Message string `json:"message"`
+	State   string `json:"state"`
+	Status  string `json:"status"`
+	IsCheck string `json:"ischeck"`
+}
+
+var KD100Flags = map[string]string{
+	"ane66":          "安能快递",
+	"debangwuliu":    "德邦物流",
+	"debangkuaidi":   "德邦快递",
+	"ems":            "EMS",
+	"guotongkuaidi":  "国通快递",
+	"huitongkuaidi":  "百世快递",
+	"jd":             "京东物流",
+	"kuayue":         "跨越速运",
+	"pjbest":         "品骏快递",
+	"shentong":       "申通快递",
+	"shunfeng":       "顺丰速运",
+	"suer":           "速尔快递",
+	"xinfengwuliu":   "信丰物流",
+	"youshuwuliu":    "优速物流",
+	"youzhengguonei": "邮政快递包裹",
+	"yuantong":       "圆通速递",
+	"yuantongguoji":  "圆通国际",
+	"yunda":          "韵达快递",
+	"zhaijisong":     "宅急送",
+	"zhongtong":      "中通快递",
+	"ewe":            "EWE全球快递",
+	"quanyikuaidi":   "全一快递",
+	"tiantian":       "天天快递",
+	"sxjdfreight":    "顺心捷达",
+	"dhl":            "DHL-中国件",
+	"tnt":            "TNT",
+	"other":          "其它快递",
+}
+
+// GetKDStatus 获取快递跟踪信息
+func GetKDStatus(com, num string) string {
+	fmt.Printf("查询物流公司为 %v, 快递为编号为 %v 的快递\n", KD100Flags[com], num)
+	key := "jqayXRgj8154"                          //客户授权key
+	customer := "E59437A1C1C69273AEB48F587CEF57B4" //查询公司编号
+
+	postUrl := "https://poll.kuaidi100.com/poll/query.do" //实时查询请求地址
+
+	paramData := make(map[string]string)
+	paramData["com"] = com //快递公司编码
+	paramData["num"] = num //快递单号
+
+	paramDataSlice, _ := json.Marshal(paramData)
+	paramjson := string(paramDataSlice)
+
+	sign := strings.ToUpper(GetMD5Encode(paramjson + key + customer))
+
+	//POST请求需要三个参数,分别为customer(CustomerId)和sign(签名)和param(参数)
+	postRes, postErr := http.PostForm(postUrl, url.Values{"customer": {customer}, "sign": {sign}, "param": {paramjson}})
+	if postErr != nil {
+		fmt.Println("查询失败" + postErr.Error())
+		return "查询失败"
+	}
+	postBody, err := ioutil.ReadAll(postRes.Body)
+	if err != nil {
+		fmt.Println("查询失败,请至快递公司官网自行查询" + err.Error())
+		return "查询失败,请至快递公司官网自行查询"
+	}
+	resp := KdState{}
+	err = json.Unmarshal(postBody, &resp)
+	if err != nil {
+		fmt.Println("json.Unmarshal error", err.Error())
+		return "查询失败"
+	}
+	if resp.IsCheck == "1" {
+		fmt.Println("查询成功,快递已签收")
+	} else {
+		fmt.Println("查询成功,快递尚未签收")
+	}
+	return resp.IsCheck
+}
+
+// GetMD5Encode 返回一个32位md5加密后的字符串
+func GetMD5Encode(data string) string {
+	h := md5.New()
+	h.Write([]byte(data))
+	return hex.EncodeToString(h.Sum(nil))
+}