Merge remote-tracking branch 'origin/mark' into su
This commit is contained in:
@@ -22,8 +22,10 @@ import (
|
||||
const (
|
||||
DefActSkuStock = 200 // 缺省活动库存
|
||||
|
||||
maxDiscount4SkuSecKill = 80
|
||||
minDiscount4SkuDirectDown = 0
|
||||
maxDiscount4SkuSecKill = 80
|
||||
maxDiscount4Sku = 98
|
||||
minDiscount4SkuDirectDown = 0
|
||||
minDiscount4SkuDirectDownMTWM = 30
|
||||
)
|
||||
|
||||
type ActOrderRuleParam struct {
|
||||
@@ -179,7 +181,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac
|
||||
if actSkuMap.ActualActPrice <= 0 {
|
||||
actSkuMap.ActualActPrice = 1
|
||||
}
|
||||
if err2 = checkDiscountValidation(act.Type, float64(actSkuMap.ActualActPrice)*100/float64(actSkuMap.VendorPrice)); err2 != nil {
|
||||
if err2 = checkDiscountValidation(vendorIDs, act.Type, float64(actSkuMap.ActualActPrice)*100/float64(actSkuMap.VendorPrice)); err2 != nil {
|
||||
v.ErrMsg = err2.Error()
|
||||
v.ActualActPrice = actSkuMap.ActualActPrice
|
||||
v.VendorPrice = actSkuMap.VendorPrice
|
||||
@@ -303,14 +305,16 @@ func AddActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
|
||||
return err
|
||||
}
|
||||
|
||||
func checkDiscountValidation(actType int, pricePercentage float64) (err error) {
|
||||
func checkDiscountValidation(vendorIDs []int, actType int, pricePercentage float64) (err error) {
|
||||
pricePercentageMin := int(math.Floor(pricePercentage))
|
||||
pricePercentageMax := int(math.Ceil(pricePercentage))
|
||||
if actType == model.ActSkuDirectDown && (pricePercentageMin < minDiscount4SkuDirectDown || pricePercentageMax > 99) {
|
||||
if pricePercentageMin < minDiscount4SkuDirectDown {
|
||||
err = fmt.Errorf("%s活动折扣必须大于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDown)
|
||||
} else if pricePercentageMax > 99 {
|
||||
err = fmt.Errorf("%s活动必须有折扣", model.ActTypeName[actType])
|
||||
} else if pricePercentageMax > maxDiscount4Sku {
|
||||
err = fmt.Errorf("%s活动必须至少有%d折扣", model.ActTypeName[actType], maxDiscount4Sku)
|
||||
} else if len(vendorIDs) > 0 && vendorIDs[0] == model.VendorIDMTWM && pricePercentageMin < minDiscount4SkuDirectDownMTWM {
|
||||
err = fmt.Errorf("美团平台%s活动折扣必须大于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDownMTWM)
|
||||
}
|
||||
} else if actType == model.ActSkuSecKill && pricePercentageMax > maxDiscount4SkuSecKill {
|
||||
err = fmt.Errorf("%s活动折扣必须小于:%d", model.ActTypeName[actType], maxDiscount4SkuSecKill)
|
||||
@@ -333,7 +337,7 @@ func checkActValidation(act *model.Act, vendorIDs []int) (err error) {
|
||||
if act.Type == model.ActSkuDirectDown || act.Type == model.ActSkuSecKill {
|
||||
if act.PricePercentage == 0 {
|
||||
errList.AddErr(fmt.Errorf("必须指定缺省活动折扣"))
|
||||
} else if err = checkDiscountValidation(act.Type, float64(act.PricePercentage)); err != nil {
|
||||
} else if err = checkDiscountValidation(vendorIDs, act.Type, float64(act.PricePercentage)); err != nil {
|
||||
errList.AddErr(err)
|
||||
} else if act.Type == model.ActSkuSecKill && vendorIDMap[model.VendorIDMTWM] == 1 {
|
||||
errList.AddErr(fmt.Errorf("%s平台不支持%s活动", model.VendorChineseNames[model.VendorIDMTWM], model.ActTypeName[model.ActSkuSecKill]))
|
||||
@@ -668,7 +672,7 @@ func DeleteActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, act
|
||||
originSyncStatus |= act.SyncStatus
|
||||
isDeleteAll := true
|
||||
isDeleteAtLeastOne := false
|
||||
if actStoreSkuParam != nil {
|
||||
if true { //actStoreSkuParam != nil {
|
||||
actStoreSkuMap := partner.SplitActStoreSku(actStoreSkuMap[vendorID])
|
||||
for storeID := range actStoreSkuMap {
|
||||
for _, actStoreSku := range actStoreSkuMap[storeID] {
|
||||
@@ -954,7 +958,7 @@ func ForceUpdateVendorPrice(ctx *jxcontext.Context, vendorID int, actType int, s
|
||||
if err = dao.GetEntity(db, storeSkuBind, model.FieldStoreID, model.FieldSkuID, model.FieldDeletedAt); err == nil {
|
||||
vendorPrice := int(v.VendorPrice)
|
||||
if vendorPrice != 0 {
|
||||
if err2 := checkDiscountValidation(actType, float64(v.ActPrice)*100/float64(v.VendorPrice)); err2 != nil {
|
||||
if err2 := checkDiscountValidation([]int{vendorID}, actType, float64(v.ActPrice)*100/float64(v.VendorPrice)); err2 != nil {
|
||||
v.ErrMsg = err2.Error()
|
||||
v.ActualActPrice = v.ActPrice
|
||||
wrongSkuList = append(wrongSkuList, v)
|
||||
@@ -962,7 +966,7 @@ func ForceUpdateVendorPrice(ctx *jxcontext.Context, vendorID int, actType int, s
|
||||
}
|
||||
} else {
|
||||
vendorPrice = dao.GetStoreSkuBindVendorPrice(storeSkuBind, vendorID)
|
||||
if checkDiscountValidation(actType, float64(v.ActPrice)*100/float64(vendorPrice)) != nil {
|
||||
if checkDiscountValidation([]int{vendorID}, actType, float64(v.ActPrice)*100/float64(vendorPrice)) != nil {
|
||||
if actType == model.ActSkuSecKill {
|
||||
vendorPrice = int(v.ActPrice)*100/maxDiscount4SkuSecKill + 10
|
||||
} else if actType == model.ActSkuDirectDown {
|
||||
|
||||
@@ -362,13 +362,6 @@ func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint s
|
||||
ReCalculateJxPrice(ctx, storeIDs)
|
||||
}
|
||||
}
|
||||
// for _, v := range storeMapList {
|
||||
// if _, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, &model.StoreSkuBind{}, nil, ctx.GetUserName(), map[string]interface{}{
|
||||
// model.FieldStoreID: v.StoreID,
|
||||
// }, dao.GetSyncStatusStructField(model.VendorNames[v.VendorID]), model.SyncFlagPriceMask); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// }
|
||||
case model.ConfigTypeFreightPack:
|
||||
dao.Commit(db)
|
||||
storeMapList, err := dao.GetStoresMapList(db, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
@@ -116,8 +117,9 @@ func UpdateCategory(ctx *jxcontext.Context, categoryID int, payload map[string]i
|
||||
if valid["name"] != nil {
|
||||
valid["name"] = strings.Trim(valid["name"].(string), " ")
|
||||
syncStatus = model.SyncFlagModifiedMask
|
||||
valid[model.FieldJdSyncStatus] = int8(syncStatus) | cat.JdSyncStatus
|
||||
}
|
||||
if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, cat, valid, userName, nil, model.FieldJdSyncStatus, syncStatus); err == nil {
|
||||
if num, err = dao.UpdateEntityLogically(db, cat, valid, userName, nil); err == nil {
|
||||
SetStoreCategorySyncStatus2(db, nil, []int{categoryID}, model.SyncFlagModifiedMask)
|
||||
var skuIDs []int
|
||||
if valid["jdCategoryID"] != nil || valid["ebaiCategoryID"] != nil || valid["mtwmCategoryID"] != nil ||
|
||||
@@ -208,8 +210,8 @@ func ReorderCategories(ctx *jxcontext.Context, parentID int, categoryIDs []int,
|
||||
}
|
||||
for k, v := range categoryIDs {
|
||||
catsMap[v].Seq = k
|
||||
catsMap[v].JdSyncStatus |= model.SyncFlagModifiedMask
|
||||
if _, err = dao.UpdateEntity(db, catsMap[v], "Seq"); err != nil {
|
||||
catsMap[v].LastOperator = ctx.GetUserName()
|
||||
if _, err = dao.UpdateEntity(db, catsMap[v]); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -725,7 +727,8 @@ func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interf
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, skuName, valid, userName, nil, model.FieldJdSyncStatus, model.SyncFlagModifiedMask); err == nil {
|
||||
valid[model.FieldJdSyncStatus] = model.SyncFlagModifiedMask | skuName.JdSyncStatus
|
||||
if num, err = dao.UpdateEntityLogically(db, skuName, valid, userName, nil); err == nil {
|
||||
if utils.Interface2Int64WithDefault(payload["isGlobal"], 0) == 0 && payload["places"] != nil {
|
||||
if places, ok := payload["places"].([]interface{}); ok {
|
||||
if _, err = dao.DeleteSkuNamePlace(db, nameID, nil); err == nil {
|
||||
@@ -745,10 +748,16 @@ func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interf
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
sku := &model.Sku{}
|
||||
_, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, sku, nil, userName, map[string]interface{}{
|
||||
model.FieldNameID: nameID,
|
||||
}, model.FieldJdSyncStatus, model.SyncFlagModifiedMask)
|
||||
skuList, err2 := dao.GetSkus(db, nil, []int{nameID}, nil, nil)
|
||||
if err = err2; err == nil {
|
||||
for _, v := range skuList {
|
||||
sku := &v.Sku
|
||||
sku.JdSyncStatus |= model.SyncFlagModifiedMask
|
||||
sku.LastOperator = userName
|
||||
sku.UpdatedAt = time.Now()
|
||||
dao.UpdateEntity(db, sku)
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
skuIDs, err2 := dao.GetSkuIDByNames(db, []int{nameID})
|
||||
if err = err2; err == nil && len(skuIDs) > 0 {
|
||||
@@ -873,11 +882,12 @@ func UpdateSku(ctx *jxcontext.Context, skuID int, payload map[string]interface{}
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
maskValue := model.SyncFlagModifiedMask
|
||||
maskValue := int8(model.SyncFlagModifiedMask)
|
||||
if valid["specQuality"] != nil || valid["specUnit"] != nil {
|
||||
maskValue |= model.SyncFlagSpecMask
|
||||
}
|
||||
if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, sku, valid, userName, nil, model.FieldJdSyncStatus, maskValue); err == nil {
|
||||
valid[model.FieldJdSyncStatus] = maskValue | sku.JdSyncStatus
|
||||
if num, err = dao.UpdateEntityLogically(db, sku, valid, userName, nil); err == nil {
|
||||
if num == 1 {
|
||||
if num, err = dao.ExecuteSQL(db, `
|
||||
UPDATE sku_name t1
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"mime/multipart"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
|
||||
@@ -2182,3 +2188,84 @@ func GetStoreListByLocation(ctx *jxcontext.Context, lng, lat float64, needWalkDi
|
||||
}
|
||||
return storeList, err
|
||||
}
|
||||
|
||||
func JdStoreInfoCoordinateRecover(ctx *jxcontext.Context, files []*multipart.FileHeader) (err error) {
|
||||
if len(files) == 0 {
|
||||
return errors.New("没有文件上传!")
|
||||
}
|
||||
fileHeader := files[0]
|
||||
file1, err := fileHeader.Open()
|
||||
defer file1.Close()
|
||||
|
||||
db := dao.GetDB()
|
||||
storeList, err := dao.GetStoresMapList(db, []int{model.VendorIDJD}, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
|
||||
if err == nil {
|
||||
var validStoreList []*dao.StoreDetail
|
||||
for _, v := range storeList {
|
||||
if v.Status != model.StoreStatusDisabled && v.CreatedAt.Sub(utils.Str2Time("2019-10-01")) > 0 {
|
||||
storeInfo, err := api.JdAPI.GetStoreInfoByStationNo2(v.VendorStoreID)
|
||||
if err == nil && storeInfo.CreateTime.GoTime().Sub(utils.Str2Time("2019-10-25")) > 0 {
|
||||
if storeDetail, err := dao.GetStoreDetail(db, v.StoreID, v.VendorID); err == nil {
|
||||
validStoreList = append(validStoreList, storeDetail)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
getStoreList := func(lng, lat, lng2, lat2 int) (vendorStoreIDs []string) {
|
||||
for _, v := range validStoreList {
|
||||
if v.Lng >= lng && v.Lng <= lng2 && v.Lat >= lat && v.Lat <= lat2 {
|
||||
vendorStoreIDs = append(vendorStoreIDs, v.VendorStoreID)
|
||||
}
|
||||
}
|
||||
return vendorStoreIDs
|
||||
}
|
||||
sheetName := "老格明细"
|
||||
file, err2 := excelize.OpenReader(file1)
|
||||
if err = err2; err == nil {
|
||||
rows, err2 := file.GetRows(sheetName)
|
||||
if err = err2; err == nil {
|
||||
str2Coords := func(str string) (lng, lat int) {
|
||||
list := strings.Split(str, ",")
|
||||
if len(list) >= 2 {
|
||||
lng, lat = jxutils.StandardCoordinate2Int(utils.Str2Float64WithDefault(list[1], 0)), jxutils.StandardCoordinate2Int(utils.Str2Float64WithDefault(list[0], 0))
|
||||
}
|
||||
return lng, lat
|
||||
}
|
||||
for i := 1; i < len(rows); i++ {
|
||||
lng, lat := str2Coords(rows[i][8])
|
||||
lng2, lat2 := str2Coords(rows[i][7])
|
||||
vendorStoreIDs := getStoreList(lng, lat, lng2, lat2)
|
||||
countInfo := fmt.Sprintf("京西已拓%d", len(vendorStoreIDs))
|
||||
axis, _ := excelize.CoordinatesToCellName(5, i+1)
|
||||
file.SetCellStr(sheetName, axis, countInfo)
|
||||
axis2, _ := excelize.CoordinatesToCellName(6, i+1)
|
||||
file.SetCellStr(sheetName, axis2, strings.Join(vendorStoreIDs, ","))
|
||||
}
|
||||
filename := ExecuteFileName(fileHeader.Filename)
|
||||
buf := bytes.NewBuffer(nil)
|
||||
if _, err = io.Copy(buf, file1); err != nil {
|
||||
return err
|
||||
}
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:save %s success", filename)
|
||||
downloadURL, err := jxutils.UploadExportContent(buf.Bytes(), filename)
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s, failed error:%v", filename, err)
|
||||
} else {
|
||||
if authInfo, err := ctx.GetV2AuthInfo(); err == nil {
|
||||
noticeMsg := fmt.Sprintf("path=%s\n", downloadURL)
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "导出老格恢复拓店进度成功", noticeMsg)
|
||||
}
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL:%s", filename, downloadURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func ExecuteFileName(filename string) (name string) {
|
||||
filePrefix := filename[strings.LastIndex(filename, "."):len(filename)]
|
||||
fileRealName := filename[0:strings.LastIndex(filename, ".")]
|
||||
name = fileRealName + utils.Int64ToStr(time.Now().Unix()) + filePrefix
|
||||
return name
|
||||
}
|
||||
|
||||
@@ -92,11 +92,10 @@ type StoreSkuNameExt struct {
|
||||
StoreName string `json:"storeName"`
|
||||
|
||||
model.SkuName
|
||||
PayPercentage int `json:"-"`
|
||||
UnitPrice int `json:"unitPrice"`
|
||||
Skus []map[string]interface{} `orm:"-" json:"skus2,omitempty"`
|
||||
Skus2 []*StoreSkuExt `orm:"-" json:"skus,omitempty"`
|
||||
SkusStr string `json:"-"`
|
||||
PayPercentage int `json:"-"`
|
||||
UnitPrice int `json:"unitPrice"`
|
||||
Skus []*StoreSkuExt `orm:"-" json:"skus,omitempty"`
|
||||
SkusStr string `json:"-"`
|
||||
|
||||
PendingOpType int8 `json:"pendingOpType"` // 取值同 StoreOpRequest.Type
|
||||
PendingUnitPrice int `json:"pendingUnitPrice"` // 这个是待审核的价格申请
|
||||
@@ -178,7 +177,7 @@ const (
|
||||
maxStoreNameBind = 3000 // 最大门店SkuName bind个数
|
||||
maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数
|
||||
|
||||
AutoSaleAtStr = "20:25:00"
|
||||
AutoSaleAtStr = "22:00:00"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -495,7 +494,7 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
|
||||
} else {
|
||||
storeName = storeNameMap[index]
|
||||
}
|
||||
storeName.Skus2 = append(storeName.Skus2, &v.StoreSkuExt)
|
||||
storeName.Skus = append(storeName.Skus, &v.StoreSkuExt)
|
||||
}
|
||||
if err == nil {
|
||||
if isSaleInfo {
|
||||
@@ -524,7 +523,7 @@ func GetStoreAndSkuIDsFromInfo(skuNamesInfo *StoreSkuNamesInfo) (storeIDs, skuID
|
||||
skuIDMap := make(map[int]int)
|
||||
for _, skuName := range skuNamesInfo.SkuNames {
|
||||
storeIDMap[skuName.StoreID] = 1
|
||||
for _, sku := range skuName.Skus2 {
|
||||
for _, sku := range skuName.Skus {
|
||||
skuIDMap[sku.SkuID] = 1
|
||||
}
|
||||
}
|
||||
@@ -572,8 +571,8 @@ func updateActPrice4StoreSkuNameNew(db *dao.DaoDB, storeIDs, skuIDs []int, skuNa
|
||||
actStoreSkuMap4EarningPrice := jxutils.NewActStoreSkuMap(actStoreSkuList, false)
|
||||
|
||||
for _, skuName := range skuNamesInfo.SkuNames {
|
||||
if len(skuName.Skus2) > 0 {
|
||||
for _, v := range skuName.Skus2 {
|
||||
if len(skuName.Skus) > 0 {
|
||||
for _, v := range skuName.Skus {
|
||||
if actStoreSku := actStoreSkuMap4Act.GetActStoreSku(skuName.StoreID, v.SkuID, -1); actStoreSku != nil {
|
||||
v.ActPrice = int(actStoreSku.ActualActPrice)
|
||||
v.ActID = actStoreSku.ActID
|
||||
@@ -628,7 +627,7 @@ func updateSaleInfo4StoreSkuName(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
var newSkuNames []*StoreSkuNameExt
|
||||
for _, skuName := range skuNamesInfo.SkuNames {
|
||||
var newSkus []*StoreSkuExt
|
||||
for _, sku := range skuName.Skus2 {
|
||||
for _, sku := range skuName.Skus {
|
||||
saleInfo := saleInfoMap[jxutils.Combine2Int(skuName.StoreID, sku.SkuID)]
|
||||
if saleInfo == nil && fromCount == 0 {
|
||||
saleInfo = &SkuSaleInfo{}
|
||||
@@ -640,7 +639,7 @@ func updateSaleInfo4StoreSkuName(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
}
|
||||
}
|
||||
if len(newSkus) > 0 {
|
||||
skuName.Skus2 = newSkus
|
||||
skuName.Skus = newSkus
|
||||
newSkuNames = append(newSkuNames, skuName)
|
||||
}
|
||||
}
|
||||
@@ -2121,3 +2120,15 @@ func ReCalculateJxPrice(ctx *jxcontext.Context, storeIDs []int) (err error) {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func GetTopSkusByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuAndName []*model.SkuAndName, err error) {
|
||||
if len(storeIDs) == 0 {
|
||||
return skuAndName, err
|
||||
}
|
||||
db := dao.GetDB()
|
||||
skuAndName, err = dao.GetTopSkusByStoreIDs(db, storeIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return skuAndName, err
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ func GetMultiStoreAllSkuInfo(ctx *jxcontext.Context, vendorMap map[int]bool) {
|
||||
func GetFilterJxSkuInfoMap(jxSkuInfoList []*StoreSkuNameExt) map[int]*StoreSkuNameExt {
|
||||
filterJxSkuInfoMap := make(map[int]*StoreSkuNameExt)
|
||||
for _, value := range jxSkuInfoList {
|
||||
for _, skuInfo := range value.Skus2 {
|
||||
for _, skuInfo := range value.Skus {
|
||||
filterJxSkuInfoMap[skuInfo.SkuID] = value
|
||||
}
|
||||
}
|
||||
@@ -329,24 +329,24 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin
|
||||
//多规格商品不用比较数量单位
|
||||
if jxSkuInfo.IsSpu == 0 {
|
||||
//jxSkuDetailName : 前缀 ([荐]) + 分类名(xxx水饺) + 数量单位(约..g/份) + 注释 (补充..)
|
||||
jxSkuDetailName = jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, jxSkuInfo.Skus2[0].Comment, jxSkuInfo.SkuName.Unit, jxSkuInfo.Skus2[0].SkuSpecQuality, jxSkuInfo.Skus2[0].SkuSpecUnit, 0)
|
||||
jxSkuDetailName = jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, jxSkuInfo.Skus[0].Comment, jxSkuInfo.SkuName.Unit, jxSkuInfo.Skus[0].SkuSpecQuality, jxSkuInfo.Skus[0].SkuSpecUnit, 0)
|
||||
} else {
|
||||
//jxSkuDetailName : 前缀 ([荐]) + 分类名(xxx水饺) + 数量单位(约..g/份) + 注释 (补充..)
|
||||
jxSkuDetailName = jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, jxSkuInfo.Skus2[0].Comment, "", jxSkuInfo.Skus2[0].SkuSpecQuality, "", 0)
|
||||
jxSkuDetailName = jxutils.ComposeSkuName(jxSkuInfo.SkuName.Prefix, jxSkuInfo.SkuName.Name, jxSkuInfo.Skus[0].Comment, "", jxSkuInfo.Skus[0].SkuSpecQuality, "", 0)
|
||||
}
|
||||
|
||||
//jxSkuSaleStatus : 商品状态 ,skustatus 优先级高于 StoreSkuStatus
|
||||
jxSkuSaleStatus := jxutils.MergeSkuStatus(jxSkuInfo.Skus2[0].SkuStatus, jxSkuInfo.Skus2[0].StoreSkuStatus)
|
||||
jxSkuSaleStatus := jxutils.MergeSkuStatus(jxSkuInfo.Skus[0].SkuStatus, jxSkuInfo.Skus[0].StoreSkuStatus)
|
||||
jxSkuSaleStatusName := GetSkuSaleStatusName(jxSkuSaleStatus)
|
||||
|
||||
vendorSkuInfo := filterVendorSkuInfoMap[skuID]
|
||||
var status int8
|
||||
if vendorID == model.VendorIDMTWM {
|
||||
status = jxSkuInfo.Skus2[0].MtwmSyncStatus
|
||||
status = jxSkuInfo.Skus[0].MtwmSyncStatus
|
||||
} else if vendorID == model.VendorIDEBAI {
|
||||
status = jxSkuInfo.Skus2[0].EbaiSyncStatus
|
||||
status = jxSkuInfo.Skus[0].EbaiSyncStatus
|
||||
} else if vendorID == model.VendorIDJD {
|
||||
status = jxSkuInfo.Skus2[0].JdSyncStatus
|
||||
status = jxSkuInfo.Skus[0].JdSyncStatus
|
||||
}
|
||||
syncStatus := utils.Int2Str(int(status))
|
||||
toBeCreate := GetBoolName(model.IsSyncStatusNeedCreate(status))
|
||||
|
||||
@@ -673,7 +673,7 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v
|
||||
if opType == AmendPruneOnlyAmend || opType == AmendPruneAll {
|
||||
for _, v := range localSkuList {
|
||||
if !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) && v.BindID != 0 {
|
||||
syncStatus := 0
|
||||
syncStatus := int8(0)
|
||||
if remoteSkuMap[v.VendorSkuID] == 0 {
|
||||
if !model.IsSyncStatusNew(v.StoreSkuSyncStatus) {
|
||||
syncStatus = model.SyncFlagNewMask
|
||||
@@ -684,7 +684,10 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v
|
||||
if syncStatus != 0 {
|
||||
skuBind := &model.StoreSkuBind{}
|
||||
skuBind.ID = v.BindID
|
||||
dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, skuBind, nil, ctx.GetUserName(), nil, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), syncStatus)
|
||||
skuBind.LastOperator = ctx.GetUserName()
|
||||
skuBind.UpdatedAt = time.Now()
|
||||
dao.SetStoreSkuBindSyncStatus(skuBind, vendorID, syncStatus|v.StoreSkuSyncStatus)
|
||||
dao.UpdateEntity(db, skuBind, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), model.FieldLastOperator, model.FieldUpdatedAt)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -720,7 +723,7 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v
|
||||
|
||||
for _, v := range localCatList {
|
||||
if !model.IsSyncStatusDelete(v.StoreCatSyncStatus) && v.MapID != 0 {
|
||||
syncStatus := 0
|
||||
syncStatus := int8(0)
|
||||
if remoteCatMap[v.VendorCatID] == 0 {
|
||||
if !model.IsSyncStatusNew(v.StoreCatSyncStatus) {
|
||||
syncStatus = model.SyncFlagNewMask
|
||||
@@ -731,7 +734,10 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v
|
||||
if syncStatus != 0 {
|
||||
catBind := &model.StoreSkuCategoryMap{}
|
||||
catBind.ID = v.MapID
|
||||
dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, catBind, nil, ctx.GetUserName(), nil, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), syncStatus)
|
||||
catBind.LastOperator = ctx.GetUserName()
|
||||
catBind.UpdatedAt = time.Now()
|
||||
dao.SetStoreCatMapSyncStatus(catBind, vendorID, syncStatus|v.StoreCatSyncStatus)
|
||||
dao.UpdateEntity(db, catBind, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), model.FieldLastOperator, model.FieldUpdatedAt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,16 @@ package cms
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
@@ -36,8 +44,27 @@ var (
|
||||
auth2.UserIDMobile: "mobile",
|
||||
auth2.UserIDEmail: "email",
|
||||
}
|
||||
jdUsersStruct GetJdUsersStruct
|
||||
titleListJdUser = []string{
|
||||
"用户名",
|
||||
"关联门店",
|
||||
"所属角色",
|
||||
"状态",
|
||||
}
|
||||
)
|
||||
|
||||
type GetJdUsersStruct struct {
|
||||
locker sync.RWMutex
|
||||
userMap []JdUserStruct
|
||||
}
|
||||
|
||||
type JdUserStruct struct {
|
||||
UserName string `json:"用户名"`
|
||||
StoreIDs string `json:"关联门店"`
|
||||
RoleName string `json:"所属角色"`
|
||||
Status string `json:"状态"`
|
||||
}
|
||||
|
||||
type UserProvider struct {
|
||||
}
|
||||
|
||||
@@ -777,3 +804,128 @@ func HandleUserWXRemark(db *dao.DaoDB, mobile string, mobileIsUerID bool) (err e
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func GetJdUsers(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
jxVendorIDsMap = make(map[string]string)
|
||||
pageNoList []int
|
||||
storeUserList []interface{}
|
||||
disabledIdList []interface{}
|
||||
)
|
||||
db := dao.GetDB()
|
||||
jdUsersStruct.userMap = jdUsersStruct.userMap[0:0]
|
||||
//获取京东商城所有用户
|
||||
_, _, toatlPage, _ := api.JdAPI.PrivilegeSearchUser(1)
|
||||
for i := 1; i <= toatlPage; i++ {
|
||||
pageNoList = append(pageNoList, i)
|
||||
}
|
||||
storeMapList, err := dao.GetStoreMapsListWithoutDisabled(db, []int{model.VendorIDJD}, model.StoreStatusDisabled)
|
||||
for _, v := range storeMapList {
|
||||
jxVendorIDsMap[v.VendorStoreID] = utils.Int64ToStr(int64(v.StoreID))
|
||||
}
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
taskFunc1 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
pageNo := batchItemList[0].(int)
|
||||
storeUserLists, _, _, err := api.JdAPI.PrivilegeSearchUser(pageNo)
|
||||
retVal = storeUserLists
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel1 := tasksch.NewParallelTask("获取京东商城所有用户列表", tasksch.NewParallelConfig(), ctx, taskFunc1, pageNoList)
|
||||
tasksch.HandleTask(taskParallel1, task, true).Run()
|
||||
storeUserList, err = taskParallel1.GetResult(0)
|
||||
case 1:
|
||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vv := batchItemList[0].(*jdapi.StoreUserInfo)
|
||||
vendorStoreIDs, err := api.JdAPI.GetJdUserBindStoreIDs(vv.ID)
|
||||
var vendorStoreIDsMap = make(map[string]string, len(vendorStoreIDs))
|
||||
var vendorStoreIDsResult []string
|
||||
var roleNameStr string
|
||||
for _, v := range vendorStoreIDs {
|
||||
if jxVendorIDsMap[v] == "" {
|
||||
continue
|
||||
}
|
||||
vendorStoreIDsMap[v] = jxVendorIDsMap[v]
|
||||
}
|
||||
if vv.RoleNameStr != "" {
|
||||
roleNameStr = strings.ReplaceAll(vv.RoleNameStr, " ", "")
|
||||
if roleNameStr != jdapi.JdUserRoleJHYName && roleNameStr != jdapi.JdUserRolesName && roleNameStr != jdapi.JdUserNoRole {
|
||||
api.JdAPI.UpdateJdUserRoles(int64(vv.ID), []string{jdapi.JdUserRoleJHYId})
|
||||
}
|
||||
}
|
||||
if len(vendorStoreIDsMap) == 0 {
|
||||
isManager, _ := api.JdAPI.IsJdManagerUser(int64(vv.ID))
|
||||
if isManager {
|
||||
jdStruct := JdUserStruct{vv.LoginName, "商家管理员", vv.RoleNameStr, vv.LockStatus}
|
||||
jdUsersStruct.AppendData(jdStruct)
|
||||
} else {
|
||||
retVal = []int64{int64(vv.ID)}
|
||||
}
|
||||
} else {
|
||||
for _, m := range vendorStoreIDsMap {
|
||||
vendorStoreIDsResult = append(vendorStoreIDsResult, m)
|
||||
}
|
||||
sort.Strings(vendorStoreIDsResult[:])
|
||||
jdStruct := JdUserStruct{vv.LoginName, strings.Join(vendorStoreIDsResult, ","), vv.RoleNameStr, vv.LockStatus}
|
||||
jdUsersStruct.AppendData(jdStruct)
|
||||
}
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel := tasksch.NewParallelTask("获取京东商城用户关联门店列表", tasksch.NewParallelConfig(), ctx, taskFunc, storeUserList)
|
||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||
disabledIdList, err = taskParallel.GetResult(0)
|
||||
case 2:
|
||||
taskFunc2 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
id := batchItemList[0].(int64)
|
||||
api.JdAPI.PrivilegeUpdateJdUserStatus(id, jdapi.JdUserStatusDisable)
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel2 := tasksch.NewParallelTask("禁用未关联活跃门店用户", tasksch.NewParallelConfig(), ctx, taskFunc2, disabledIdList)
|
||||
tasksch.HandleTask(taskParallel2, task, true).Run()
|
||||
_, err = taskParallel2.GetResult(0)
|
||||
case 3:
|
||||
WriteToExcelJd(task, jdUsersStruct.userMap)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
taskSeq := tasksch.NewSeqTask2("获取京东商城用户关联门店列表-序列任务", ctx, isContinueWhenError, taskSeqFunc, 4)
|
||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = taskSeq.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = taskSeq.GetID()
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func (d *GetJdUsersStruct) AppendData(jd JdUserStruct) {
|
||||
d.locker.RLock()
|
||||
defer d.locker.RUnlock()
|
||||
d.userMap = append(d.userMap, jd)
|
||||
}
|
||||
|
||||
func WriteToExcelJd(task *tasksch.SeqTask, jd []JdUserStruct) (err error) {
|
||||
var sheetList []*excel.Obj2ExcelSheetConfig
|
||||
var downloadURL, fileName string
|
||||
excelConf := &excel.Obj2ExcelSheetConfig{
|
||||
Title: "京东用户列表",
|
||||
Data: jd,
|
||||
CaptionList: titleListJdUser,
|
||||
}
|
||||
sheetList = append(sheetList, excelConf)
|
||||
if excelConf != nil {
|
||||
downloadURL, fileName, err = jxutils.UploadExeclAndPushMsg(sheetList, "京东用户列表")
|
||||
} else {
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: JdUserStruct is nil!")
|
||||
}
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s,failed error:%v", fileName, err)
|
||||
} else {
|
||||
noticeMsg := fmt.Sprintf("[详情点我]path=%s, \n", downloadURL)
|
||||
task.SetNoticeMsg(noticeMsg)
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s, success, downloadURL:%s", fileName, downloadURL)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/tempop"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/act"
|
||||
@@ -165,7 +163,7 @@ func doDailyWork() {
|
||||
//订单门店归属补漏
|
||||
//fromDate, toDate都不传默认刷新当前天5天以前的订单,只传fromDate默认刷新fromDate到当天的订单
|
||||
//只传toDate默认刷新toDate到5天以前的订单
|
||||
tempop.RefreshOrdersWithoutJxStoreID(jxcontext.AdminCtx, "", "", true, true)
|
||||
orderman.RefreshOrdersWithoutJxStoreID(jxcontext.AdminCtx, "", "", true, true)
|
||||
}
|
||||
|
||||
func RefreshRealMobile(ctx *jxcontext.Context, vendorID int, fromTime, toTime time.Time, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
|
||||
@@ -223,7 +223,7 @@ func GetAllStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeList
|
||||
if jxSkuInfoData, err2 := cms.GetStoreSkus(ctx, storeID, []int{}, true, "", true, false, map[string]interface{}{}, 0, -1); jxSkuInfoData != nil {
|
||||
jxSkuPriceMapData := make(map[int]int)
|
||||
for _, value := range jxSkuInfoData.SkuNames {
|
||||
for _, skuInfo := range value.Skus2 {
|
||||
for _, skuInfo := range value.Skus {
|
||||
saleStatus := jxutils.MergeSkuStatus(skuInfo.SkuStatus, skuInfo.StoreSkuStatus)
|
||||
if saleStatus == model.SkuStatusNormal {
|
||||
jxSkuPriceMapData[skuInfo.SkuID] = skuInfo.BindPrice
|
||||
|
||||
@@ -78,7 +78,7 @@ func GetStoreSkuSalesInfo(ctx *jxcontext.Context, storeID int) (outStoreSkuSales
|
||||
storeSkuData, err := cms.GetStoreSkus(ctx, storeID, citySkuIDs, true, "", true, false, map[string]interface{}{}, 0, -1)
|
||||
if err == nil {
|
||||
for _, value := range storeSkuData.SkuNames {
|
||||
for _, skuInfo := range value.Skus2 {
|
||||
for _, skuInfo := range value.Skus {
|
||||
storeSkuMapData[skuInfo.SkuID] = value
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func GetStoreSkuSalesInfo(ctx *jxcontext.Context, storeID int) (outStoreSkuSales
|
||||
jxSkuInfoData, err := cms.GetStoreSkus(ctx, storeID, citySkuIDs, true, "", true, false, map[string]interface{}{}, 0, -1)
|
||||
jxSkuPriceMapData := make(map[int]int)
|
||||
for _, value := range jxSkuInfoData.SkuNames {
|
||||
for _, skuInfo := range value.Skus2 {
|
||||
for _, skuInfo := range value.Skus {
|
||||
jxSkuPriceMapData[skuInfo.SkuID] = skuInfo.BindPrice
|
||||
}
|
||||
}
|
||||
@@ -148,10 +148,10 @@ func GetStoreSkuSalesInfo(ctx *jxcontext.Context, storeID int) (outStoreSkuSales
|
||||
skuAndNameInfo := skuAndNameMapData[skuID]
|
||||
if storeSkuInfo != nil {
|
||||
skuName := storeSkuInfo.SkuName
|
||||
skuInfo := storeSkuInfo.Skus2[0]
|
||||
skuInfo := storeSkuInfo.Skus[0]
|
||||
storeSkuSales.SkuName = jxutils.ComposeSkuName(skuName.Prefix, skuName.Name, skuInfo.Comment, skuName.Unit, skuInfo.SkuSpecQuality, skuInfo.SkuSpecUnit, 0)
|
||||
storeSkuSales.SkuImage = storeSkuInfo.Img
|
||||
storeSkuSales.SkuPrice = jxutils.IntPrice2StandardCurrencyString(int64(storeSkuInfo.Skus2[0].BindPrice))
|
||||
storeSkuSales.SkuPrice = jxutils.IntPrice2StandardCurrencyString(int64(storeSkuInfo.Skus[0].BindPrice))
|
||||
} else if skuAndNameInfo != nil {
|
||||
skuNameList, err := dao.GetSkuNames(db, []int{skuAndNameInfo.NameID})
|
||||
prefix := ""
|
||||
|
||||
@@ -2,36 +2,26 @@ package tempop
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/delivery"
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/yonghui"
|
||||
"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/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
@@ -44,26 +34,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
var (
|
||||
innerDataPat *regexp.Regexp
|
||||
jdUsersStruct GetJdUsersStruct
|
||||
titleList = []string{
|
||||
"用户名",
|
||||
"关联门店",
|
||||
"状态",
|
||||
}
|
||||
)
|
||||
|
||||
type GetJdUsersStruct struct {
|
||||
locker sync.RWMutex
|
||||
userMap []JdUserStruct
|
||||
}
|
||||
|
||||
type JdUserStruct struct {
|
||||
UserName string `json:"用户名"`
|
||||
StoreIDs string `json:"关联门店"`
|
||||
Status string `json:"状态"`
|
||||
}
|
||||
var innerDataPat *regexp.Regexp
|
||||
|
||||
func init() {
|
||||
innerDataPat = regexp.MustCompile(`"result":(.*),"code":200`)
|
||||
@@ -1388,218 +1359,3 @@ func JdStoreInfo1125() (hint string, err error) {
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func JdStoreInfoCoordinateRecover(ctx *jxcontext.Context, files []*multipart.FileHeader) (err error) {
|
||||
if len(files) == 0 {
|
||||
return errors.New("没有文件上传!")
|
||||
}
|
||||
fileHeader := files[0]
|
||||
file1, err := fileHeader.Open()
|
||||
defer file1.Close()
|
||||
|
||||
db := dao.GetDB()
|
||||
storeList, err := dao.GetStoresMapList(db, []int{model.VendorIDJD}, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
|
||||
if err == nil {
|
||||
var validStoreList []*dao.StoreDetail
|
||||
for _, v := range storeList {
|
||||
if v.Status != model.StoreStatusDisabled && v.CreatedAt.Sub(utils.Str2Time("2019-10-01")) > 0 {
|
||||
storeInfo, err := api.JdAPI.GetStoreInfoByStationNo2(v.VendorStoreID)
|
||||
if err == nil && storeInfo.CreateTime.GoTime().Sub(utils.Str2Time("2019-10-25")) > 0 {
|
||||
if storeDetail, err := dao.GetStoreDetail(db, v.StoreID, v.VendorID); err == nil {
|
||||
validStoreList = append(validStoreList, storeDetail)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
getStoreList := func(lng, lat, lng2, lat2 int) (vendorStoreIDs []string) {
|
||||
for _, v := range validStoreList {
|
||||
if v.Lng >= lng && v.Lng <= lng2 && v.Lat >= lat && v.Lat <= lat2 {
|
||||
vendorStoreIDs = append(vendorStoreIDs, v.VendorStoreID)
|
||||
}
|
||||
}
|
||||
return vendorStoreIDs
|
||||
}
|
||||
sheetName := "老格明细"
|
||||
file, err2 := excelize.OpenReader(file1)
|
||||
if err = err2; err == nil {
|
||||
rows, err2 := file.GetRows(sheetName)
|
||||
if err = err2; err == nil {
|
||||
str2Coords := func(str string) (lng, lat int) {
|
||||
list := strings.Split(str, ",")
|
||||
if len(list) >= 2 {
|
||||
lng, lat = jxutils.StandardCoordinate2Int(utils.Str2Float64WithDefault(list[1], 0)), jxutils.StandardCoordinate2Int(utils.Str2Float64WithDefault(list[0], 0))
|
||||
}
|
||||
return lng, lat
|
||||
}
|
||||
for i := 1; i < len(rows); i++ {
|
||||
lng, lat := str2Coords(rows[i][8])
|
||||
lng2, lat2 := str2Coords(rows[i][7])
|
||||
vendorStoreIDs := getStoreList(lng, lat, lng2, lat2)
|
||||
countInfo := fmt.Sprintf("京西已拓%d", len(vendorStoreIDs))
|
||||
axis, _ := excelize.CoordinatesToCellName(5, i+1)
|
||||
file.SetCellStr(sheetName, axis, countInfo)
|
||||
axis2, _ := excelize.CoordinatesToCellName(6, i+1)
|
||||
file.SetCellStr(sheetName, axis2, strings.Join(vendorStoreIDs, ","))
|
||||
}
|
||||
filename := ExecuteFileName(fileHeader.Filename)
|
||||
buf := bytes.NewBuffer(nil)
|
||||
if _, err = io.Copy(buf, file1); err != nil {
|
||||
return err
|
||||
}
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:save %s success", filename)
|
||||
downloadURL, err := jxutils.UploadExportContent(buf.Bytes(), filename)
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s, failed error:%v", filename, err)
|
||||
} else {
|
||||
if authInfo, err := ctx.GetV2AuthInfo(); err == nil {
|
||||
noticeMsg := fmt.Sprintf("path=%s\n", downloadURL)
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "导出老格恢复拓店进度成功", noticeMsg)
|
||||
}
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL:%s", filename, downloadURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func ExecuteFileName(filename string) (name string) {
|
||||
filePrefix := filename[strings.LastIndex(filename, "."):len(filename)]
|
||||
fileRealName := filename[0:strings.LastIndex(filename, ".")]
|
||||
name = fileRealName + utils.Int64ToStr(time.Now().Unix()) + filePrefix
|
||||
return name
|
||||
}
|
||||
|
||||
func GetJdUsers(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
jxVendorIDsMap = make(map[string]string)
|
||||
pageNoList []int
|
||||
storeUserList []interface{}
|
||||
)
|
||||
db := dao.GetDB()
|
||||
//获取京东商城所有用户
|
||||
_, _, toatlPage, _ := api.JdAPI.PrivilegeSearchUser(1)
|
||||
for i := 1; i <= toatlPage; i++ {
|
||||
pageNoList = append(pageNoList, i)
|
||||
}
|
||||
storeMapList, err := dao.GetStoreMapsListWithoutDisabled(db, []int{model.VendorIDJD}, model.StoreStatusDisabled)
|
||||
for _, v := range storeMapList {
|
||||
jxVendorIDsMap[v.VendorStoreID] = utils.Int64ToStr(int64(v.StoreID))
|
||||
}
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
taskFunc1 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
pageNo := batchItemList[0].(int)
|
||||
storeUserLists, _, _, err := api.JdAPI.PrivilegeSearchUser(pageNo)
|
||||
retVal = storeUserLists
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel1 := tasksch.NewParallelTask("获取京东商城所有用户列表", tasksch.NewParallelConfig(), ctx, taskFunc1, pageNoList)
|
||||
tasksch.HandleTask(taskParallel1, task, true).Run()
|
||||
storeUserList, err = taskParallel1.GetResult(0)
|
||||
case 1:
|
||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vv := batchItemList[0].(*jdapi.StoreUserInfo)
|
||||
vendorStoreIDs, err := api.JdAPI.GetJdUserBindStoreIDs(vv.ID)
|
||||
var vendorStoreIDsMap = make(map[string]string, len(vendorStoreIDs))
|
||||
var vendorStoreIDsResult []string
|
||||
for _, v := range vendorStoreIDs {
|
||||
if jxVendorIDsMap[v] == "" {
|
||||
continue
|
||||
}
|
||||
vendorStoreIDsMap[v] = jxVendorIDsMap[v]
|
||||
}
|
||||
if len(vendorStoreIDsMap) == 0 {
|
||||
if vv.LoginName == "jd_jxcs1223" || vv.LoginName == "jd_jxgy" {
|
||||
jdStruct := JdUserStruct{vv.LoginName, "管理员", vv.LockStatus}
|
||||
jdUsersStruct.AppendData(jdStruct)
|
||||
}
|
||||
jdStruct := JdUserStruct{vv.LoginName, "", vv.LockStatus}
|
||||
jdUsersStruct.AppendData(jdStruct)
|
||||
} else {
|
||||
for _, m := range vendorStoreIDsMap {
|
||||
vendorStoreIDsResult = append(vendorStoreIDsResult, m)
|
||||
}
|
||||
sort.Strings(vendorStoreIDsResult[:])
|
||||
jdStruct := JdUserStruct{vv.LoginName, strings.Join(vendorStoreIDsResult, ","), vv.LockStatus}
|
||||
jdUsersStruct.AppendData(jdStruct)
|
||||
}
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel := tasksch.NewParallelTask("获取京东商城用户关联门店列表", tasksch.NewParallelConfig(), ctx, taskFunc, storeUserList)
|
||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||
_, err = taskParallel.GetResult(0)
|
||||
case 2:
|
||||
//写excel
|
||||
WriteToExcel(task, jdUsersStruct.userMap)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
taskSeq := tasksch.NewSeqTask2("获取京东商城用户关联门店列表-序列任务", ctx, isContinueWhenError, taskSeqFunc, 3)
|
||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = taskSeq.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = taskSeq.GetID()
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func (d *GetJdUsersStruct) AppendData(jd JdUserStruct) {
|
||||
d.locker.RLock()
|
||||
defer d.locker.RUnlock()
|
||||
d.userMap = append(d.userMap, jd)
|
||||
}
|
||||
|
||||
func WriteToExcel(task *tasksch.SeqTask, jd []JdUserStruct) (err error) {
|
||||
var sheetList []*excel.Obj2ExcelSheetConfig
|
||||
var downloadURL, fileName string
|
||||
excelConf := &excel.Obj2ExcelSheetConfig{
|
||||
Title: "京东用户列表",
|
||||
Data: jd,
|
||||
CaptionList: titleList,
|
||||
}
|
||||
sheetList = append(sheetList, excelConf)
|
||||
if excelConf != nil {
|
||||
downloadURL, fileName, err = yonghui.UploadExeclAndPushMsg(sheetList, "京东用户列表")
|
||||
} else {
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: JdUserStruct is nil!")
|
||||
}
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s,failed error:%v", fileName, err)
|
||||
} else {
|
||||
noticeMsg := fmt.Sprintf("[详情点我]path=%s, \n", downloadURL)
|
||||
task.SetNoticeMsg(noticeMsg)
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s, success, downloadURL:%s", fileName, downloadURL)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func RefreshOrdersWithoutJxStoreID(ctx *jxcontext.Context, fromDate, toDate string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
fromDateParam time.Time
|
||||
toDateParam time.Time
|
||||
)
|
||||
if fromDate != "" {
|
||||
fromDateParam = utils.Str2Time(fromDate)
|
||||
}
|
||||
if toDate != "" {
|
||||
toDateParam = utils.Str2Time(toDate)
|
||||
}
|
||||
db := dao.GetDB()
|
||||
task := tasksch.NewParallelTask("订单门店归属补漏", tasksch.NewParallelConfig().SetParallelCount(1), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
_, err = dao.UpdateOrdersWithoutJxStoreID(db, fromDateParam, toDateParam)
|
||||
return retVal, err
|
||||
}, []int{0})
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = task.GetID()
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
@@ -200,7 +200,6 @@ var (
|
||||
const (
|
||||
parallelCount = 5
|
||||
UpdateGoodsShelfStatusCount = 50 //微盟下架商品api限制一次50个
|
||||
fileExt = ".xlsx"
|
||||
)
|
||||
|
||||
func (d *DataSuccessLock) AppendData(dataSuccess DataSuccess) {
|
||||
@@ -753,12 +752,12 @@ func WriteToExcel(task *tasksch.SeqTask, dataSuccess []DataSuccess, dataFailed [
|
||||
}
|
||||
sheetList2 = append(sheetList2, excelConf2)
|
||||
if excelConf1 != nil {
|
||||
downloadURL1, fileName1, err = UploadExeclAndPushMsg(sheetList1, "微盟已更新商品")
|
||||
downloadURL1, fileName1, err = jxutils.UploadExeclAndPushMsg(sheetList1, "微盟已更新商品")
|
||||
} else {
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!")
|
||||
}
|
||||
if excelConf2 != nil {
|
||||
downloadURL2, fileName2, err = UploadExeclAndPushMsg(sheetList2, "缺少商品_微盟")
|
||||
downloadURL2, fileName2, err = jxutils.UploadExeclAndPushMsg(sheetList2, "缺少商品_微盟")
|
||||
} else {
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: dataFailed is nil!")
|
||||
}
|
||||
@@ -772,15 +771,6 @@ func WriteToExcel(task *tasksch.SeqTask, dataSuccess []DataSuccess, dataFailed [
|
||||
return err
|
||||
}
|
||||
|
||||
func UploadExeclAndPushMsg(sheetList []*excel.Obj2ExcelSheetConfig, name string) (downloadURL, fileName string, err error) {
|
||||
excelBin := excel.Obj2Excel(sheetList)
|
||||
timeStr := utils.Int64ToStr(time.Now().Unix())
|
||||
fileName = name + timeStr + fileExt
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:save %s success", fileName)
|
||||
downloadURL, err = jxutils.UploadExportContent(excelBin, fileName)
|
||||
return downloadURL, fileName, err
|
||||
}
|
||||
|
||||
func UpdateJxPriceByWeimob(ctx *jxcontext.Context, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
storeSkuBindInfoList []interface{}
|
||||
@@ -909,12 +899,12 @@ func WriteToExcel3(task *tasksch.SeqTask, dataSuccess []DataStoreSkusSuccess, da
|
||||
}
|
||||
sheetList2 = append(sheetList2, excelConf2)
|
||||
if excelConf1 != nil {
|
||||
downloadURL1, fileName1, err = UploadExeclAndPushMsg(sheetList1, "京西已更新商品")
|
||||
downloadURL1, fileName1, err = jxutils.UploadExeclAndPushMsg(sheetList1, "京西已更新商品")
|
||||
} else {
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!")
|
||||
}
|
||||
if excelConf2 != nil {
|
||||
downloadURL2, fileName2, err = UploadExeclAndPushMsg(sheetList2, "缺少商品_京西")
|
||||
downloadURL2, fileName2, err = jxutils.UploadExeclAndPushMsg(sheetList2, "缺少商品_京西")
|
||||
} else {
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: dataFailed is nil!")
|
||||
}
|
||||
@@ -1105,13 +1095,13 @@ func WriteToExcel2(ctx *jxcontext.Context, DataFineList, DataHairyList []*Data)
|
||||
sheetList2 = append(sheetList2, excelConf2)
|
||||
noticeMsg += "[详情点我]"
|
||||
if len(DataFineList) > 0 {
|
||||
downloadURL1, fileName1, err = UploadExeclAndPushMsg(sheetList1, "京西采购_精品")
|
||||
downloadURL1, fileName1, err = jxutils.UploadExeclAndPushMsg(sheetList1, "京西采购_精品")
|
||||
noticeMsg += "path1=" + downloadURL1 + " "
|
||||
} else {
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: DataFineList is nil!")
|
||||
}
|
||||
if len(DataHairyList) > 0 {
|
||||
downloadURL2, fileName2, err = UploadExeclAndPushMsg(sheetList2, "京西采购_毛菜")
|
||||
downloadURL2, fileName2, err = jxutils.UploadExeclAndPushMsg(sheetList2, "京西采购_毛菜")
|
||||
noticeMsg += "path2=" + downloadURL2
|
||||
} else {
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: DataHairyList is nil!")
|
||||
|
||||
Reference in New Issue
Block a user