This commit is contained in:
苏尹岚
2020-09-03 15:11:18 +08:00
parent a947dae65a
commit df434b2c1e

View File

@@ -4,26 +4,22 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"math"
"regexp" "regexp"
"strings" "strings"
"time" "time"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin" "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/business/partner/delivery" "git.rosy.net.cn/jx-callback/business/partner/delivery"
"github.com/360EntSecGroup-Skylar/excelize" "github.com/360EntSecGroup-Skylar/excelize"
"github.com/qiniu/api.v7/storage" "github.com/qiniu/api.v7/storage"
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
"git.rosy.net.cn/baseapi/platformapi/jdapi" "git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/baseapi/platformapi/mtwmapi" "git.rosy.net.cn/baseapi/platformapi/mtwmapi"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/baseapi/utils/errlist" "git.rosy.net.cn/baseapi/utils/errlist"
"git.rosy.net.cn/jx-callback/business/jxstore/cms" "git.rosy.net.cn/jx-callback/business/jxstore/cms"
"git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch" "git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model"
@@ -1589,81 +1585,83 @@ func UploadJdsImage(ctx *jxcontext.Context) (err error) {
// fmt.Println("updateList2", utils.Format4Output(updateList, false)) // fmt.Println("updateList2", utils.Format4Output(updateList, false))
// fmt.Println("deleteList2", deleteList) // fmt.Println("deleteList2", deleteList)
// cms.DeletedDuplicateWaitAuditData(ctx, dao.GetDB()) // cms.DeletedDuplicateWaitAuditData(ctx, dao.GetDB())
type tmp struct { // type tmp struct {
JdID string `json:"jdID"` // JdID string `json:"jdID"`
S int `json:"s"` // S int `json:"s"`
} // }
type SpecialtyStoreSkus struct { // type SpecialtyStoreSkus struct {
StoreID int `json:"门店ID"` // StoreID int `json:"门店ID"`
StoreName string `json:"门店名"` // StoreName string `json:"门店名"`
City string `json:"城市"` // City string `json:"城市"`
Area int `json:"面积"` // Area int `json:"面积"`
} // }
var ( // var (
ss []*tmp // ss []*tmp
excelTitle = []string{ // excelTitle = []string{
"门店ID", // "门店ID",
"门店名", // "门店名",
"城市", // "城市",
"面积", // "面积",
} // }
sheetList []*excel.Obj2ExcelSheetConfig // sheetList []*excel.Obj2ExcelSheetConfig
specialtyStoreSkus []*SpecialtyStoreSkus // specialtyStoreSkus []*SpecialtyStoreSkus
downloadURL, fileName string // downloadURL, fileName string
) // )
storeMaps, _ := dao.GetStoresMapList(dao.GetDB(), []int{model.VendorIDJD}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "") // storeMaps, _ := dao.GetStoresMapList(dao.GetDB(), []int{model.VendorIDJD}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "")
for _, v := range storeMaps { // for _, v := range storeMaps {
time.Sleep(time.Second / 3) // time.Sleep(time.Second / 3)
station, err := jd.GetAPI("320406").GetDeliveryRangeByStationNo2(v.VendorStoreID) // station, err := jd.GetAPI("320406").GetDeliveryRangeByStationNo2(v.VendorStoreID)
if err != nil { // if err != nil {
continue // continue
} // }
if station.DeliveryRangeType == 2 { // if station.DeliveryRangeType == 2 {
strs := strings.Split(station.DeliveryRange, ";") // strs := strings.Split(station.DeliveryRange, ";")
ss = append(ss, &tmp{ // ss = append(ss, &tmp{
JdID: v.VendorStoreID, // JdID: v.VendorStoreID,
S: utils.Float64TwoInt(math.Ceil((jxutils.ComputeSignedArea(strs[:len(strs)-1])))), // S: utils.Float64TwoInt(math.Ceil((jxutils.ComputeSignedArea(strs[:len(strs)-1])))),
}) // })
} // }
} // }
for i := 0; i < len(ss)-1; i++ { // for i := 0; i < len(ss)-1; i++ {
for j := 0; j < len(ss)-1-i; j++ { // for j := 0; j < len(ss)-1-i; j++ {
if ss[j].S > ss[j+1].S { // if ss[j].S > ss[j+1].S {
temp := ss[j] // temp := ss[j]
ss[j] = ss[j+1] // ss[j] = ss[j+1]
ss[j+1] = temp // ss[j+1] = temp
} // }
} // }
} // }
for _, v := range ss { // for _, v := range ss {
storeDetail, _ := dao.GetStoreDetailByVendorStoreID(dao.GetDB(), v.JdID, model.VendorIDJD) // storeDetail, _ := dao.GetStoreDetailByVendorStoreID(dao.GetDB(), v.JdID, model.VendorIDJD)
place, _ := dao.GetPlaceByCode(dao.GetDB(), storeDetail.CityCode) // place, _ := dao.GetPlaceByCode(dao.GetDB(), storeDetail.CityCode)
specialtyStoreSku := &SpecialtyStoreSkus{ // specialtyStoreSku := &SpecialtyStoreSkus{
StoreID: storeDetail.ID, // StoreID: storeDetail.ID,
StoreName: storeDetail.Name, // StoreName: storeDetail.Name,
City: place.Name, // City: place.Name,
Area: v.S, // Area: v.S,
} // }
specialtyStoreSkus = append(specialtyStoreSkus, specialtyStoreSku) // specialtyStoreSkus = append(specialtyStoreSkus, specialtyStoreSku)
} // }
excelConf := &excel.Obj2ExcelSheetConfig{ // excelConf := &excel.Obj2ExcelSheetConfig{
Title: "sheet1", // Title: "sheet1",
Data: specialtyStoreSkus, // Data: specialtyStoreSkus,
CaptionList: excelTitle, // CaptionList: excelTitle,
} // }
sheetList = append(sheetList, excelConf) // sheetList = append(sheetList, excelConf)
if excelConf != nil { // if excelConf != nil {
downloadURL, fileName, err = jxutils.UploadExeclAndPushMsg(sheetList, "面积") // downloadURL, fileName, err = jxutils.UploadExeclAndPushMsg(sheetList, "面积")
} else { // } else {
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!") // baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!")
} // }
if err != nil { // if err != nil {
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName, err) // baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName, err)
} else { // } else {
noticeMsg := fmt.Sprintf("[详情点我]%s/billshow/?normal=true&path=%s \n", globals.BackstageHost, downloadURL) // noticeMsg := fmt.Sprintf("[详情点我]%s/billshow/?normal=true&path=%s \n", globals.BackstageHost, downloadURL)
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, ctx.GetUserID(), "异步任务完成", noticeMsg) // ddmsg.SendUserMessage(dingdingapi.MsgTyeText, ctx.GetUserID(), "异步任务完成", noticeMsg)
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess downloadURL: [%v]", downloadURL) // baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess downloadURL: [%v]", downloadURL)
} // }
orderman.RefreshJdShopOrdersEarningPrice(jxcontext.AdminCtx, time.Now().AddDate(0, 0, -3).Format("20060102"), time.Now().Format("20060102"))
return err return err
} }