Merge remote-tracking branch 'origin/mark' into su
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user