Merge remote-tracking branch 'origin/mark' into su
This commit is contained in:
@@ -952,32 +952,36 @@ func ForceUpdateVendorPrice(ctx *jxcontext.Context, vendorID int, actType int, s
|
||||
}
|
||||
storeSkuBind.DeletedAt = utils.DefaultTimeValue
|
||||
if err = dao.GetEntity(db, storeSkuBind, model.FieldStoreID, model.FieldSkuID, model.FieldDeletedAt); err == nil {
|
||||
if v.VendorPrice != 0 {
|
||||
if err2 := checkDiscountValidation(actType, float64(v.ActualActPrice)*100/float64(v.VendorPrice)); err2 != nil {
|
||||
vendorPrice := int(v.VendorPrice)
|
||||
if vendorPrice != 0 {
|
||||
if err2 := checkDiscountValidation(actType, float64(v.ActPrice)*100/float64(v.VendorPrice)); err2 != nil {
|
||||
v.ErrMsg = err2.Error()
|
||||
v.ActualActPrice = v.ActPrice
|
||||
wrongSkuList = append(wrongSkuList, v)
|
||||
storeSkuBind = nil
|
||||
}
|
||||
} else {
|
||||
vendorPrice := dao.GetStoreSkuBindVendorPrice(storeSkuBind, vendorID)
|
||||
if checkDiscountValidation(actType, float64(v.ActualActPrice)*100/float64(vendorPrice)) != nil {
|
||||
vendorPrice = dao.GetStoreSkuBindVendorPrice(storeSkuBind, vendorID)
|
||||
if checkDiscountValidation(actType, float64(v.ActPrice)*100/float64(vendorPrice)) != nil {
|
||||
if actType == model.ActSkuSecKill {
|
||||
vendorPrice = int(v.ActualActPrice)*100/maxDiscount4SkuSecKill + 10
|
||||
vendorPrice = int(v.ActPrice)*100/maxDiscount4SkuSecKill + 10
|
||||
} else if actType == model.ActSkuDirectDown {
|
||||
vendorPrice = int(v.ActualActPrice) + 10
|
||||
vendorPrice = int(v.ActPrice) + 10
|
||||
}
|
||||
dao.SetStoreSkuBindVendorPrice(storeSkuBind, vendorID, vendorPrice)
|
||||
if vendorID != model.VendorIDJX {
|
||||
dao.SetStoreSkuBindSyncStatus(storeSkuBind, vendorID, dao.GetStoreSkuBindSyncStatus(storeSkuBind, vendorID)|model.SyncFlagPriceMask)
|
||||
}
|
||||
storeSkuBind.LastOperator = ctx.GetUserName()
|
||||
} else {
|
||||
storeSkuBind = nil
|
||||
}
|
||||
}
|
||||
if storeSkuBind != nil {
|
||||
dao.SetStoreSkuBindVendorPrice(storeSkuBind, vendorID, vendorPrice)
|
||||
if vendorID != model.VendorIDJX {
|
||||
dao.SetStoreSkuBindSyncStatus(storeSkuBind, vendorID, dao.GetStoreSkuBindSyncStatus(storeSkuBind, vendorID)|model.SyncFlagPriceMask)
|
||||
}
|
||||
storeSkuBind.LastOperator = ctx.GetUserName()
|
||||
storeSkuBindList = append(storeSkuBindList, storeSkuBind)
|
||||
}
|
||||
} else {
|
||||
errList.AddErr(err)
|
||||
errList.AddErr(fmt.Errorf("获取门店:%d商品:%d出错:%s", v.StoreID, v.SkuID, err))
|
||||
}
|
||||
}
|
||||
if err = errList.GetErrListAsOne(); err != nil {
|
||||
|
||||
@@ -192,16 +192,18 @@ func TestSyncAct(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestForceUpdateVendorPrice(t *testing.T) {
|
||||
_, err := ForceUpdateVendorPrice(jxcontext.AdminCtx, model.VendorIDJD, model.ActSkuDirectDown, []*ActStoreSkuParam{
|
||||
hint, err := ForceUpdateVendorPrice(jxcontext.AdminCtx, model.VendorIDJD, model.ActSkuDirectDown, []*ActStoreSkuParam{
|
||||
&ActStoreSkuParam{
|
||||
ActStoreSku: model.ActStoreSku{
|
||||
StoreID: 100118,
|
||||
SkuID: 22509,
|
||||
StoreID: 100118,
|
||||
SkuID: 22509,
|
||||
ActPrice: 9900,
|
||||
},
|
||||
ActualActPrice: 9900,
|
||||
VendorPrice: 19900,
|
||||
},
|
||||
}, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(hint)
|
||||
}
|
||||
|
||||
@@ -1207,9 +1207,7 @@ func TmpGetJxBadCommentsByStoreId(ctx *jxcontext.Context, keyword string, storeI
|
||||
}
|
||||
sql += " ORDER BY t1.createtime DESC"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
var commentList []*JxBadCommentsExt
|
||||
|
||||
@@ -193,7 +193,7 @@ func GetStoreSkus(ctx *jxcontext.Context, storeID int, skuIDs []int, isFocus boo
|
||||
return GetStoresSkus(ctx, []int{storeID}, skuIDs, isFocus, keyword, isBySku, isAct, params, offset, pageSize)
|
||||
}
|
||||
|
||||
func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool, keyword string, isBySku, isAct bool, params map[string]interface{}) (sql string, sqlParams []interface{}, err error) {
|
||||
func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool, keyword string, isBySku, isAct bool, actVendorID int, params map[string]interface{}) (sql string, sqlParams []interface{}, err error) {
|
||||
sql = `
|
||||
FROM sku_name t1
|
||||
JOIN sku t2 FORCE INDEX(PRIMARY) ON t1.id = t2.name_id AND t2.deleted_at = ?/* AND t2.status = ?*/
|
||||
@@ -227,6 +227,10 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool
|
||||
time.Now(),
|
||||
time.Now(),
|
||||
})
|
||||
if actVendorID >= 0 {
|
||||
sql += " AND t1.vendor_mask & ? <> 0"
|
||||
sqlParams = append(sqlParams, model.GetVendorMask(actVendorID))
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND t2.store_id IN (" + dao.GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
@@ -380,8 +384,12 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
|
||||
if len(storeIDs) == 0 && len(skuIDs) == 0 && pageSize == -1 {
|
||||
return nil, fmt.Errorf("GetStoresSkus必须指定storeIDs或skuIDs或分页")
|
||||
}
|
||||
actVendorID := -1
|
||||
if params["actVendorID"] != nil {
|
||||
actVendorID = int(utils.Interface2Int64WithDefault(params["actVendorID"], -1))
|
||||
}
|
||||
db := dao.GetDB()
|
||||
sql, sqlParams, err := getGetStoresSkusBaseSQL(db, storeIDs, skuIDs, isFocus, keyword, isBySku, isAct, params)
|
||||
sql, sqlParams, err := getGetStoresSkusBaseSQL(db, storeIDs, skuIDs, isFocus, keyword, isBySku, isAct, actVendorID, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -499,10 +507,6 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
|
||||
if true { //!(offset == 0 && pageSize == model.UnlimitedPageSize) {
|
||||
storeIDs, skuIDs = GetStoreAndSkuIDsFromInfo(skuNamesInfo)
|
||||
}
|
||||
actVendorID := -1
|
||||
if params["actVendorID"] != nil {
|
||||
actVendorID = int(utils.Interface2Int64WithDefault(params["actVendorID"], -1))
|
||||
}
|
||||
beginTime := time.Now()
|
||||
err = updateActPrice4StoreSkuNameNew(db, storeIDs, skuIDs, skuNamesInfo, actVendorID)
|
||||
globals.SugarLogger.Debugf("GetStoresSkusNew updateActPrice4StoreSkuName:%v", time.Now().Sub(beginTime))
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/dingding"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/authz"
|
||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
@@ -201,7 +202,7 @@ func HandleOrder4Consignee(order *model.GoodsOrder) (err error) {
|
||||
if mobileNumber == "" && order.VendorUserID == "" {
|
||||
return fmt.Errorf("订单:%s手机号与平台用户标识都是空", order.VendorOrderID)
|
||||
}
|
||||
authType := jxutils.GetAuthType4Vendor(order.VendorID)
|
||||
authType := dao.GetAuthType4Vendor(order.VendorID)
|
||||
if authType == "" {
|
||||
msg := fmt.Sprintf("平台ID:%d当前不被支持,请联系开发", order.VendorID)
|
||||
globals.SugarLogger.Warn(msg)
|
||||
@@ -470,7 +471,7 @@ func AddRoles4User(ctx *jxcontext.Context, userID string, rList []*authz.RoleInf
|
||||
if err = api2.RoleMan.AddRole4User(userID, v); err != nil {
|
||||
errList.AddErr(err)
|
||||
} else if v.StoreID > 0 {
|
||||
jxutils.HandleUserWXRemark(dao.GetDB(), userID, true)
|
||||
HandleUserWXRemark(dao.GetDB(), userID, true)
|
||||
}
|
||||
} else {
|
||||
errList.AddErr(err)
|
||||
@@ -485,7 +486,7 @@ func DeleteRoles4User(ctx *jxcontext.Context, userID string, rList []*authz.Role
|
||||
if err = api2.RoleMan.DeleteRole4User(userID, v); err != nil {
|
||||
errList.AddErr(err)
|
||||
} else if v.StoreID > 0 {
|
||||
jxutils.HandleUserWXRemark(dao.GetDB(), userID, true)
|
||||
HandleUserWXRemark(dao.GetDB(), userID, true)
|
||||
}
|
||||
}
|
||||
return errList.GetErrListAsOne()
|
||||
@@ -504,7 +505,7 @@ func AddUsers4Role(ctx *jxcontext.Context, r *authz.RoleInfo, userIDList []strin
|
||||
if err = api2.RoleMan.AddRole4User(v, r); err != nil {
|
||||
errList.AddErr(err)
|
||||
} else if r.StoreID > 0 {
|
||||
jxutils.HandleUserWXRemark(dao.GetDB(), v, true)
|
||||
HandleUserWXRemark(dao.GetDB(), v, true)
|
||||
}
|
||||
}
|
||||
return errList.GetErrListAsOne()
|
||||
@@ -516,7 +517,7 @@ func DeleteUsers4Role(ctx *jxcontext.Context, r *authz.RoleInfo, userIDList []st
|
||||
if err = api2.RoleMan.DeleteRole4User(v, r); err != nil {
|
||||
errList.AddErr(err)
|
||||
} else if r.StoreID > 0 {
|
||||
jxutils.HandleUserWXRemark(dao.GetDB(), v, true)
|
||||
HandleUserWXRemark(dao.GetDB(), v, true)
|
||||
}
|
||||
}
|
||||
return errList.GetErrListAsOne()
|
||||
@@ -713,3 +714,66 @@ func GetSelfInfo(ctx *jxcontext.Context) (user *model.User, err error) {
|
||||
}
|
||||
return user, err
|
||||
}
|
||||
|
||||
func HandleUserWXRemark(db *dao.DaoDB, mobile string, mobileIsUerID bool) (err error) {
|
||||
if db == nil {
|
||||
db = dao.GetDB()
|
||||
}
|
||||
openIDs := []string{}
|
||||
storeID := 0
|
||||
remark := ""
|
||||
|
||||
// if !globals.DisableWXAuth1 {
|
||||
// wxinfo, err := dao.GetUserStoreInfo(db, "tel", mobile)
|
||||
// if err == nil {
|
||||
// openIDs = []string{wxinfo.OpenID}
|
||||
// storeID = wxinfo.JxStoreID
|
||||
// }
|
||||
// }
|
||||
if globals.EnableWXAuth2 {
|
||||
userID := ""
|
||||
if mobileIsUerID {
|
||||
userID = mobile
|
||||
} else {
|
||||
userList, _, err2 := dao.GetUsers(db, model.UserTypeStoreBoss, "", nil, "", mobile, 0, -1)
|
||||
if err = err2; len(userList) > 0 {
|
||||
userID = userList[0].GetID()
|
||||
}
|
||||
}
|
||||
if userID != "" {
|
||||
authBindList, err2 := dao.GetUserBindAuthInfo(db, userID, model.AuthBindTypeAuth, []string{weixin.AuthTypeMP}, "", "")
|
||||
if err = err2; err == nil {
|
||||
for _, v := range authBindList {
|
||||
openIDs = append(openIDs, v.AuthID)
|
||||
}
|
||||
}
|
||||
roleList, err2 := api2.RoleMan.GetUserRoleList(userID)
|
||||
if err = err2; err == nil && len(roleList) > 0 {
|
||||
storeID = roleList[0].StoreID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(openIDs) > 0 {
|
||||
if storeID > 0 {
|
||||
store := &model.Store{}
|
||||
store.ID = storeID
|
||||
if err = dao.GetEntity(db, store); err == nil {
|
||||
city := &model.Place{
|
||||
Code: store.CityCode,
|
||||
}
|
||||
if err = dao.GetEntity(db, city, "Code"); err == nil {
|
||||
remark = city.Name + "-" + store.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
if globals.EnableStoreWrite {
|
||||
for _, openID := range openIDs {
|
||||
err = api.WeixinAPI.CBUpdateRemark(openID, remark)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/act"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
@@ -122,6 +123,9 @@ func Init() {
|
||||
}, updateActStatusTimeList)
|
||||
ScheduleScoreStore()
|
||||
ScheduleCheckStoreAlert()
|
||||
ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() {
|
||||
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, 0, true, true)
|
||||
}, ChangeStoreSkuSaleStatusList)
|
||||
}
|
||||
ScheduleTimerFunc("AutoSaleStoreSku", func() {
|
||||
cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false)
|
||||
@@ -134,11 +138,6 @@ func Init() {
|
||||
"04:05:06",
|
||||
})
|
||||
}
|
||||
if beego.BConfig.RunMode == "alpha" {
|
||||
ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() {
|
||||
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, 0, true, true)
|
||||
}, ChangeStoreSkuSaleStatusList)
|
||||
}
|
||||
}
|
||||
|
||||
func doDailyWork() {
|
||||
@@ -157,6 +156,10 @@ func doDailyWork() {
|
||||
SaveImportantTaskID(TaskNameSyncStoreSku, taskID)
|
||||
|
||||
InitEx()
|
||||
|
||||
// 每天补全前一天与当天的订单
|
||||
curDate := utils.Time2Date(time.Now())
|
||||
orderman.FixedOrderManager.AmendMissingOrders(jxcontext.AdminCtx, nil, 0, curDate.Add(-24*time.Hour), curDate, true, true)
|
||||
}
|
||||
|
||||
func RefreshRealMobile(ctx *jxcontext.Context, vendorID int, fromTime, toTime time.Time, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -49,6 +50,7 @@ var (
|
||||
titleList = []string{
|
||||
"用户名",
|
||||
"关联门店",
|
||||
"状态",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -60,6 +62,7 @@ type GetJdUsersStruct struct {
|
||||
type JdUserStruct struct {
|
||||
UserName string `json:"用户名"`
|
||||
StoreIDs string `json:"关联门店"`
|
||||
Status string `json:"状态"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -954,7 +957,7 @@ func UpdateAllWeiXinRemark(ctx *jxcontext.Context, isAsync, isContinueWhenError
|
||||
rootTask := tasksch.NewParallelTask("刷新微信备注", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
tel := batchItemList[0].(string)
|
||||
err = jxutils.HandleUserWXRemark(dao.GetDB(), tel, false)
|
||||
err = cms.HandleUserWXRemark(dao.GetDB(), tel, false)
|
||||
return nil, err
|
||||
}, mobileList)
|
||||
tasksch.ManageTask(rootTask).Run()
|
||||
@@ -1470,18 +1473,32 @@ func ExecuteFileName(filename string) (name string) {
|
||||
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] = v.VendorStoreID
|
||||
jxVendorIDsMap[v.VendorStoreID] = utils.Int64ToStr(int64(v.StoreID))
|
||||
}
|
||||
//获取京东商城所有用户
|
||||
storeUserList, err := api.JdAPI.PrivilegeSearchUserAll()
|
||||
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)
|
||||
@@ -1491,30 +1508,35 @@ func GetJdUsers(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint
|
||||
if jxVendorIDsMap[v] == "" {
|
||||
continue
|
||||
}
|
||||
vendorStoreIDsMap[v] = v
|
||||
vendorStoreIDsMap[v] = jxVendorIDsMap[v]
|
||||
}
|
||||
if len(vendorStoreIDsMap) == 0 {
|
||||
jdStruct := JdUserStruct{vv.LoginName, ""}
|
||||
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)
|
||||
}
|
||||
jdStruct := JdUserStruct{vv.LoginName, strings.Join(vendorStoreIDsResult, ",")}
|
||||
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)
|
||||
taskParallel := tasksch.NewParallelTask("获取京东商城用户关联门店列表", tasksch.NewParallelConfig(), ctx, taskFunc, storeUserList)
|
||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||
_, err = taskParallel.GetResult(0)
|
||||
case 1:
|
||||
case 2:
|
||||
//写excel
|
||||
WriteToExcel(task, jdUsersStruct.userMap)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
taskSeq := tasksch.NewSeqTask2("获取京东商城用户列表-序列任务", ctx, isContinueWhenError, taskSeqFunc, 2)
|
||||
taskSeq := tasksch.NewSeqTask2("获取京东商城用户关联门店列表-序列任务", ctx, isContinueWhenError, taskSeqFunc, 3)
|
||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = taskSeq.GetResult(0)
|
||||
|
||||
@@ -133,7 +133,7 @@ var (
|
||||
SkuRow: 1,
|
||||
}, "净配": &SheetParam{
|
||||
SkuIDCol: 0,
|
||||
SkuPriceCol: 12,
|
||||
SkuPriceCol: 14,
|
||||
SkuNameCol: 1,
|
||||
OrgSkuIdCol: 4,
|
||||
OrgSkuPriceCol: 7,
|
||||
@@ -237,14 +237,15 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i
|
||||
func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
skuMap = make(map[string]*ExcelParam)
|
||||
errMsg string
|
||||
costPrice float64 //成本价
|
||||
goodsList []*weimobapi.GoodsInfo
|
||||
goodsIDListForPutAway []interface{}
|
||||
isCompare bool
|
||||
isExecute = false
|
||||
)
|
||||
db := dao.GetDB()
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
var errMsg string
|
||||
switch step {
|
||||
case 0:
|
||||
//读取excel文件
|
||||
@@ -256,22 +257,20 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
||||
sheetParam := sheetMap[k]
|
||||
rows, _ := xlsx.GetRows(k)
|
||||
for rowNum, row := range rows {
|
||||
if rowNum < sheetParam.SkuRow {
|
||||
continue
|
||||
}
|
||||
GetCellIntoMap(sheetParam, skuMap, row, k, rowNum)
|
||||
if len(skuMap) < 1 {
|
||||
errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]\n", k)
|
||||
}
|
||||
}
|
||||
if errMsg != "" {
|
||||
return "", errors.New(errMsg)
|
||||
errMsg += GetCellIntoMap(sheetParam, skuMap, row, k, rowNum)
|
||||
}
|
||||
}
|
||||
//修改分组名
|
||||
// 分类名格式为:可定XX日
|
||||
// XX为上传永辉 提供的 价格表时间 +2天
|
||||
isCompare, err = UpdateClassifyAndGetLastClassify()
|
||||
if errMsg == "" {
|
||||
isExecute = true
|
||||
} else {
|
||||
return "", fmt.Errorf(errMsg)
|
||||
}
|
||||
if isExecute {
|
||||
isCompare, err = UpdateClassifyAndGetLastClassify()
|
||||
}
|
||||
case 1:
|
||||
//获取微盟所有商品
|
||||
param := &weimobapi.QueryGoodsListParam{
|
||||
@@ -305,7 +304,6 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
||||
Comment: "在微盟上未找到该商品",
|
||||
}
|
||||
dataFailed.AppendData2(outPutData)
|
||||
// errMsg += fmt.Sprintf("在微盟上未找到该商品xxx", xxx)
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
@@ -326,7 +324,6 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
||||
Comment: "在京西库中未找到该商品",
|
||||
}
|
||||
dataFailed.AppendData2(outPutData)
|
||||
// return "", errors.New(fmt.Sprintf("在京西库中未找到该商品!name_id : [%v]\n", goodsDetail.SkuMap.SingleSku.OuterSkuCode))
|
||||
} else {
|
||||
if skuList[0].Unit == "份" {
|
||||
if goodsDetail.SkuMap.SingleSku.B2CSku.Weight == 0 {
|
||||
@@ -337,7 +334,9 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
||||
} else {
|
||||
costPrice = skuMap[spuCode].Price
|
||||
}
|
||||
_, _, _ = updateWeiMobGoods(costPrice, skuMap[spuCode].Price, skuList[0].Unit, isCompare, goodsDetail)
|
||||
if isExecute {
|
||||
_, _, _ = updateWeiMobGoods(costPrice, skuMap[spuCode].Price, skuList[0].Unit, isCompare, goodsDetail)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//下架微盟商品
|
||||
@@ -360,7 +359,9 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
||||
for _, v := range batchItemList {
|
||||
int64Slice = append(int64Slice, v.(int64))
|
||||
}
|
||||
PutAwayWeiMobSku(int64Slice)
|
||||
if isExecute {
|
||||
PutAwayWeiMobSku(int64Slice)
|
||||
}
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel4 := tasksch.NewParallelTask("下架微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetBatchSize(UpdateGoodsShelfStatusCount), ctx, taskFunc4, goodsIDListForPutAway)
|
||||
@@ -369,9 +370,7 @@ func LoadExcelBinByYongHui(ctx *jxcontext.Context, reader io.Reader, isAsync, is
|
||||
case 4:
|
||||
WriteToExcel(task, dataSuccess.dataSuccessList, dataFailed.dataFailedList)
|
||||
}
|
||||
// if errMsg != "" {
|
||||
// return result, errors.New(errMsg)
|
||||
// }
|
||||
|
||||
return result, err
|
||||
}
|
||||
taskSeq := tasksch.NewSeqTask2("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, isContinueWhenError, taskSeqFunc, 5)
|
||||
@@ -403,17 +402,6 @@ func GetGoodsInfoAndDetailMap(goodsList []*weimobapi.GoodsInfo) (goodsMap map[st
|
||||
return goodsMap
|
||||
}
|
||||
|
||||
// func getSelectedClassifyLeafList(l []weimobapi.SelectedClassifyList) (list []int64) {
|
||||
// for _, v := range l {
|
||||
// if v.ChildrenClassify == nil {
|
||||
// list = append(list, v.ClassifyID)
|
||||
// } else {
|
||||
// subList := getSelectedClassifyLeafList(v.ChildrenClassify)
|
||||
// }
|
||||
// }
|
||||
// return list
|
||||
// }
|
||||
|
||||
func updateWeiMobGoods(costPrice, salePrice float64, unit string, isCompare bool, goodsDetail *weimobapi.GoodsDetailInfo) (goodsID int64, skuMap map[string]int64, err error) {
|
||||
var (
|
||||
categoryList []*weimobapi.CategoryList
|
||||
@@ -579,7 +567,7 @@ func IsChineseChar(str string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row []string, sheetName string, rowNum int) {
|
||||
func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row []string, sheetName string, rowNum int) (errMsg string) {
|
||||
var (
|
||||
skuID string
|
||||
orgSkuID string
|
||||
@@ -596,19 +584,27 @@ func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row [
|
||||
)
|
||||
for k, cell := range row {
|
||||
if cell != "" {
|
||||
if !IsChineseChar(cell) {
|
||||
if k == skuIDCol && skuIDCol >= 0 {
|
||||
skuID = cell
|
||||
if k == skuIDCol && skuIDCol >= 0 {
|
||||
skuID = cell
|
||||
}
|
||||
if k == skuPriceCol && skuPriceCol >= 0 {
|
||||
if rowNum == sheetParam.SkuRow-1 {
|
||||
if !strings.Contains(cell, "今日供价") && !strings.Contains(cell, "单价") {
|
||||
errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]列今日供价附近可能增加或减少了一列,请确认!", sheetName, k+1)
|
||||
}
|
||||
}
|
||||
if k == skuPriceCol && skuPriceCol >= 0 {
|
||||
skuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0))
|
||||
}
|
||||
if k == orgSkuIDCol && orgSkuIDCol >= 0 {
|
||||
orgSkuID = "0" + cell
|
||||
}
|
||||
if k == orgSkuPriceCol && orgSkuPriceCol >= 0 {
|
||||
orgSkuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0))
|
||||
skuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0))
|
||||
}
|
||||
if k == orgSkuIDCol && orgSkuIDCol >= 0 {
|
||||
orgSkuID = "0" + cell
|
||||
}
|
||||
if k == orgSkuPriceCol && orgSkuPriceCol >= 0 {
|
||||
if rowNum == sheetParam.SkuRow-1 {
|
||||
if !strings.Contains(cell, "进价") {
|
||||
errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]列进价附近可能增加或减少了一列,请确认!", sheetName, k+1)
|
||||
}
|
||||
}
|
||||
orgSkuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0))
|
||||
}
|
||||
if k == skuNameCol && skuNameCol >= 0 {
|
||||
skuName = cell
|
||||
@@ -618,34 +614,50 @@ func GetCellIntoMap(sheetParam *SheetParam, skuMap map[string]*ExcelParam, row [
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(skuMap) > 0 {
|
||||
if skuMap[skuID] != nil {
|
||||
if skuMap[skuID].Price != 0 && skuMap[skuID].Price != skuPrice && skuPrice != 0 {
|
||||
if skuPrice > skuMap[skuID].Price {
|
||||
if rowNum >= sheetParam.SkuRow {
|
||||
if rowNum == sheetParam.SkuRow {
|
||||
if IsChineseChar(skuID) {
|
||||
if IsChineseChar(skuID) {
|
||||
errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]行附近可能增加了一行,请确认!", sheetName, rowNum)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(skuMap) > 0 {
|
||||
if skuMap[skuID] != nil {
|
||||
if skuMap[skuID].Price != 0 && skuMap[skuID].Price != skuPrice && skuPrice != 0 {
|
||||
if skuPrice > skuMap[skuID].Price {
|
||||
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||
}
|
||||
} else {
|
||||
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||
}
|
||||
} else {
|
||||
} else if skuPrice != 0 {
|
||||
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||
}
|
||||
} else if skuPrice != 0 {
|
||||
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||
}
|
||||
if skuMap[orgSkuID] != nil {
|
||||
if skuMap[orgSkuID].Price != 0 && skuMap[orgSkuID].Price != orgSkuPrice && orgSkuPrice != 0 {
|
||||
if orgSkuPrice > skuMap[orgSkuID].Price {
|
||||
if skuMap[orgSkuID] != nil {
|
||||
if skuMap[orgSkuID].Price != 0 && skuMap[orgSkuID].Price != orgSkuPrice && orgSkuPrice != 0 {
|
||||
if orgSkuPrice > skuMap[orgSkuID].Price {
|
||||
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||
}
|
||||
} else if orgSkuPriceCol >= 0 && orgSkuIDCol >= 0 && orgSkuNameCol >= 0 {
|
||||
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||
}
|
||||
} else if orgSkuPriceCol >= 0 && orgSkuIDCol >= 0 && orgSkuNameCol >= 0 {
|
||||
} else if orgSkuPrice != 0 {
|
||||
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||
}
|
||||
} else if orgSkuPrice != 0 {
|
||||
} else {
|
||||
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||
}
|
||||
delete(skuMap, "")
|
||||
} else {
|
||||
BuildSkuMap(skuID, skuName, skuPrice, skuMap)
|
||||
BuildSkuMap(orgSkuID, orgSkuName, orgSkuPrice, skuMap)
|
||||
for i := rowNum; i < sheetParam.SkuRow; i++ {
|
||||
if !IsChineseChar(skuID) {
|
||||
errMsg += fmt.Sprintf("sheet页:[%v],Excel排版发生变化!第[%v]行附近可能减少了一行,请确认!", sheetName, rowNum)
|
||||
}
|
||||
}
|
||||
}
|
||||
delete(skuMap, "")
|
||||
return errMsg
|
||||
}
|
||||
func BuildSkuMap(id, name string, price float64, skuMap map[string]*ExcelParam) {
|
||||
excelParam := &ExcelParam{
|
||||
@@ -753,7 +765,7 @@ func WriteToExcel(task *tasksch.SeqTask, dataSuccess []DataSuccess, dataFailed [
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName1, fileName2, err)
|
||||
} else {
|
||||
noticeMsg := fmt.Sprintf("[详情点我]path1=%s, path2=%s \n", globals.BackstageHost, downloadURL1, downloadURL2)
|
||||
noticeMsg := fmt.Sprintf("[详情点我]path1=%s, path2=%s \n", downloadURL1, downloadURL2)
|
||||
task.SetNoticeMsg(noticeMsg)
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s ,%s success, downloadURL1:%s ,downloadURL2:%s", fileName1, fileName2, downloadURL1, downloadURL2)
|
||||
}
|
||||
@@ -909,7 +921,7 @@ func WriteToExcel3(task *tasksch.SeqTask, dataSuccess []DataStoreSkusSuccess, da
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName1, fileName2, err)
|
||||
} else {
|
||||
noticeMsg := fmt.Sprintf("[详情点我]path1=%s, path2=%s \n", globals.BackstageHost, downloadURL1, downloadURL2)
|
||||
noticeMsg := fmt.Sprintf("[详情点我]path1=%s, path2=%s \n", downloadURL1, downloadURL2)
|
||||
task.SetNoticeMsg(noticeMsg)
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s ,%s success, downloadURL1:%s ,downloadURL2:%s", fileName1, fileName2, downloadURL1, downloadURL2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user