查找京东商城用户关联的活跃门店
This commit is contained in:
@@ -15,6 +15,8 @@ import (
|
||||
"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"
|
||||
@@ -26,6 +28,7 @@ import (
|
||||
"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"
|
||||
@@ -40,7 +43,24 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
var innerDataPat *regexp.Regexp
|
||||
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:"关联门店"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
innerDataPat = regexp.MustCompile(`"result":(.*),"code":200`)
|
||||
@@ -1446,3 +1466,91 @@ func ExecuteFileName(filename string) (name string) {
|
||||
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)
|
||||
)
|
||||
//获取京东有效的店
|
||||
db := dao.GetDB()
|
||||
storeMapList, err := dao.GetStoreMapsListWithoutDisabled(db, []int{model.VendorIDJD}, model.StoreStatusDisabled)
|
||||
for _, v := range storeMapList {
|
||||
jxVendorIDsMap[v.VendorStoreID] = v.VendorStoreID
|
||||
}
|
||||
//获取京东商城所有用户
|
||||
storeUserList, err := api.JdAPI.PrivilegeSearchUserAll()
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
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] = v
|
||||
}
|
||||
if len(vendorStoreIDsMap) == 0 {
|
||||
jdStruct := JdUserStruct{vv.LoginName, ""}
|
||||
jdUsersStruct.AppendData(jdStruct)
|
||||
} else {
|
||||
for _, m := range vendorStoreIDsMap {
|
||||
vendorStoreIDsResult = append(vendorStoreIDsResult, m)
|
||||
}
|
||||
jdStruct := JdUserStruct{vv.LoginName, strings.Join(vendorStoreIDsResult, ",")}
|
||||
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 1:
|
||||
//写excel
|
||||
WriteToExcel(task, jdUsersStruct.userMap)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
taskSeq := tasksch.NewSeqTask2("获取京东商城用户列表-序列任务", ctx, isContinueWhenError, taskSeqFunc, 2)
|
||||
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
|
||||
}
|
||||
|
||||
@@ -539,7 +539,7 @@ func updateWeiMobGoods(costPrice, salePrice float64, unit string, isCompare bool
|
||||
} else {
|
||||
outPutData := DataSuccess{
|
||||
NameID: goodsDetail.OuterGoodsCode,
|
||||
Name: goodsDetail.Title,
|
||||
Name: newSkuTitle,
|
||||
Unit: unit,
|
||||
OrgPrice: goodsDetail.SkuMap.SingleSku.SalePrice,
|
||||
NowPrice: salePrice,
|
||||
|
||||
@@ -441,3 +441,22 @@ func FreightDeductionPack2Obj(packStr string) (obj *model.FreightDeductionPack)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
func GetStoreMapsListWithoutDisabled(db *DaoDB, vendorIDs []int, status int) (storeMapList []*model.StoreMap, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM store_map
|
||||
WHERE 1=1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND vendor_id in (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
if status != model.StoreStatusAll {
|
||||
sql += " AND status != ?"
|
||||
sqlParams = append(sqlParams, status)
|
||||
}
|
||||
err = GetRows(db, &storeMapList, sql, sqlParams...)
|
||||
return storeMapList, err
|
||||
}
|
||||
|
||||
@@ -367,3 +367,18 @@ func (c *TempOpController) JdStoreInfoCoordinateRecover() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 查找京东用户
|
||||
// @Description 查找京东用户
|
||||
// @Param token header string true "认证token"
|
||||
// @Param isAsync formData bool false "是否异步操作"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetJdUsers [post]
|
||||
func (c *TempOpController) GetJdUsers() {
|
||||
c.callGetJdUsers(func(params *tTempopGetJdUsersParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = tempop.GetJdUsers(params.Ctx, params.IsAsync, params.IsContinueWhenError)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1800,6 +1800,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetJdUsers",
|
||||
Router: `/GetJdUsers`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"],
|
||||
beego.ControllerComments{
|
||||
Method: "JdStoreInfoCoordinateRecover",
|
||||
|
||||
Reference in New Issue
Block a user