Merge remote-tracking branch 'origin/mark' into su
This commit is contained in:
@@ -96,7 +96,7 @@ var (
|
||||
}
|
||||
authTypeGuesserMap = map[string]*regexp.Regexp{
|
||||
AuthTypeEmail: regexp.MustCompile(`^[A-Za-z0-9_\-\.]+\@[A-Za-z0-9_\-]+(\.[A-Za-z]+){1,5}$`),
|
||||
AuthTypeMobile: regexp.MustCompile(`^1[345789]\d{9}$`),
|
||||
AuthTypeMobile: regexp.MustCompile(`^1[3456789]\d{9}$`),
|
||||
}
|
||||
|
||||
// 永久全局的TOKEN,内部使用
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
package auth
|
||||
|
||||
// const (
|
||||
// DefTokenDuration = 7 * 24 * time.Hour // 7天
|
||||
// )
|
||||
|
||||
// type IAuther interface {
|
||||
// Login(id, secret string) (userID, loginType string, err error)
|
||||
// Logout(loginInfo *LoginInfo) error
|
||||
// }
|
||||
|
||||
// var (
|
||||
// authers map[string]IAuther
|
||||
// )
|
||||
|
||||
// var (
|
||||
// ErrUserNotExist = errors.New("用户不存在,请联系运营创建")
|
||||
// ErrLoginTypeNotSupported = errors.New("不支持指定的登录类型")
|
||||
// ErrUIDAndPassNotMatch = errors.New("用户与密码不匹配")
|
||||
// ErrAPINeedRealLogin = errors.New("此API要求真正登录")
|
||||
// ErrIllegalLoginType = errors.New("不支持的登录类型")
|
||||
// )
|
||||
|
||||
// type LoginInfo struct {
|
||||
// ID string
|
||||
// LoginType string
|
||||
// ExpiresIn int64
|
||||
// Token string
|
||||
// }
|
||||
|
||||
// func init() {
|
||||
// authers = make(map[string]IAuther)
|
||||
// }
|
||||
|
||||
// func RegisterAuther(loginType string, handler IAuther) {
|
||||
// authers[loginType] = handler
|
||||
// }
|
||||
|
||||
// func CreateLoginInfo(id, loginType string) (loginInfo *LoginInfo) {
|
||||
// token := utils.GetUUID()
|
||||
// loginInfo = &LoginInfo{
|
||||
// ID: id,
|
||||
// LoginType: loginType,
|
||||
// ExpiresIn: time.Now().Add(DefTokenDuration).Unix(),
|
||||
// Token: token,
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("CreateLoginInfo id:%s, loginType:%s, loginInfo:%s", id, loginType, utils.Format4Output(loginInfo, true))
|
||||
// api.Cacher.Set(token, loginInfo, DefTokenDuration)
|
||||
// return loginInfo
|
||||
// }
|
||||
|
||||
// func Login(id, loginType, secret string) (loginInfo *LoginInfo, err error) {
|
||||
// globals.SugarLogger.Debugf("Login id:%s, loginType:%s, secret:%s", id, loginType, secret)
|
||||
// if handler := authers[loginType]; handler != nil {
|
||||
// userID, loginType2, err2 := handler.Login(id, secret)
|
||||
// if err = err2; err == nil {
|
||||
// if userID != "" {
|
||||
// globals.SugarLogger.Debugf("Login id:%s, loginType:%s, id changed to:%s", id, loginType, userID)
|
||||
// id = userID
|
||||
// }
|
||||
// if loginType2 != "" {
|
||||
// loginType = loginType2
|
||||
// }
|
||||
// return CreateLoginInfo(id, loginType), nil
|
||||
// }
|
||||
// err = ConvertErr2NoUser(err, "")
|
||||
// } else {
|
||||
// err = ErrLoginTypeNotSupported
|
||||
// }
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// func Logout(token string) (err error) {
|
||||
// globals.SugarLogger.Debugf("Logout token:%s", token)
|
||||
// loginInfo := new(LoginInfo)
|
||||
// if err = api.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
// if handler := authers[loginInfo.LoginType]; handler != nil {
|
||||
// err = handler.Logout(loginInfo)
|
||||
// }
|
||||
// api.Cacher.Del(token)
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func GetUserInfo(token string) (loginInfo *LoginInfo, err error) {
|
||||
// loginInfo = new(LoginInfo)
|
||||
// if err = api.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
// return loginInfo, nil
|
||||
// }
|
||||
// return nil, model.ErrTokenIsInvalid
|
||||
// }
|
||||
|
||||
// func ConvertErr2NoUser(err error, mobileNum string) error {
|
||||
// if dao.IsNoRowsError(err) {
|
||||
// err = ErrUserNotExist
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func (a *LoginInfo) GetAuthID() string {
|
||||
// return a.ID
|
||||
// }
|
||||
|
||||
// func (a *LoginInfo) GetAuthType() string {
|
||||
// return a.LoginType
|
||||
// }
|
||||
|
||||
// func (a *LoginInfo) GetUserTag() string {
|
||||
// return a.ID
|
||||
// }
|
||||
@@ -1,90 +0,0 @@
|
||||
package mobile
|
||||
|
||||
// const (
|
||||
// DefVerifyCodeDuration = 5 * time.Minute
|
||||
// TestMobile = "91112345678"
|
||||
// TestVerifyCode = "123456"
|
||||
// )
|
||||
|
||||
// var (
|
||||
// warningMap = map[string]int{
|
||||
// "isv.AMOUNT_NOT_ENOUGH": 1,
|
||||
// "isv.ACCOUNT_ABNORMAL": 1,
|
||||
// "isv.OUT_OF_SERVICE": 1,
|
||||
// "isv.DAY_LIMIT_CONTROL": 1,
|
||||
// }
|
||||
// )
|
||||
|
||||
// const (
|
||||
// LoginType = "mobile"
|
||||
// )
|
||||
|
||||
// var (
|
||||
// ErrVerifyCodeIsWrong = errors.New("验证码错")
|
||||
// )
|
||||
|
||||
// type Auther struct {
|
||||
// }
|
||||
|
||||
// var (
|
||||
// auther *Auther
|
||||
// )
|
||||
|
||||
// func init() {
|
||||
// auther = new(Auther)
|
||||
// auth.RegisterAuther(LoginType, auther)
|
||||
// }
|
||||
|
||||
// func SendVerifyCode(mobileNumber string) error {
|
||||
// code := fmt.Sprintf("%06d", rand.Intn(1000000))
|
||||
// globals.SugarLogger.Debugf("SendVerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
|
||||
// smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
||||
// response, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_175583158", string(utils.MustMarshal(map[string]interface{}{
|
||||
// "code": code,
|
||||
// })))
|
||||
// api.Cacher.Set(mobileNumber, code, DefVerifyCodeDuration)
|
||||
// if err == nil && response.Code == aliyunsmsclient.ResponseCodeOk {
|
||||
// } else {
|
||||
// if err == nil {
|
||||
// if warningMap[response.Code] == 1 {
|
||||
// globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
// } else {
|
||||
// globals.SugarLogger.Infof("SendVerifyCode mobileNumber:%s failed with response:%s", mobileNumber, utils.Format4Output(response, false))
|
||||
// }
|
||||
// err = fmt.Errorf("发送短信出错:%s", response.Message)
|
||||
// } else {
|
||||
// globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err)
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func VerifyCode(mobileNumber, code string) (err error) {
|
||||
// globals.SugarLogger.Debugf("VerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
|
||||
// err = ErrVerifyCodeIsWrong
|
||||
// if mobileNumber == TestMobile && code == TestVerifyCode {
|
||||
// err = nil
|
||||
// } else {
|
||||
// if value := api.Cacher.Get(mobileNumber); value != nil {
|
||||
// if code == value.(string) {
|
||||
// api.Cacher.Del(mobileNumber)
|
||||
// err = nil
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func (a *Auther) Login(mobileNum, verifyCode string) (userID, LoginType string, err error) {
|
||||
// if err = VerifyCode(mobileNum, verifyCode); err == nil {
|
||||
// _, err = dao.GetWeiXinUserByIDs(dao.GetDB(), mobileNum, "", "", "")
|
||||
// err = auth.ConvertErr2NoUser(err, mobileNum)
|
||||
// }
|
||||
// return "", "", err
|
||||
// }
|
||||
|
||||
// func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
|
||||
// return nil
|
||||
// }
|
||||
@@ -1,8 +0,0 @@
|
||||
package mobile
|
||||
|
||||
// func TestSendVerifyCode(t *testing.T) {
|
||||
// err := SendVerifyCode("18180948107")
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// }
|
||||
@@ -1,249 +0,0 @@
|
||||
package weixin
|
||||
|
||||
// const (
|
||||
// LoginType = "weixinsns"
|
||||
// LoginTypeMiniProgram = "weixinmini"
|
||||
// DefTempPasswordDuration = 20 * time.Minute // 登录时间限制在5分钟内
|
||||
// )
|
||||
|
||||
// const (
|
||||
// CacheKeySeparator = "/"
|
||||
// MiniVerifyCodePrefix = "MiniVerifyCode"
|
||||
// SessionKeyPrefix = "SessionKey"
|
||||
// )
|
||||
|
||||
// var (
|
||||
// StrStateIsWrong = "state:%s状态不对"
|
||||
// )
|
||||
|
||||
// var (
|
||||
// auther *Auther
|
||||
// AutherMini *AutherMiniProgram
|
||||
// )
|
||||
|
||||
// var (
|
||||
// ErrExceptionalLogin = errors.New("登录异常,超时,请重走绑定流程")
|
||||
// )
|
||||
|
||||
// type Auther struct {
|
||||
// }
|
||||
|
||||
// type AutherMiniProgram struct {
|
||||
// }
|
||||
|
||||
// type UserInfoExt struct {
|
||||
// weixinapi.SNSUserInfo
|
||||
// TempPassword string `json:"tempPassword"` // 一段时间有效的登录密码
|
||||
// LoginInfo *auth.LoginInfo `json:"loginInfo"`
|
||||
// }
|
||||
|
||||
// func init() {
|
||||
// auther = new(Auther)
|
||||
// auth.RegisterAuther(LoginType, auther)
|
||||
|
||||
// AutherMini = new(AutherMiniProgram)
|
||||
// auth.RegisterAuther(LoginTypeMiniProgram, AutherMini)
|
||||
// }
|
||||
|
||||
// func cacheSNSInfo(wxUserinfo *weixinapi.SNSUserInfo, password string, duration time.Duration) {
|
||||
// api.Cacher.Set(wxUserinfo.OpenID, password, duration)
|
||||
// api.Cacher.Set(wxUserinfo.OpenID+".sns", wxUserinfo, duration)
|
||||
// }
|
||||
|
||||
// func getSNSInfoFromCache(openID string) (wxUserinfo *weixinapi.SNSUserInfo, password string) {
|
||||
// password, _ = api.Cacher.Get(openID).(string)
|
||||
// wxUserinfo = new(weixinapi.SNSUserInfo)
|
||||
// if err := api.Cacher.GetAs(openID+".sns", wxUserinfo); err != nil {
|
||||
// wxUserinfo = nil
|
||||
// }
|
||||
// return wxUserinfo, password
|
||||
// }
|
||||
|
||||
// func GetWeiXinUserInfo(code string, state string) (userInfo *UserInfoExt, err error) {
|
||||
// globals.SugarLogger.Debugf("GetUserInfo code:%s", code)
|
||||
// if state == "" {
|
||||
// token, err2 := api.WeixinAPI.SNSRetrieveToken(code)
|
||||
// if err = err2; err == nil {
|
||||
// wxUserinfo, err2 := api.WeixinAPI.SNSGetUserInfo(token.AccessToken, token.OpenID)
|
||||
// if err = err2; err == nil {
|
||||
// userInfo = &UserInfoExt{
|
||||
// SNSUserInfo: *wxUserinfo,
|
||||
// TempPassword: utils.GetUUID(),
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("GetUserInfo code:%s, userInfo:%s", code, utils.Format4Output(userInfo, true))
|
||||
// cacheSNSInfo(wxUserinfo, userInfo.TempPassword, DefTempPasswordDuration)
|
||||
// user, err2 := dao.GetWeiXinUserByIDs(dao.GetDB(), "", wxUserinfo.UnionID, wxUserinfo.OpenID, "")
|
||||
// if err = err2; err == nil {
|
||||
// userInfo.LoginInfo = auth.CreateLoginInfo(user.Tel, mobile.LoginType)
|
||||
// } else if !dao.IsNoRowsError(err) { // 非用户不存在错误,报错
|
||||
// return nil, err
|
||||
// }
|
||||
// return userInfo, nil
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// err = fmt.Errorf(StrStateIsWrong, state)
|
||||
// }
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// // 此函数需要调整
|
||||
// func (a *Auther) Login(openid, password string) (userID, LoginType string, err error) {
|
||||
// globals.SugarLogger.Debugf("weixinsns Login openid:%s, password:%s", openid, password)
|
||||
// _, cachedPwd := getSNSInfoFromCache(openid)
|
||||
// if cachedPwd != "" && password == cachedPwd {
|
||||
// api.Cacher.Del(openid)
|
||||
// return "", "", nil
|
||||
// }
|
||||
// return "", "", ErrExceptionalLogin
|
||||
// }
|
||||
|
||||
// func (a *Auther) Logout(loginInfo *auth.LoginInfo) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// func BindMobile(token, mobileNum, code, nickname string) (err error) {
|
||||
// globals.SugarLogger.Debugf("BindMobile token:%s, mobileNum:%s, code:%s, nickname:%s", token, mobileNum, code, nickname)
|
||||
|
||||
// loginInfo := new(auth.LoginInfo)
|
||||
// if err = api.Cacher.GetAs(token, loginInfo); err == nil {
|
||||
// if err = mobile.VerifyCode(mobileNum, code); err == nil {
|
||||
// wxUserinfo, _ := getSNSInfoFromCache(loginInfo.ID)
|
||||
// if wxUserinfo == nil {
|
||||
// return fmt.Errorf("绑定超时,请重新绑定")
|
||||
// }
|
||||
// if nickname == "" {
|
||||
// nickname = wxUserinfo.NickName
|
||||
// }
|
||||
// err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(dao.GetDB(), mobileNum, nickname, wxUserinfo.UnionID, wxUserinfo.OpenID, ""), mobileNum)
|
||||
// }
|
||||
// }
|
||||
// jxutils.HandleUserWXRemark(nil, mobileNum, false)
|
||||
// return err
|
||||
// }
|
||||
|
||||
// // 绑定手机加登录
|
||||
// func BindMobile2(openid, secret, mobileNum, verifyCode, nickname string) (loginInfo *auth.LoginInfo, err error) {
|
||||
// globals.SugarLogger.Debugf("BindMobile2 openid:%s, secret:%s, mobileNum:%s, verifyCode:%s, nickname:%s", openid, secret, mobileNum, verifyCode, nickname)
|
||||
|
||||
// err = ErrExceptionalLogin
|
||||
// if value := api.Cacher.Get(openid); value != nil {
|
||||
// wxUserinfo, cachedSecret := getSNSInfoFromCache(openid)
|
||||
// if wxUserinfo == nil {
|
||||
// return nil, fmt.Errorf("绑定超时,请重新绑定")
|
||||
// }
|
||||
// if secret == cachedSecret {
|
||||
// if err = mobile.VerifyCode(mobileNum, verifyCode); err == nil {
|
||||
// api.Cacher.Del(openid)
|
||||
// err = nil
|
||||
// if nickname == "" {
|
||||
// nickname = wxUserinfo.NickName
|
||||
// }
|
||||
// if err = dao.UpdateWeiXinUser(dao.GetDB(), mobileNum, nickname, wxUserinfo.UnionID, wxUserinfo.OpenID, ""); err == nil {
|
||||
// loginInfo = auth.CreateLoginInfo(mobileNum, mobile.LoginType)
|
||||
// } else {
|
||||
// err = auth.ConvertErr2NoUser(err, mobileNum)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// jxutils.HandleUserWXRemark(nil, mobileNum, false)
|
||||
// return loginInfo, err
|
||||
// }
|
||||
|
||||
// // 此函数已废弃
|
||||
// // 对于小程序来说,
|
||||
// // 1,用户必须先在后台创建(手机号标识)
|
||||
// // 2,用户必须先绑定微信
|
||||
// // 先以短信方式登录:
|
||||
// // SendMobileVerifyCode
|
||||
// // Login use type mobile
|
||||
// // MiniBindWeiXin
|
||||
// // 3,用户以CODE来登录(Login use type weixinmini)
|
||||
// // Login
|
||||
|
||||
// func (a *AutherMiniProgram) BindWeiXin(ctx *jxcontext.Context, code, nickName string) (err error) {
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram BindWeiXin code:%s, nickName:%s", code, nickName)
|
||||
// loginInfo := ctx.GetLoginInfo()
|
||||
// if loginInfo == nil || loginInfo.GetAuthType() != mobile.LoginType {
|
||||
// return fmt.Errorf("调用AutherMiniProgram BindWeiXin时,必须以手机验证方式登录")
|
||||
// }
|
||||
// sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// err = dao.UpdateWeiXinUser(dao.GetDB(), loginInfo.GetAuthID(), nickName, sessionInfo.UnionID, "", sessionInfo.OpenID)
|
||||
// return auth.ConvertErr2NoUser(err, "")
|
||||
// }
|
||||
|
||||
// // 绑定小程序
|
||||
// func (a *AutherMiniProgram) BindMiniProgram(ctx *jxcontext.Context, code string) (err error) {
|
||||
// globals.SugarLogger.Debugf("BindMiniProgram code:%s", code)
|
||||
// if ctx.GetLoginType() != mobile.LoginType {
|
||||
// return errors.New("登录方式应该为手机")
|
||||
// }
|
||||
// sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// db := dao.GetDB()
|
||||
// user, err := dao.GetWeiXinUserByIDs(db, ctx.GetLoginID(), "", "", "")
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // if user.OpenIDUnion != sessionInfo.UnionID {
|
||||
// // return errors.New("绑定用户不匹配")
|
||||
// // }
|
||||
// err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(db, user.Tel, "", sessionInfo.UnionID, "", sessionInfo.OpenID), user.Tel)
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func (a *AutherMiniProgram) Login(mobileNum, code string) (userID, LoginType string, err error) {
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram Login mobileNum:%s, code:%s", mobileNum, code)
|
||||
// sessionInfo, err := weixin2.ProxySNSCode2Session(code)
|
||||
// if err != nil {
|
||||
// return "", "", err
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram Login code:%s, unionID:%s, openID:%s", code, sessionInfo.UnionID, sessionInfo.OpenID)
|
||||
// db := dao.GetDB()
|
||||
// user, err := dao.GetWeiXinUserByIDs(db, "", sessionInfo.UnionID, "", sessionInfo.OpenID)
|
||||
// if err != nil {
|
||||
// return "", "", auth.ConvertErr2NoUser(err, mobileNum)
|
||||
// }
|
||||
// if user.OpenIDMini != sessionInfo.OpenID {
|
||||
// user.OpenIDMini = sessionInfo.OpenID
|
||||
// dao.UpdateEntity(db, user, "OpenIDMini")
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram Login user.Tel:%s, code:%s, openID:%s", user.Tel, code, sessionInfo.OpenID)
|
||||
// if mobileNum != user.Tel {
|
||||
|
||||
// }
|
||||
// api.Cacher.Set(composeSessionKeyCacheKey(user.Tel), sessionInfo.SessionKey, auth.DefTokenDuration)
|
||||
// return user.Tel, mobile.LoginType, err
|
||||
// }
|
||||
|
||||
// func (a *AutherMiniProgram) Logout(loginInfo *auth.LoginInfo) error {
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram Logout openid:%s", utils.Format4Output(loginInfo, false))
|
||||
// return api.Cacher.Del(composeSessionKeyCacheKey(loginInfo.GetAuthID()))
|
||||
// }
|
||||
|
||||
// func (a *AutherMiniProgram) DecryptData(ctx *jxcontext.Context, encryptedData, iv string) (decryptedDataBase64 string, err error) {
|
||||
// globals.SugarLogger.Debugf("AutherMiniProgram DecryptData encryptedData:%s, iv:%s", encryptedData, iv)
|
||||
// var sessionKey string
|
||||
// if err = api.Cacher.GetAs(composeSessionKeyCacheKey(ctx.GetLoginInfo().GetAuthID()), &sessionKey); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// decryptedData, err := weixin2.ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// return base64.StdEncoding.EncodeToString(decryptedData), nil
|
||||
// }
|
||||
|
||||
// func composeMiniVerifiyCacheKey(key string) string {
|
||||
// return MiniVerifyCodePrefix + CacheKeySeparator + key
|
||||
// }
|
||||
|
||||
// func composeSessionKeyCacheKey(key string) string {
|
||||
// return SessionKeyPrefix + CacheKeySeparator + key
|
||||
// }
|
||||
@@ -737,3 +737,30 @@ func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context,
|
||||
}
|
||||
return hint, 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
|
||||
}
|
||||
|
||||
@@ -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!")
|
||||
|
||||
@@ -12,9 +12,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/routinepool"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
@@ -39,6 +41,8 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
const fileExt = ".xlsx"
|
||||
|
||||
type OrderSkuList []*model.OrderSku
|
||||
|
||||
func (l OrderSkuList) Len() int {
|
||||
@@ -564,6 +568,15 @@ func UploadExportContent(content []byte, key string) (downloadURL string, err er
|
||||
return downloadURL, 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 = UploadExportContent(excelBin, fileName)
|
||||
return downloadURL, fileName, err
|
||||
}
|
||||
|
||||
func TaskResult2Hint(resultList []interface{}) (hint string) {
|
||||
strList := make([]string, len(resultList))
|
||||
for k, v := range resultList {
|
||||
|
||||
@@ -922,20 +922,15 @@ func GetOrders(db *DaoDB, ids []int64, isIncludeSku, isIncludeFake bool, fromDat
|
||||
func UpdateOrdersWithoutJxStoreID(db *DaoDB, fromDate, toDate time.Time) (count int64, err error) {
|
||||
sql := `
|
||||
UPDATE goods_order t1
|
||||
JOIN store_map a ON a.vendor_store_id = t1.vendor_store_id
|
||||
JOIN store_map a ON a.vendor_store_id = t1.vendor_store_id AND a.vendor_id = t1.vendor_id
|
||||
SET t1.jx_store_id = a.store_id
|
||||
WHERE t1.jx_store_id = 0
|
||||
AND t1.status != ?
|
||||
AND t1.vendor_store_id != ?
|
||||
AND a.status = ?
|
||||
AND a.deleted_at = ?
|
||||
AND t1.order_created_at >= ? AND t1.order_created_at <= ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
model.OrderStatusCanceled,
|
||||
2523687, //测试门店
|
||||
model.StoreStatusOpened,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
sql += " AND t1.order_created_at >= ?"
|
||||
sql += " AND t1.order_created_at <= ?"
|
||||
if !utils.IsTimeZero(fromDate) {
|
||||
sqlParams = append(sqlParams, fromDate)
|
||||
if !utils.IsTimeZero(toDate) {
|
||||
@@ -954,3 +949,38 @@ func UpdateOrdersWithoutJxStoreID(db *DaoDB, fromDate, toDate time.Time) (count
|
||||
}
|
||||
return ExecuteSQL(db, sql, sqlParams)
|
||||
}
|
||||
|
||||
func GetMyOrderCountInfo(db *DaoDB, userID string, fromDate, toDate time.Time, statuss []int) (countInfo []*model.GoodsOrderCountInfo, err error) {
|
||||
if utils.IsTimeZero(fromDate) {
|
||||
return nil, fmt.Errorf("必须指定开始日期")
|
||||
}
|
||||
if !utils.IsTimeZero(fromDate) {
|
||||
fromDate = utils.Time2Date(fromDate)
|
||||
if utils.IsTimeZero(toDate) {
|
||||
toDate = fromDate
|
||||
}
|
||||
}
|
||||
if !utils.IsTimeZero(toDate) {
|
||||
toDate = utils.Time2Date(toDate)
|
||||
toDate = toDate.Add(24 * time.Hour)
|
||||
}
|
||||
|
||||
sql := `
|
||||
SELECT t1.lock_status, t1.status, COUNT(*) count
|
||||
FROM goods_order t1
|
||||
WHERE t1.user_id = ? AND t1.vendor_id = ?
|
||||
AND t1.order_created_at >= ? AND t1.order_created_at < ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
userID,
|
||||
model.VendorIDJX,
|
||||
fromDate, toDate,
|
||||
}
|
||||
if len(statuss) > 0 {
|
||||
sql += " AND t1.status IN (" + GenQuestionMarks(len(statuss)) + ")"
|
||||
sqlParams = append(sqlParams, statuss)
|
||||
}
|
||||
sql += " GROUP BY 1,2"
|
||||
err = GetRows(db, &countInfo, sql, sqlParams...)
|
||||
return countInfo, err
|
||||
}
|
||||
|
||||
@@ -663,6 +663,36 @@ func GetStoreSkusByNameIDs(db *DaoDB, storeIDs []int, nameID int) (skuList []*St
|
||||
return skuList, err
|
||||
}
|
||||
|
||||
func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuAndName []*model.SkuAndName, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM(
|
||||
SELECT SUM(b.count) count,b.sku_id
|
||||
FROM goods_order a
|
||||
JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id
|
||||
JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ?
|
||||
WHERE 1=1
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND a.store_id in(" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
sql += `
|
||||
AND b.sale_price > ?
|
||||
GROUP BY b.sku_id)t1
|
||||
JOIN sku t2 ON t1.sku_id = t2.id
|
||||
JOIN sku_name t3 ON t2.name_id = t3.id
|
||||
ORDER BY t1.count DESC
|
||||
LIMIT ?
|
||||
`
|
||||
sqlParams = append(sqlParams, 100, 30)
|
||||
err = GetRows(db, &skuAndName, sql, sqlParams...)
|
||||
return skuAndName, err
|
||||
}
|
||||
|
||||
func SetStoreSkuBindVendorPrice(storeSkuBind *model.StoreSkuBind, vendorID int, vendorPrice int) {
|
||||
switch vendorID {
|
||||
case model.VendorIDJD:
|
||||
@@ -712,3 +742,12 @@ func GetStoreSkuBindSyncStatus(storeSkuBind *model.StoreSkuBind, vendorID int) (
|
||||
}
|
||||
return syncStatus
|
||||
}
|
||||
|
||||
func SetStoreCatMapSyncStatus(storeCatMap *model.StoreSkuCategoryMap, vendorID int, syncStatus int8) {
|
||||
switch vendorID {
|
||||
case model.VendorIDMTWM:
|
||||
storeCatMap.MtwmSyncStatus = syncStatus
|
||||
case model.VendorIDEBAI:
|
||||
storeCatMap.EbaiSyncStatus = syncStatus
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ type GoodsOrder struct {
|
||||
EarningPrice int64 `json:"earningPrice"` // 结算给门店老板的钱(未扣除可能的三方配送费)
|
||||
Weight int `json:"weight"` // 单位为克
|
||||
VendorUserID string `orm:"column(vendor_user_id);size(48)" json:"vendorUserID"`
|
||||
UserID string `orm:"column(user_id);size(48)" json:"userID"`
|
||||
UserID string `orm:"column(user_id);size(48);index" json:"userID"`
|
||||
ConsigneeName string `orm:"size(32)" json:"consigneeName"`
|
||||
ConsigneeMobile string `orm:"size(32)" json:"consigneeMobile"` // 订单中的收货手机号
|
||||
ConsigneeMobile2 string `orm:"size(32)" json:"consigneeMobile2"` // 收货人真实手机号
|
||||
|
||||
@@ -66,9 +66,11 @@ func ActStoreSku2ActStoreSkuMap(actStoreSku *model.ActStoreSku2) (actStoreSkuMap
|
||||
return actStoreSkuMap
|
||||
}
|
||||
|
||||
func Act2Update(act *model.Act2, syncStatus int) (item *dao.KVUpdateItem) {
|
||||
func Act2Update(ctx *jxcontext.Context, act *model.Act2, syncStatus int) (item *dao.KVUpdateItem) {
|
||||
kvs := map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldUpdatedAt: time.Now(),
|
||||
model.FieldLastOperator: ctx.GetUserName(),
|
||||
}
|
||||
if syncStatus == model.SyncFlagDeletedMask {
|
||||
kvs[model.FieldDeletedAt] = time.Now()
|
||||
@@ -82,10 +84,12 @@ func Act2Update(act *model.Act2, syncStatus int) (item *dao.KVUpdateItem) {
|
||||
return item
|
||||
}
|
||||
|
||||
func ActStoreSku2Update(actStoreSkuList []*model.ActStoreSku2, syncStatus int) (items []*dao.KVUpdateItem) {
|
||||
func ActStoreSku2Update(ctx *jxcontext.Context, actStoreSkuList []*model.ActStoreSku2, syncStatus int) (items []*dao.KVUpdateItem) {
|
||||
for _, v := range actStoreSkuList {
|
||||
kvs := map[string]interface{}{
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldSyncStatus: 0,
|
||||
model.FieldUpdatedAt: time.Now(),
|
||||
model.FieldLastOperator: ctx.GetUserName(),
|
||||
}
|
||||
if syncStatus == model.SyncFlagDeletedMask {
|
||||
kvs[model.FieldDeletedAt] = time.Now()
|
||||
|
||||
@@ -299,34 +299,34 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
err = func() (err error) {
|
||||
if model.IsSyncStatusDelete(act.SyncStatus) {
|
||||
canceledList, err2 := cancelSkuAct(ctx, nil, vendorActInfoMap)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(canceledList, model.SyncFlagModifiedMask)...)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, canceledList, model.SyncFlagModifiedMask)...)
|
||||
if err = err2; err == nil {
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
|
||||
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
|
||||
}
|
||||
} else if model.IsSyncStatusNew(act.SyncStatus) {
|
||||
createdList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(createdList, model.SyncFlagNewMask)...)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, createdList, model.SyncFlagNewMask)...)
|
||||
if err = err2; err == nil {
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask))
|
||||
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagNewMask))
|
||||
}
|
||||
} else if model.IsSyncStatusUpdate(act.SyncStatus) {
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(updateItems, false))
|
||||
if len(actStoreSkuList4Create) > 0 {
|
||||
addedList, err2 := addSkuActSkus(ctx, nil, act, actStoreSkuList4Create, vendorActIDMap)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(addedList, model.SyncFlagNewMask)...)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, addedList, model.SyncFlagNewMask)...)
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(deleteActInfoMap) > 0 {
|
||||
deletedList, err2 := deleteSkuActSkus(ctx, nil, deleteActInfoMap, vendorActInfoMap)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(deletedList, model.SyncFlagDeletedMask)...)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, deletedList, model.SyncFlagDeletedMask)...)
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
|
||||
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -1,555 +0,0 @@
|
||||
package ebai
|
||||
|
||||
// type tStoreSkuFullInfo struct {
|
||||
// model.StoreSkuBind
|
||||
|
||||
// NameID int `orm:"column(name_id)"`
|
||||
|
||||
// SpecQuality float32 `json:"specQuality"`
|
||||
// SpecUnit string `orm:"size(8)" json:"specUnit"` // 质量或容量
|
||||
// Weight int `json:"weight"` // 重量/质量,单位为克,当相应的SkuName的SpecUnit为g或kg时,必须等于SpecQuality
|
||||
// SkuStatus int
|
||||
|
||||
// Prefix string `orm:"size(255)" json:"prefix"`
|
||||
// Name string `orm:"size(255);index" json:"name"`
|
||||
// Comment string `orm:"size(255)" json:"comment"`
|
||||
// IsGlobal int8 `orm:"default(1)" json:"isGlobal"` // 是否是全部(全国)可见,如果否的话,可见性由SkuPlace决定
|
||||
// Unit string `orm:"size(8)" json:"unit"`
|
||||
// Img string `orm:"size(255)" json:"img"`
|
||||
// PlaceStr string
|
||||
// Upc string
|
||||
// DescImgEbai string
|
||||
|
||||
// CatName string `orm:"size(255)"`
|
||||
|
||||
// CatMapID int `orm:"column(cat_map_id)"`
|
||||
// CatID int `orm:"column(cat_id)"`
|
||||
// CatEbaiID int64 `orm:"column(cat_ebai_id)"`
|
||||
|
||||
// ParentCatMapID int `orm:"column(parent_cat_map_id)"`
|
||||
// ParentCatID int `orm:"column(parent_cat_id)"`
|
||||
// ParentCatEbaiID int64 `orm:"column(parent_cat_ebai_id)"`
|
||||
|
||||
// EbaiCat1ID int64 `orm:"column(ebai_cat1_id)"`
|
||||
// EbaiCat2ID int64 `orm:"column(ebai_cat2_id)"`
|
||||
// EbaiCat3ID int64 `orm:"column(ebai_cat3_id)"`
|
||||
|
||||
// CatPricePercentage int
|
||||
// }
|
||||
|
||||
// type tStoreCatInfo struct {
|
||||
// model.StoreSkuCategoryMap
|
||||
// CatID int `orm:"column(cat_id)"`
|
||||
// Name string
|
||||
// ParentID int `orm:"column(parent_id)"`
|
||||
// Level int
|
||||
// Type int
|
||||
// Seq int
|
||||
|
||||
// ParentEbaiID int64 `orm:"column(parent_ebai_id)"`
|
||||
// Children map[string]*tStoreCatInfo `orm:"-"`
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) getDirtyStoreSkus(db *dao.DaoDB, storeID int, skuIDs []int) (storeSkuInfoList []*tStoreSkuFullInfo, err error) {
|
||||
// sql := `
|
||||
// SELECT
|
||||
// t1.*, t2.spec_quality, t2.spec_unit, t2.weight, t2.status sku_status,
|
||||
// t3.id name_id, t3.prefix, t3.name, t2.comment, t3.is_global, t3.unit, IF(t3.img_ebai <> '', t3.img_ebai, t3.img) img, t3.upc, t3.desc_img_ebai,
|
||||
// t4.name cat_name, t4.ebai_price_percentage cat_price_percentage,
|
||||
// t4.id cat_id,
|
||||
// t5.id cat_map_id, t5.ebai_id cat_ebai_id,
|
||||
// t4p.id parent_cat_id,
|
||||
// t5p.id parent_cat_map_id, t5p.ebai_id parent_cat_ebai_id,
|
||||
// cat1.vendor_category_id ebai_cat3_id, cat2.vendor_category_id ebai_cat2_id, cat2.parent_id ebai_cat1_id
|
||||
// FROM store_sku_bind t1
|
||||
// LEFT JOIN sku t2 ON t1.sku_id = t2.id AND t2.deleted_at = ? AND t2.status = ?
|
||||
// LEFT JOIN sku_name t3 ON t2.name_id = t3.id AND t3.deleted_at = ? AND t3.status = ?
|
||||
// LEFT JOIN sku_category t4 ON t3.category_id = t4.id
|
||||
// LEFT JOIN sku_category t4p ON t4p.id = t4.parent_id
|
||||
// LEFT JOIN store_sku_category_map t5 ON t5.store_id = t1.store_id AND t5.category_id = t4.id AND t5.deleted_at = ?
|
||||
// LEFT JOIN store_sku_category_map t5p ON t5p.store_id = t1.store_id AND t5p.category_id = t4p.id AND t5p.deleted_at = ?
|
||||
// LEFT JOIN sku_vendor_category cat1 ON t4.ebai_category_id = cat1.vendor_category_id AND cat1.vendor_id = ?
|
||||
// LEFT JOIN sku_vendor_category cat2 ON cat1.parent_id = cat2.vendor_category_id AND cat1.vendor_id = ?
|
||||
// WHERE t1.store_id = ? AND (t1.ebai_sync_status <> 0 OR (t1.ebai_id <> 0 AND t3.id IS NULL))
|
||||
// `
|
||||
// sqlParams := []interface{}{
|
||||
// utils.DefaultTimeValue,
|
||||
// model.SkuStatusNormal,
|
||||
// utils.DefaultTimeValue,
|
||||
// model.SkuStatusNormal,
|
||||
// utils.DefaultTimeValue,
|
||||
// utils.DefaultTimeValue,
|
||||
// model.VendorIDEBAI,
|
||||
// model.VendorIDEBAI,
|
||||
// storeID,
|
||||
// }
|
||||
// if len(skuIDs) > 0 {
|
||||
// sql += " AND t1.sku_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
|
||||
// sqlParams = append(sqlParams, skuIDs)
|
||||
// }
|
||||
// sql += " ORDER BY t1.price DESC"
|
||||
// err = dao.GetRows(db, &storeSkuInfoList, sql, sqlParams...)
|
||||
// return storeSkuInfoList, err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) createCatByStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, db *dao.DaoDB, storeID int, storeSkuInfoList []*tStoreSkuFullInfo) (num int64, err error) {
|
||||
// catList2Add := make(map[int]int)
|
||||
// for _, storeSku := range storeSkuInfoList {
|
||||
// if storeSku.CatID != 0 && storeSku.EbaiSyncStatus&(model.SyncFlagNewMask|model.SyncFlagStoreSkuModifiedMask) != 0 && storeSku.Status == model.SkuStatusNormal {
|
||||
// if storeSku.ParentCatMapID == 0 && storeSku.ParentCatID != 0 {
|
||||
// catList2Add[storeSku.ParentCatID] = 1
|
||||
// }
|
||||
// if storeSku.CatMapID == 0 {
|
||||
// catList2Add[storeSku.CatID] = 1
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// num = int64(len(catList2Add))
|
||||
// if num > 0 {
|
||||
// for k := range catList2Add {
|
||||
// if err = dao.AddStoreCategoryMap(db, storeID, k, model.VendorIDEBAI, "", model.SyncFlagNewMask, ctx.GetUserName()); err != nil {
|
||||
// return 0, err
|
||||
// }
|
||||
// }
|
||||
// if _, err = p.SyncStoreCategory(ctx, parentTask, storeID, false); err != nil {
|
||||
// return 0, err
|
||||
// }
|
||||
// }
|
||||
// return num, nil
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// userName := ctx.GetUserName()
|
||||
// globals.SugarLogger.Debugf("ebai FullSyncStoreSkus storeID:%d, isContinueWhenError:%t, userName:%s", storeID, isContinueWhenError, userName)
|
||||
|
||||
// db := dao.GetDB()
|
||||
// storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDEBAI)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// rootTask := tasksch.NewSeqTask("FullSyncStoreSkus", ctx,
|
||||
// func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
// switch step {
|
||||
// case 0:
|
||||
// err = p.DeleteStoreAllSkus(ctx, rootTask, storeID, storeDetail.VendorStoreID, isContinueWhenError)
|
||||
// // 强制忽略删除SKU错误
|
||||
// if isContinueWhenError {
|
||||
// err = nil
|
||||
// }
|
||||
// if err == nil {
|
||||
// _, err = dao.SetStoreSkuSyncStatus(db, model.VendorIDEBAI, []int{storeID}, nil, model.SyncFlagNewMask)
|
||||
// }
|
||||
// case 1:
|
||||
// if err = p.DeleteStoreAllCategories(ctx, rootTask, storeID, storeDetail.VendorStoreID, isContinueWhenError); err == nil {
|
||||
// _, err = dao.SetStoreCategorySyncStatus(db, model.VendorIDEBAI, []int{storeID}, nil, model.SyncFlagNewMask)
|
||||
// }
|
||||
// case 2:
|
||||
// err = p.SyncLocalStoreCategory(db, storeID, userName)
|
||||
// case 3:
|
||||
// _, err = p.SyncStoreCategory(ctx, rootTask, storeID, false)
|
||||
// case 4:
|
||||
// _, err = p.SyncStoreSkus(ctx, rootTask, storeID, nil, false, isContinueWhenError)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, 5)
|
||||
// tasksch.AddChild(parentTask, rootTask).Run()
|
||||
// if !isAsync {
|
||||
// _, err = rootTask.GetResult(0)
|
||||
// }
|
||||
// return rootTask.ID, err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// db := dao.GetDB()
|
||||
// storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDEBAI)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// return p.syncStoreSkus(ctx, parentTask, storeDetail, skuIDs, isAsync, isContinueWhenError)
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) syncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeDetail *dao.StoreDetail, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// storeID := storeDetail.Store.ID
|
||||
// userName := ctx.GetUserName()
|
||||
// globals.SugarLogger.Debugf("ebai SyncStoreSkus storeID:%d, skuIDs:%v, isContinueWhenError:%t, userName:%s", storeID, skuIDs, isContinueWhenError, userName)
|
||||
|
||||
// var storeSkuInfoList []*tStoreSkuFullInfo
|
||||
// var num int64
|
||||
// strStoreID := utils.Int2Str(storeID)
|
||||
|
||||
// rootTask := tasksch.NewSeqTask("SyncStoreSkus饿百1", ctx,
|
||||
// func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
// if step == 0 {
|
||||
// db := dao.GetDB()
|
||||
// if _, err = p.SyncStoreCategory(ctx, parentTask, storeID, false); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// for i := 0; i < 3; i++ {
|
||||
// if storeSkuInfoList, err = p.getDirtyStoreSkus(db, storeID, skuIDs); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if num, err = p.createCatByStoreSkus(ctx, rootTask, db, storeID, storeSkuInfoList); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if num == 0 {
|
||||
// break
|
||||
// }
|
||||
// if _, err = p.SyncStoreCategory(ctx, parentTask, storeID, false); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// }
|
||||
// if num != 0 {
|
||||
// globals.SugarLogger.Infof("SyncStoreSkus 不能创建商品所需的类别, storeID:%d, skuIDs:%v, isContinueWhenError:%t, userName:%s", storeID, skuIDs, isContinueWhenError, userName)
|
||||
// return nil, errors.New("不能创建商品所需的类别")
|
||||
// }
|
||||
// } else if step == 1 {
|
||||
// task := tasksch.NewParallelTask("SyncStoreSkus饿百2", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
// func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// storeSku := batchItemList[0].(*tStoreSkuFullInfo)
|
||||
// pricePercentage := jxutils.GetPricePercentage(storeDetail.PricePercentagePackObj, storeSku.Price, int(storeDetail.PricePercentage))
|
||||
// // globals.SugarLogger.Debugf("skuID:%d, price:%d, pricePercentage:%d", storeSku.SkuID, storeSku.Price, pricePercentage)
|
||||
// // globals.SugarLogger.Debugf(utils.Format4Output(storeDetail.PricePercentagePackObj, false))
|
||||
// updateFields := []string{model.FieldEbaiSyncStatus}
|
||||
// syncStatus := int8(0)
|
||||
// if storeSku.NameID == 0 || storeSku.EbaiSyncStatus&model.SyncFlagDeletedMask != 0 {
|
||||
// if storeSku.EbaiSyncStatus&model.SyncFlagNewMask == 0 && !jxutils.IsEmptyID(storeSku.EbaiID) {
|
||||
// if globals.EnableEbaiStoreWrite {
|
||||
// opResult, err2 := api.EbaiAPI.SkuDelete(ctx.GetTrackInfo(), strStoreID, []int64{storeSku.EbaiID}, nil)
|
||||
// if err = err2; err != nil {
|
||||
// if ebaiapi.IsErrSkuNotExist(err) || (opResult != nil && len(opResult.FailedList) == 1) {
|
||||
// err = nil
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// if utils.IsTimeZero(storeSku.DeletedAt) {
|
||||
// storeSku.DeletedAt = time.Now()
|
||||
// updateFields = append(updateFields, model.FieldDeletedAt)
|
||||
// }
|
||||
// storeSku.EbaiID = 0
|
||||
// updateFields = append(updateFields, model.FieldEbaiID)
|
||||
// }
|
||||
// } else {
|
||||
// if storeSku.EbaiSyncStatus&model.SyncFlagNewMask != 0 {
|
||||
// // globals.SugarLogger.Debug(utils.Format4Output(genSkuParamsFromStoreSkuInfo(storeSku), false))
|
||||
// // todo 适当处理重复(即已经创建)的情况
|
||||
// mergedStoreSkuStatus := jxutils.MergeSkuStatus(storeSku.SkuStatus, storeSku.Status)
|
||||
// if mergedStoreSkuStatus == model.SkuStatusNormal { // 待创建且不可售的,暂不新建
|
||||
// if storeSku.Img != "" {
|
||||
// if globals.EnableEbaiStoreWrite {
|
||||
// if storeSku.EbaiID, err = api.EbaiAPI.SkuCreate(ctx.GetTrackInfo(), strStoreID, storeSku.SkuID, genSkuParamsFromStoreSkuInfo(pricePercentage, storeSku)); err == nil {
|
||||
// utils.AfterFuncWithRecover(5*time.Second, func() {
|
||||
// api.EbaiAPI.SkuShopCategoryMap(strStoreID, storeSku.EbaiID, "", storeSku.CatEbaiID, ebaiapi.MaxSkuCatRank-storeSku.Price)
|
||||
// })
|
||||
// }
|
||||
// } else {
|
||||
// storeSku.EbaiID = jxutils.GenFakeID()
|
||||
// }
|
||||
// if err == nil {
|
||||
// updateFields = append(updateFields, model.FieldEbaiID)
|
||||
// } else if ebaiapi.IsErrSkuExist(err) {
|
||||
// if storeSku.EbaiID = api.EbaiAPI.GetEbaiSkuIDFromCustomID(strStoreID, utils.Int2Str(storeSku.SkuID)); storeSku.EbaiID > 0 {
|
||||
// err = nil
|
||||
// updateFields = append(updateFields, model.FieldEbaiID)
|
||||
// if err2 := skuUpdate(ctx, strStoreID, pricePercentage, storeSku); err2 != nil {
|
||||
// syncStatus = model.SyncFlagStoreSkuModifiedMask
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// err = fmt.Errorf("SKUANME%d:%s没有图片,同步失败", storeSku.NameID, storeSku.Name)
|
||||
// }
|
||||
// } else {
|
||||
// updateFields = nil
|
||||
// }
|
||||
// } else if storeSku.EbaiSyncStatus&model.SyncFlagStoreSkuModifiedMask != 0 {
|
||||
// if jxutils.IsEmptyID(storeSku.EbaiID) {
|
||||
// err = fmt.Errorf("京西数据异常,修改一个没有创建的饿百商品:%d, store:%s", storeSku.SkuID, strStoreID)
|
||||
// } else {
|
||||
// if storeSku.Img != "" {
|
||||
// err = skuUpdate(ctx, strStoreID, pricePercentage, storeSku)
|
||||
// } else {
|
||||
// err = fmt.Errorf("SKUANME%d:%s没有图片,同步失败", storeSku.NameID, storeSku.Name)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// if len(updateFields) > 0 {
|
||||
// storeSku.EbaiSyncStatus = syncStatus
|
||||
// _, err = dao.UpdateEntity(nil, &storeSku.StoreSkuBind, updateFields...)
|
||||
// }
|
||||
// } else if isErrModifyPrice(err) {
|
||||
// // err = partner.NewErrorCode(err.Error(), partner.ErrCodeChangePriceFailed, model.VendorIDEBAI)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, storeSkuInfoList)
|
||||
// tasksch.AddChild(rootTask, task).Run()
|
||||
// _, err = task.GetResult(0)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, 2)
|
||||
// tasksch.AddChild(parentTask, rootTask).Run()
|
||||
// if !isAsync {
|
||||
// _, err = rootTask.GetResult(0)
|
||||
// }
|
||||
// return rootTask.ID, err
|
||||
// }
|
||||
|
||||
// func skuUpdate(ctx *jxcontext.Context, strStoreID string, pricePercentage int, storeSku *tStoreSkuFullInfo) (err error) {
|
||||
// if globals.EnableEbaiStoreWrite {
|
||||
// if _, err = api.EbaiAPI.SkuUpdate(ctx.GetTrackInfo(), strStoreID, storeSku.EbaiID, genSkuParamsFromStoreSkuInfo(pricePercentage, storeSku)); err != nil {
|
||||
// // 如果是改价错误,尝试把价格标志去掉再同步
|
||||
// if isErrModifyPrice(err) {
|
||||
// storeSku.EbaiSyncStatus = storeSku.EbaiSyncStatus & ^model.SyncFlagPriceMask
|
||||
// if storeSku.EbaiSyncStatus != 0 {
|
||||
// if _, err2 := api.EbaiAPI.SkuUpdate(ctx.GetTrackInfo(), strStoreID, storeSku.EbaiID, genSkuParamsFromStoreSkuInfo(pricePercentage, storeSku)); err2 != nil {
|
||||
// err = err2
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
// func isErrModifyPrice(err error) bool {
|
||||
// if errExt, ok := err.(*utils.ErrorWithCode); ok && errExt.IntCode() == 1 {
|
||||
// for _, v := range []string{
|
||||
// "无法修改价格",
|
||||
// "sku_参加营销活动",
|
||||
// } {
|
||||
// if strings.Index(errExt.ErrMsg(), v) >= 0 {
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) RefreshStoresAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool, storeIDs []int) (hint string, err error) {
|
||||
// return hint, err
|
||||
// }
|
||||
|
||||
// ///////////
|
||||
// func genSkuParamsFromStoreSkuInfo(pricePercentage int, storeSku *tStoreSkuFullInfo) (params map[string]interface{}) {
|
||||
// price := jxutils.CaculateSkuVendorPrice(storeSku.Price, pricePercentage, storeSku.CatPricePercentage)
|
||||
// params = map[string]interface{}{
|
||||
// "name": utils.LimitMixedStringLen(jxutils.ComposeSkuName(storeSku.Prefix, storeSku.Name, storeSku.Comment, storeSku.Unit, storeSku.SpecQuality, storeSku.SpecUnit, 0), ebaiapi.MaxSkuNameByteCount),
|
||||
// "left_num": model.MaxStoreSkuStockQty,
|
||||
// "category_id": storeSku.CatEbaiID,
|
||||
// "predict_cat": 0, // 不使用推荐类目
|
||||
// "cat1_id": getEbaiCat(storeSku.EbaiCat1ID, 1),
|
||||
// "cat2_id": getEbaiCat(storeSku.EbaiCat2ID, 2),
|
||||
// "cat3_id": getEbaiCat(storeSku.EbaiCat3ID, 3),
|
||||
// "weight": storeSku.Weight,
|
||||
// "photos": []map[string]interface{}{
|
||||
// map[string]interface{}{
|
||||
// "is_master": true,
|
||||
// "url": storeSku.Img,
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// if storeSku.DescImgEbai != "" {
|
||||
// params["rtf"] = storeSku.DescImgEbai
|
||||
// }
|
||||
// if storeSku.EbaiSyncStatus&(model.SyncFlagPriceMask|model.SyncFlagNewMask) != 0 {
|
||||
// params["sale_price"] = price
|
||||
// }
|
||||
// if storeSku.EbaiSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 {
|
||||
// params["status"] = jxSkuStatus2Ebai(jxutils.MergeSkuStatus(storeSku.SkuStatus, storeSku.Status))
|
||||
// }
|
||||
// // todo 饿百如果给的UPC是空要报错,但如果我要删除UPC怎么弄?
|
||||
// // if storeSku.Upc != "" {
|
||||
// // params["upc"] = storeSku.Upc
|
||||
// // }
|
||||
// return params
|
||||
// }
|
||||
|
||||
// // 从饿百同步分类信息到本地
|
||||
// // 些函数执行后:
|
||||
// // 远程有与本地有的条目会关联(并置标记,下次同步会刷新远程)
|
||||
// // 远程没有本地有的条目会标记新增
|
||||
// // 远程有本地没有的条目不做处理
|
||||
// func (p *PurchaseHandler) SyncLocalStoreCategory(db *dao.DaoDB, storeID int, userName string) (err error) {
|
||||
// globals.SugarLogger.Debugf("ebai SyncLocalStoreCategory storeID:%d, userName:%s", storeID, userName)
|
||||
|
||||
// sql := `
|
||||
// SELECT t2.*, t1.id cat_id, t1.name, t1.parent_id, t1.level, t1.type, t1.seq
|
||||
// FROM sku_category t1
|
||||
// LEFT JOIN store_sku_category_map t2 ON t1.id = t2.category_id AND t2.store_id = ? AND (t2.deleted_at = ?)
|
||||
// WHERE t1.deleted_at = ?
|
||||
// ORDER BY t1.level
|
||||
// `
|
||||
// var catList []*tStoreCatInfo
|
||||
// if err = dao.GetRows(db, &catList, sql, storeID, utils.DefaultTimeValue, utils.DefaultTimeValue); err == nil {
|
||||
// cat1Map := map[string]*tStoreCatInfo{}
|
||||
// for _, v := range catList {
|
||||
// v.Name = formatCatName(v.Name)
|
||||
// if v.Level == 1 {
|
||||
// cat1 := cat1Map[v.Name]
|
||||
// if cat1 == nil {
|
||||
// cat1Map[v.Name] = v
|
||||
// cat1Map[utils.Int2Str(v.CatID)] = v
|
||||
// v.Children = make(map[string]*tStoreCatInfo)
|
||||
// }
|
||||
// } else {
|
||||
// cat1 := cat1Map[utils.Int2Str(v.ParentID)]
|
||||
// if cat1 == nil {
|
||||
// panic(fmt.Sprintf("can not find category, id:%d", v.ParentID))
|
||||
// }
|
||||
// cat1.Children[v.Name] = v
|
||||
// }
|
||||
// v.EbaiSyncStatus |= model.SyncFlagNewMask
|
||||
// }
|
||||
// result, err2 := api.EbaiAPI.ShopCategoryGet(utils.Int2Str(storeID))
|
||||
// if err = err2; err == nil {
|
||||
// dao.Begin(db)
|
||||
// defer func() {
|
||||
// dao.Rollback(db)
|
||||
// }()
|
||||
// // globals.SugarLogger.Debug(utils.Format4Output(cat1Map, false))
|
||||
// if err = p.processLocalCatByRemote(db, storeID, cat1Map, result, userName); err == nil {
|
||||
// err = p.updateLocalCatAsNew(db, cat1Map, userName)
|
||||
// }
|
||||
// if err == nil {
|
||||
// dao.Commit(db)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
// // 从本地同步分类信息到饿百
|
||||
// // 测试过程中出现过,父分类创建成功后马上创建子分类会报没有父分类错
|
||||
// func (p *PurchaseHandler) SyncStoreCategory(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync bool) (hint string, err error) {
|
||||
// userName := ctx.GetUserName()
|
||||
// globals.SugarLogger.Debugf("ebai SyncStoreCategory storeID:%d, userName:%s", storeID, userName)
|
||||
|
||||
// db := dao.GetDB()
|
||||
// rootTask := tasksch.NewSeqTask("ebai SyncStoreCategory", ctx,
|
||||
// func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
// level := step + 1
|
||||
// sql := `
|
||||
// SELECT t2.*, t1.name, t1.parent_id, t1.level, t1.type, t1.seq, t2p.ebai_id parent_ebai_id
|
||||
// FROM sku_category t1
|
||||
// LEFT JOIN sku_category t1p ON t1.parent_id = t1p.id
|
||||
// JOIN store_sku_category_map t2 ON t1.id = t2.category_id AND t2.store_id = ? AND t2.ebai_sync_status <> 0
|
||||
// LEFT JOIN store_sku_category_map t2p ON t1p.id = t2p.category_id AND t2p.store_id = ? AND t2p.deleted_at = ?
|
||||
// WHERE t1.level = ? AND t1.deleted_at = ?
|
||||
// `
|
||||
// var catList []*tStoreCatInfo
|
||||
// sqlParams := []interface{}{
|
||||
// storeID,
|
||||
// storeID,
|
||||
// utils.DefaultTimeValue,
|
||||
// level,
|
||||
// utils.DefaultTimeValue,
|
||||
// }
|
||||
// if err = dao.GetRows(db, &catList, sql, sqlParams...); err == nil {
|
||||
// if len(catList) > 0 {
|
||||
// strStoreID := utils.Int2Str(storeID)
|
||||
// task := tasksch.NewParallelTask("SyncStoreCategory", nil, ctx,
|
||||
// func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// updateFields := []string{model.FieldEbaiSyncStatus}
|
||||
// catInfo := batchItemList[0].(*tStoreCatInfo)
|
||||
// // globals.SugarLogger.Debug(utils.Format4Output(catInfo, false))
|
||||
// if catInfo.EbaiSyncStatus&model.SyncFlagDeletedMask != 0 { // 删除
|
||||
// if catInfo.EbaiSyncStatus&model.SyncFlagNewMask == 0 && catInfo.EbaiID != 0 {
|
||||
// if globals.EnableEbaiStoreWrite {
|
||||
// if err = api.EbaiAPI.ShopCategoryDelete(strStoreID, catInfo.EbaiID); ebaiapi.IsErrCategoryNotExist(err) {
|
||||
// err = nil
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else if catInfo.EbaiSyncStatus&model.SyncFlagNewMask != 0 { // 新增
|
||||
// if globals.EnableEbaiStoreWrite {
|
||||
// catName := formatCatName(catInfo.Name)
|
||||
// catInfo.EbaiID, err = api.EbaiAPI.ShopCategoryCreate(strStoreID, catInfo.ParentEbaiID, catName, jxCatSeq2Ebai(catInfo.Seq))
|
||||
// if ebaiapi.IsErrCategoryExist(err) {
|
||||
// if catInfo.EbaiID = api.EbaiAPI.GetEbaiCatIDFromName(strStoreID, catName); catInfo.EbaiID > 0 {
|
||||
// err = nil
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// catInfo.EbaiID = jxutils.GenFakeID()
|
||||
// }
|
||||
// if err == nil {
|
||||
// updateFields = append(updateFields, model.FieldEbaiID)
|
||||
// }
|
||||
// } else if catInfo.EbaiSyncStatus&model.SyncFlagModifiedMask != 0 { // 修改
|
||||
// if globals.EnableEbaiStoreWrite {
|
||||
// err = api.EbaiAPI.ShopCategoryUpdate(strStoreID, catInfo.EbaiID, formatCatName(catInfo.Name), jxCatSeq2Ebai(catInfo.Seq))
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// db2 := dao.GetDB()
|
||||
// catInfo.EbaiSyncStatus = 0
|
||||
// _, err = dao.UpdateEntity(db2, &catInfo.StoreSkuCategoryMap, updateFields...)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, catList)
|
||||
// rootTask.AddChild(task).Run()
|
||||
// _, err = task.GetResult(0)
|
||||
// }
|
||||
// }
|
||||
// return nil, err
|
||||
// }, 2)
|
||||
// tasksch.AddChild(parentTask, rootTask).Run()
|
||||
// if !isAsync {
|
||||
// _, err = rootTask.GetResult(0)
|
||||
// }
|
||||
// return rootTask.ID, err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) processLocalCatByRemote(db *dao.DaoDB, storeID int, localCatMap map[string]*tStoreCatInfo, remoteCatList []*ebaiapi.CategoryInfo, userName string) (err error) {
|
||||
// if localCatMap == nil || remoteCatList == nil {
|
||||
// return nil
|
||||
// }
|
||||
// for _, v := range remoteCatList {
|
||||
// jxCat := localCatMap[v.Name]
|
||||
// if jxCat == nil { // 远程有,本地没有,非法类别
|
||||
// // globals.SugarLogger.Debug(v.Name)
|
||||
// // globals.SugarLogger.Debug(utils.Format4Output(localCatMap, false))
|
||||
// } else {
|
||||
// if jxCat.EbaiID != v.CategoryID {
|
||||
// if jxCat.ID == 0 { // 远程有,本门店没有
|
||||
// globals.SugarLogger.Debug(jxCat.CatID)
|
||||
// err = dao.AddStoreCategoryMap(db, storeID, jxCat.CatID, model.VendorIDEBAI, utils.Int64ToStr(v.CategoryID), model.SyncFlagModifiedMask, userName)
|
||||
// } else { // 远程有,本门店有,但ID信息不一致
|
||||
// _, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, &jxCat.StoreSkuCategoryMap, map[string]interface{}{
|
||||
// model.FieldEbaiID: v.CategoryID,
|
||||
// }, userName, nil, model.FieldEbaiSyncStatus, model.SyncFlagModifiedMask)
|
||||
// }
|
||||
// } else { // 两边都有,且信息一致
|
||||
// }
|
||||
// jxCat.EbaiSyncStatus = 0
|
||||
// if err = p.processLocalCatByRemote(db, storeID, jxCat.Children, v.Children, userName); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) updateLocalCatAsNew(db *dao.DaoDB, localCatMap map[string]*tStoreCatInfo, userName string) (err error) {
|
||||
// if localCatMap == nil {
|
||||
// return nil
|
||||
// }
|
||||
// for _, v := range localCatMap {
|
||||
// if v.EbaiSyncStatus&model.SyncFlagNewMask != 0 {
|
||||
// dao.WrapUpdateULEntity(&v.StoreSkuCategoryMap, userName)
|
||||
// if _, err = dao.UpdateEntity(db, &v.StoreSkuCategoryMap); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// if err = p.updateLocalCatAsNew(db, v.Children, userName); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
@@ -1,17 +0,0 @@
|
||||
package elm
|
||||
|
||||
// func (p *PurchaseHandler) SyncStoreCategory(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync bool) (hint string, err error) {
|
||||
// return "", nil
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// return hint, err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) RefreshStoresAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool, storeIDs []int) (hint string, err error) {
|
||||
// return hint, err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// return hint, err
|
||||
// }
|
||||
@@ -262,9 +262,9 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
}
|
||||
}
|
||||
for _, actStoreSkuList := range vendorActInfoMap {
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList, model.SyncFlagModifiedMask)...)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList, model.SyncFlagModifiedMask)...)
|
||||
}
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
|
||||
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
|
||||
} else if model.IsSyncStatusNew(act.SyncStatus) {
|
||||
if act.VendorActID, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil {
|
||||
if act.VendorActID != "" {
|
||||
@@ -273,15 +273,15 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
}
|
||||
return err
|
||||
}
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList4Create, model.SyncFlagNewMask)...)
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask))
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList4Create, model.SyncFlagNewMask)...)
|
||||
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagNewMask))
|
||||
} else if model.IsSyncStatusUpdate(act.SyncStatus) {
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(updateItems, false))
|
||||
if len(actStoreSkuList4Create) > 0 {
|
||||
if _, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil {
|
||||
return err
|
||||
}
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList4Create, model.SyncFlagNewMask)...)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, actStoreSkuList4Create, model.SyncFlagNewMask)...)
|
||||
}
|
||||
for vendorActID := range deleteActInfoMap {
|
||||
if vendorActID != "" {
|
||||
@@ -295,10 +295,10 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
return err
|
||||
}
|
||||
}
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(deleteActInfoMap[vendorActID], model.SyncFlagDeletedMask)...)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, deleteActInfoMap[vendorActID], model.SyncFlagDeletedMask)...)
|
||||
}
|
||||
if err == nil {
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
|
||||
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -1,191 +0,0 @@
|
||||
package jd
|
||||
|
||||
// // 京东到家,以有库存表示关注(认领)
|
||||
// func (p *PurchaseHandler) syncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, db *dao.DaoDB, storeID int, storeSkus []*dao.StoreSkuSyncInfo, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// globals.SugarLogger.Debugf("jd syncStoreSkus, storeID:%d", storeID)
|
||||
// storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDJD)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// batchSize := jdapi.MaxStoreSkuBatchSize
|
||||
// // storeSkusLen := len(storeSkus)
|
||||
// // if storeSkusLen < jdapi.MaxStoreSkuBatchSize/2 {
|
||||
// // batchSize = 1
|
||||
// // } else if storeSkusLen < jdapi.MaxStoreSkuBatchSize {
|
||||
// // batchSize = (storeSkusLen + 1) / 2
|
||||
// // } else if storeSkusLen < jdapi.MaxStoreSkuBatchSize*2 {
|
||||
// // batchSize = (storeSkusLen + 2) / 3
|
||||
// // }
|
||||
// task := tasksch.NewParallelTask("syncStoreSkus京东", tasksch.NewParallelConfig().SetBatchSize(batchSize).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
// func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// doWork := func(batchItemList []interface{}) (isPartialFailed bool, err error) {
|
||||
// var skuPriceInfoList []*jdapi.SkuPriceInfo
|
||||
// var skuVendibilityList []*jdapi.StockVendibility
|
||||
// var skuStockList []*jdapi.SkuStock
|
||||
// vendorSkuID4Price := ""
|
||||
// vendorSkuID4Qty := ""
|
||||
// stationNo := storeDetail.VendorStoreID
|
||||
// var batchBindIDs []int
|
||||
// for _, v := range batchItemList {
|
||||
// storeSku := v.(*dao.StoreSkuSyncInfo)
|
||||
// alreadyAddStock := false
|
||||
// if storeSku.StoreSkuSyncStatus&model.SyncFlagChangedMask != 0 || storeSku.BindID == 0 || storeSku.NameID == 0 {
|
||||
// if storeSku.BindID > 0 {
|
||||
// batchBindIDs = append(batchBindIDs, storeSku.BindID)
|
||||
// }
|
||||
// if storeSku.StoreSkuSyncStatus&(model.SyncFlagDeletedMask|model.SyncFlagNewMask) != 0 || storeSku.BindID == 0 || storeSku.NameID == 0 { // 关注或取消关注
|
||||
// stock := &jdapi.SkuStock{
|
||||
// OutSkuId: utils.Int2Str(storeSku.SkuID),
|
||||
// StockQty: model.MaxStoreSkuStockQty,
|
||||
// }
|
||||
// if storeSku.StoreSkuSyncStatus&model.SyncFlagDeletedMask != 0 || storeSku.DeletedAt != utils.DefaultTimeValue || storeSku.BindID == 0 || storeSku.NameID == 0 {
|
||||
// stock.StockQty = 0
|
||||
// } else {
|
||||
// alreadyAddStock = true
|
||||
// }
|
||||
// if stock.StockQty != 0 || !storeskulock.IsJdStoreSkuLocked(stationNo, storeSku.JdID) {
|
||||
// vendorSkuID4Qty = storeSku.VendorSkuID
|
||||
// skuStockList = append(skuStockList, stock)
|
||||
// }
|
||||
// }
|
||||
// if storeSku.StoreSkuSyncStatus&(model.SyncFlagPriceMask|model.SyncFlagNewMask) != 0 {
|
||||
// vendorSkuID4Price = storeSku.VendorSkuID
|
||||
// pricePercentage := jxutils.GetPricePercentage(storeDetail.PricePercentagePackObj, int(storeSku.Price), int(storeDetail.PricePercentage))
|
||||
// skuPriceInfoList = append(skuPriceInfoList, &jdapi.SkuPriceInfo{
|
||||
// OutSkuId: utils.Int2Str(storeSku.SkuID),
|
||||
// Price: constrainPrice(jxutils.CaculateSkuVendorPrice(int(storeSku.Price), pricePercentage, storeSku.CatPricePercentage)),
|
||||
// })
|
||||
// }
|
||||
// if storeSku.StoreSkuSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 {
|
||||
// vendibility := &jdapi.StockVendibility{
|
||||
// OutSkuId: utils.Int2Str(storeSku.SkuID),
|
||||
// DoSale: true,
|
||||
// }
|
||||
// if storeSku.StoreSkuStatus != model.StoreSkuBindStatusNormal {
|
||||
// vendibility.DoSale = false
|
||||
// } else if !alreadyAddStock { // 如果是设置可售则自动将库存加满
|
||||
// stock := &jdapi.SkuStock{
|
||||
// OutSkuId: utils.Int2Str(storeSku.SkuID),
|
||||
// StockQty: model.MaxStoreSkuStockQty,
|
||||
// }
|
||||
// vendorSkuID4Qty = storeSku.VendorSkuID
|
||||
// skuStockList = append(skuStockList, stock)
|
||||
// }
|
||||
// if vendibility.DoSale || !storeskulock.IsJdStoreSkuLocked(stationNo, storeSku.JdID) {
|
||||
// skuVendibilityList = append(skuVendibilityList, vendibility)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// syncMask := 0
|
||||
// errList := []error{}
|
||||
// if globals.EnableJdStoreWrite {
|
||||
// // todo 以下可以优化为并行操作
|
||||
// // globals.SugarLogger.Debug(utils.Format4Output(skuVendibilityList, false), utils.Format4Output(skuPriceInfoList, false), utils.Format4Output(skuStockList, false))
|
||||
// if len(skuVendibilityList) > 0 {
|
||||
// if _, err = getAPI("").BatchUpdateVendibility(ctx.GetTrackInfo(), "", stationNo, skuVendibilityList, ctx.GetUserName()); err == nil {
|
||||
// syncMask |= model.SyncFlagSaleMask
|
||||
// } else {
|
||||
// if !isPartialFailed {
|
||||
// isPartialFailed = isErrPartialFailed(err)
|
||||
// }
|
||||
// errList = append(errList, err)
|
||||
// }
|
||||
// }
|
||||
// if (err == nil || isContinueWhenError) && len(skuStockList) > 0 {
|
||||
// if len(skuStockList) == 1 {
|
||||
// err = getAPI("").UpdateCurrentQty(ctx.GetTrackInfo(), stationNo, utils.Str2Int64WithDefault(vendorSkuID4Qty, 0), skuStockList[0].StockQty)
|
||||
// } else {
|
||||
// _, err = getAPI("").BatchUpdateCurrentQtys(ctx.GetTrackInfo(), "", stationNo, skuStockList, ctx.GetUserName())
|
||||
// }
|
||||
// if err == nil {
|
||||
// syncMask |= model.SyncFlagNewMask | model.SyncFlagDeletedMask
|
||||
// } else {
|
||||
// if !isPartialFailed {
|
||||
// isPartialFailed = isErrPartialFailed(err)
|
||||
// }
|
||||
// errList = append(errList, err)
|
||||
// }
|
||||
// }
|
||||
// if (err == nil || isContinueWhenError) && len(skuPriceInfoList) > 0 {
|
||||
// if len(skuPriceInfoList) == 1 {
|
||||
// _, err = getAPI("").UpdateStationPrice(ctx.GetTrackInfo(), utils.Str2Int64WithDefault(vendorSkuID4Price, 0), stationNo, skuPriceInfoList[0].Price)
|
||||
// } else {
|
||||
// _, err = getAPI("").UpdateVendorStationPrice(ctx.GetTrackInfo(), "", stationNo, skuPriceInfoList)
|
||||
// }
|
||||
// if err == nil {
|
||||
// syncMask |= model.SyncFlagPriceMask
|
||||
// } else {
|
||||
// if !isPartialFailed {
|
||||
// isPartialFailed = isErrPartialFailed(err)
|
||||
// }
|
||||
// // errList = append(errList, partner.NewErrorCode(err.Error(), partner.ErrCodeChangePriceFailed, model.VendorIDJD))
|
||||
// errList = append(errList, err)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if len(errList) == 0 {
|
||||
// syncMask = -1
|
||||
// }
|
||||
// if syncMask != 0 && len(batchBindIDs) > 0 {
|
||||
// // db := dao.GetDB() // 多线程问题
|
||||
// sql := `
|
||||
// UPDATE store_sku_bind t1
|
||||
// SET t1.jd_sync_status = t1.jd_sync_status & ?
|
||||
// WHERE t1.id IN (` + dao.GenQuestionMarks(len(batchBindIDs)) + ")"
|
||||
// if _, err = dao.ExecuteSQL(db, sql, ^syncMask, batchBindIDs); err != nil {
|
||||
// errList = append(errList, err)
|
||||
// }
|
||||
// }
|
||||
// if len(errList) == 1 {
|
||||
// err = errList[0]
|
||||
// } else if len(errList) > 1 {
|
||||
// err = fmt.Errorf("%v", errList)
|
||||
// }
|
||||
// return isPartialFailed, err
|
||||
// }
|
||||
// isErrPartialFailed, err := doWork(batchItemList)
|
||||
// if isErrPartialFailed && len(batchItemList) > 1 {
|
||||
// for _, v := range batchItemList {
|
||||
// doWork([]interface{}{v})
|
||||
// }
|
||||
// }
|
||||
// return nil, err
|
||||
// }, storeSkus)
|
||||
// tasksch.HandleTask(task, parentTask, false).Run()
|
||||
// if !isAsync {
|
||||
// _, err = task.GetResult(0)
|
||||
// }
|
||||
// return task.ID, err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// globals.SugarLogger.Debugf("jd SyncStoresSkus, storeID:%d, skuIDs:%v", storeID, skuIDs)
|
||||
// db := dao.GetDB()
|
||||
// storeSkus, err := dao.GetStoreSkus(db, model.VendorIDJD, storeID, skuIDs)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// return p.syncStoreSkus(ctx, parentTask, db, storeID, storeSkus, isAsync, isContinueWhenError)
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// globals.SugarLogger.Debugf("jd FullSyncStoreSkus, storeID:%d", storeID)
|
||||
// db := dao.GetDB()
|
||||
// _, err = dao.SetStoreSkuSyncStatus(db, model.VendorIDJD, []int{storeID}, nil, model.SyncFlagStoreSkuOnlyMask)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// storeSkus, err := dao.GetFullStoreSkus(db, model.VendorIDJD, storeID)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// return p.syncStoreSkus(ctx, parentTask, db, storeID, storeSkus, isAsync, isContinueWhenError)
|
||||
// }
|
||||
|
||||
// func constrainPrice(price int) int {
|
||||
// if price <= 0 {
|
||||
// price = 1
|
||||
// }
|
||||
// return price
|
||||
// }
|
||||
@@ -9,6 +9,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/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
@@ -102,6 +103,7 @@ func init() {
|
||||
|
||||
func GetMyOrders(ctx *jxcontext.Context, fromDateStr, toDateStr string, params map[string]interface{}, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
db := dao.GetDB()
|
||||
params["vendorIDs"] = string(utils.MustMarshal([]int{model.VendorIDJX}))
|
||||
tmpOrderList, totalCount, err := dao.GetOrders(db, nil, false, false, fromDateStr, toDateStr, false, nil, false, ctx.GetUserID(), params, offset, pageSize)
|
||||
if err == nil {
|
||||
pagedInfo = &model.PagedInfo{
|
||||
@@ -133,6 +135,11 @@ func GetMyOrders(ctx *jxcontext.Context, fromDateStr, toDateStr string, params m
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
func GetMyOrderCountInfo(ctx *jxcontext.Context, fromDate, toDate time.Time, statuss []int) (countInfo []*model.GoodsOrderCountInfo, err error) {
|
||||
countInfo, err = dao.GetMyOrderCountInfo(dao.GetDB(), ctx.GetUserID(), fromDate, toDate, statuss)
|
||||
return countInfo, err
|
||||
}
|
||||
|
||||
func CreateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64, createType int) (outJxOrder *JxOrderInfo, err error) {
|
||||
outJxOrder, deliveryAddress, err := generateOrder(ctx, jxOrder, addressID)
|
||||
if err != nil {
|
||||
@@ -340,13 +347,26 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
|
||||
for _, v := range skus {
|
||||
skuIDs = append(skuIDs, v.SkuID)
|
||||
}
|
||||
storeSkuList, err := dao.GetStoresSkusInfo(db, []int{jxOrder.StoreID}, skuIDs)
|
||||
|
||||
// storeSkuList, err := dao.GetStoresSkusInfo(db, []int{jxOrder.StoreID}, skuIDs)
|
||||
// if err != nil {
|
||||
// return nil, nil, err
|
||||
// }
|
||||
// storeSkuMap := make(map[int]*model.StoreSkuBind)
|
||||
// for _, v := range storeSkuList {
|
||||
// storeSkuMap[v.SkuID] = v
|
||||
// }
|
||||
storeSkuInfo, err := cms.GetStoreSkus(ctx, jxOrder.StoreID, skuIDs, true, "", true, false, map[string]interface{}{
|
||||
"actVendorID": model.VendorIDJX,
|
||||
}, 0, model.UnlimitedPageSize)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
storeSkuMap := make(map[int]*model.StoreSkuBind)
|
||||
for _, v := range storeSkuList {
|
||||
storeSkuMap[v.SkuID] = v
|
||||
storeSkuMap := make(map[int]*cms.StoreSkuExt)
|
||||
for _, v1 := range storeSkuInfo.SkuNames {
|
||||
for _, v2 := range v1.Skus {
|
||||
storeSkuMap[v2.SkuID] = v2
|
||||
}
|
||||
}
|
||||
|
||||
skuList, err := dao.GetSkus(db, skuIDs, nil, nil, nil)
|
||||
@@ -361,6 +381,7 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
|
||||
outJxOrder2 := *jxOrder
|
||||
outJxOrder2.Skus = nil
|
||||
outJxOrder2.OrderPrice = 0
|
||||
outJxOrder2.Weight = 0
|
||||
outJxOrder = &outJxOrder2
|
||||
outJxOrder.StoreName = storeDetail.Name
|
||||
for _, v := range skus {
|
||||
@@ -368,20 +389,38 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
|
||||
if sku := skuMap[v.SkuID]; sku != nil {
|
||||
jxSku := &JxSkuInfo{
|
||||
SkuID: v.SkuID,
|
||||
Count: v.Count,
|
||||
Price: int64(storeSkuBind.JxPrice),
|
||||
Count: v.Count,
|
||||
SalePrice: int64(storeSkuBind.JxPrice), // todo 考虑活动价
|
||||
Weight: sku.Weight,
|
||||
Name: jxutils.ComposeSkuName(sku.Prefix, sku.Name, sku.Comment, sku.Unit, sku.SpecQuality, sku.SpecUnit, 0),
|
||||
}
|
||||
outJxOrder.Skus = append(outJxOrder.Skus, jxSku)
|
||||
outJxOrder.OrderPrice += int64(v.Count) * jxSku.SalePrice
|
||||
outJxOrder.Weight = v.Count * jxSku.Weight
|
||||
if storeSkuBind.ActPrice != 0 && storeSkuBind.ActPrice < storeSkuBind.JxPrice {
|
||||
jxSku.SalePrice = int64(storeSkuBind.ActPrice)
|
||||
jxSku.Count = 1
|
||||
|
||||
outJxOrder.Skus = append(outJxOrder.Skus, jxSku)
|
||||
outJxOrder.OrderPrice += int64(jxSku.Count) * jxSku.SalePrice
|
||||
outJxOrder.Weight += jxSku.Count * jxSku.Weight
|
||||
if v.Count-1 > 0 {
|
||||
jxSku2 := *jxSku
|
||||
jxSku2.SalePrice = jxSku.Price
|
||||
jxSku2.Count = v.Count - 1
|
||||
|
||||
jxSku = &jxSku2
|
||||
} else {
|
||||
jxSku = nil
|
||||
}
|
||||
}
|
||||
if jxSku != nil {
|
||||
outJxOrder.Skus = append(outJxOrder.Skus, jxSku)
|
||||
outJxOrder.OrderPrice += int64(jxSku.Count) * jxSku.SalePrice
|
||||
outJxOrder.Weight += jxSku.Count * jxSku.Weight
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Sort(JxSkuInfoList(outJxOrder.Skus))
|
||||
|
||||
if outJxOrder.FreightPrice, _, err = delivery.CalculateDeliveryFee(dao.GetDB(), jxOrder.StoreID, "",
|
||||
jxutils.StandardCoordinate2Int(deliveryAddress.Lng), jxutils.StandardCoordinate2Int(deliveryAddress.Lat),
|
||||
model.CoordinateTypeMars, outJxOrder.Weight, checkTime); err == nil {
|
||||
@@ -404,7 +443,7 @@ func jxOrder2GoodsOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, deliveryAd
|
||||
ConsigneeName: deliveryAddress.ConsigneeName,
|
||||
ConsigneeMobile: deliveryAddress.ConsigneeMobile,
|
||||
ConsigneeMobile2: deliveryAddress.ConsigneeMobile,
|
||||
ConsigneeAddress: deliveryAddress.DetailAddress,
|
||||
ConsigneeAddress: fmt.Sprintf("%s%s", deliveryAddress.Address, deliveryAddress.DetailAddress),
|
||||
CoordinateType: model.CoordinateTypeMars,
|
||||
ConsigneeLng: jxutils.StandardCoordinate2Int(deliveryAddress.Lng),
|
||||
ConsigneeLat: jxutils.StandardCoordinate2Int(deliveryAddress.Lat),
|
||||
@@ -419,7 +458,7 @@ func jxOrder2GoodsOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, deliveryAd
|
||||
}
|
||||
order.OrderCreatedAt = order.StatusTime
|
||||
order.VendorUserID = order.UserID
|
||||
if jxOrder.ExpectedDeliveredTimestamp == 0 {
|
||||
if jxOrder.ExpectedDeliveredTimestamp != 0 {
|
||||
order.ExpectedDeliveredTime = utils.Timestamp2Time(jxOrder.ExpectedDeliveredTimestamp)
|
||||
order.BusinessType = model.BusinessTypeDingshida
|
||||
} else {
|
||||
|
||||
@@ -163,34 +163,34 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
err = func() (err error) {
|
||||
if model.IsSyncStatusDelete(act.SyncStatus) {
|
||||
canceledList, err2 := cancelSkuAct(ctx, nil, actStoreSkuList)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(canceledList, model.SyncFlagModifiedMask)...)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, canceledList, model.SyncFlagModifiedMask)...)
|
||||
if err = err2; err == nil {
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
|
||||
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
|
||||
}
|
||||
} else if model.IsSyncStatusNew(act.SyncStatus) {
|
||||
createdList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(createdList, model.SyncFlagNewMask)...)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, createdList, model.SyncFlagNewMask)...)
|
||||
if err = err2; err == nil {
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask))
|
||||
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagNewMask))
|
||||
}
|
||||
} else if model.IsSyncStatusUpdate(act.SyncStatus) {
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(updateItems, false))
|
||||
if len(actStoreSkuList4Create) > 0 {
|
||||
addedList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(addedList, model.SyncFlagNewMask)...)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, addedList, model.SyncFlagNewMask)...)
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(actStoreSkuList4Delete) > 0 {
|
||||
deletedList, err2 := cancelSkuAct(ctx, nil, actStoreSkuList4Delete)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(deletedList, model.SyncFlagDeletedMask)...)
|
||||
updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, deletedList, model.SyncFlagDeletedMask)...)
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagModifiedMask))
|
||||
updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask))
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -428,7 +428,13 @@ func (c *PurchaseHandler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptI
|
||||
// err = api.MtwmAPI.OrderReceived(utils.Str2Int64(order.VendorOrderID))
|
||||
err = api.MtwmAPI.OrderConfirm(utils.Str2Int64(order.VendorOrderID))
|
||||
if err != nil {
|
||||
globals.SugarLogger.Warnf("mtwm AcceptOrRefuseOrder orderID:%s failed with err:%v", order.VendorOrderID, err)
|
||||
if utils.IsErrMatch(err, utils.Int2Str(mtwmapi.ErrCodeOpFailed), []string{
|
||||
"订单已经确认过了",
|
||||
}) {
|
||||
err = nil
|
||||
} else {
|
||||
globals.SugarLogger.Warnf("mtwm AcceptOrRefuseOrder orderID:%s failed with err:%v", order.VendorOrderID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
// if err == nil {
|
||||
|
||||
@@ -42,9 +42,9 @@ func (c *PurchaseHandler) isAfsMsg(msg *mtwmapi.CallbackMsg) bool {
|
||||
if msg.Cmd == mtwmapi.MsgTypeOrderRefund || msg.Cmd == mtwmapi.MsgTypeOrderPartialRefund {
|
||||
// refundData := msg.Data.(*mtwmapi.CallbackRefundInfo)
|
||||
orderID := utils.Str2Int64(GetOrderIDFromMsg(msg))
|
||||
orderInfo, err := api.MtwmAPI.OrderGetOrderDetail2(orderID, false)
|
||||
status, err := api.MtwmAPI.OrderViewStatus(orderID)
|
||||
if err == nil {
|
||||
return orderInfo.Status == int(utils.Str2Int64(mtwmapi.OrderStatusFinished))
|
||||
return utils.Int2Str(status) == mtwmapi.OrderStatusFinished
|
||||
}
|
||||
globals.SugarLogger.Warnf("mtwm isAfsMsg OrderGetOrderDetail2 orderID:%d failed with error:%v", orderID, err)
|
||||
}
|
||||
@@ -142,7 +142,7 @@ func (c *PurchaseHandler) onAfsOrderMsg(msg *mtwmapi.CallbackMsg) (retVal *mtwma
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) createAfsOrder(orderData url.Values) (afsOrder *model.AfsOrder) {
|
||||
afsOrder, err := partner.CurOrderManager.CreateAfsOrderFromOrder(orderData.Get("refund_id"), model.VendorIDMTWM)
|
||||
afsOrder, err := partner.CurOrderManager.CreateAfsOrderFromOrder(orderData.Get("order_id"), model.VendorIDMTWM)
|
||||
if err == nil {
|
||||
afsOrder.AfsOrderID = orderData.Get("refund_id")
|
||||
afsOrder.AfsCreatedAt = utils.Timestamp2Time(utils.Str2Int64(orderData.Get("timestamp")))
|
||||
|
||||
@@ -1,442 +0,0 @@
|
||||
package mtwm
|
||||
|
||||
// // hint,如果是异步,返回的是任务ID,如果是同步,返回是本次需要同步的目录数
|
||||
// func (p *PurchaseHandler) SyncStoreCategory(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync bool) (hint string, err error) {
|
||||
// globals.SugarLogger.Debugf("mtwm SyncStoreCategory storeID:%d, userName:%s", storeID, ctx.GetUserName())
|
||||
// num := 0
|
||||
// db := dao.GetDB()
|
||||
// storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDMTWM)
|
||||
// if err != nil {
|
||||
// return hint, err
|
||||
// }
|
||||
// vendorStoreID := storeDetail.VendorStoreID
|
||||
// rootTask := tasksch.NewSeqTask("美团外卖SyncStoreCategory step1", ctx,
|
||||
// func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
// level := step + 1
|
||||
// catList, err := dao.GetStoreCategories(db, model.VendorIDMTWM, storeID, level)
|
||||
// if len(catList) > 0 {
|
||||
// num += len(catList)
|
||||
// task := tasksch.NewParallelTask(fmt.Sprintf("美团外卖SyncStoreCategory step2, level=%d", level), nil, ctx,
|
||||
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// updateFields := []string{dao.GetSyncStatusStructField(model.VendorNames[model.VendorIDMTWM])}
|
||||
// catInfo := batchItemList[0].(*dao.SkuStoreCatInfo)
|
||||
// storeCatMap := &model.StoreSkuCategoryMap{}
|
||||
// storeCatMap.ID = catInfo.MapID
|
||||
// if catInfo.StoreCatSyncStatus&model.SyncFlagDeletedMask != 0 { // 删除
|
||||
// if catInfo.StoreCatSyncStatus&model.SyncFlagNewMask == 0 && !dao.IsVendorThingIDEmpty(catInfo.VendorCatID) {
|
||||
// globals.SugarLogger.Debugf("RetailCatDelete vendorStoreID:%s, MtwmID:%s", vendorStoreID, catInfo.VendorCatID)
|
||||
// if globals.EnableMtwmStoreWrite {
|
||||
// if err = api.MtwmAPI.RetailCatDelete(vendorStoreID, catInfo.VendorCatID); mtwmapi.IsErrCategoryNotExist(err) {
|
||||
// err = nil
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else if catInfo.StoreCatSyncStatus&(model.SyncFlagNewMask|model.SyncFlagStoreSkuModifiedMask) != 0 { // 新增或修改
|
||||
// catName := catInfo.Name
|
||||
// subCatName := ""
|
||||
// originName := ""
|
||||
// if catInfo.StoreCatSyncStatus&model.SyncFlagNewMask == 0 {
|
||||
// originName = catInfo.VendorCatID
|
||||
// }
|
||||
// if level == 2 {
|
||||
// originName = catInfo.ParentCatName
|
||||
// catName = catInfo.ParentCatName
|
||||
// subCatName = catInfo.Name
|
||||
// if catInfo.StoreCatSyncStatus&model.SyncFlagNewMask == 0 {
|
||||
// originName = catInfo.VendorCatID
|
||||
// catName = catInfo.Name
|
||||
// subCatName = ""
|
||||
// }
|
||||
// }
|
||||
// if catName == "" {
|
||||
// panic("catName is empty")
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("RetailCatUpdate vendorStoreID:%s, originName:%s, catName:%s, subCatName:%s, seq:%d", vendorStoreID, originName, catName, subCatName, catInfo.Seq)
|
||||
// if globals.EnableMtwmStoreWrite {
|
||||
// if err = api.MtwmAPI.RetailCatUpdate(vendorStoreID, originName, catName, subCatName, catInfo.Seq); catInfo.StoreCatSyncStatus&model.SyncFlagNewMask != 0 && mtwmapi.IsErrCategoryExist(err) {
|
||||
// err = nil
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// storeCatMap.MtwmID = catInfo.Name
|
||||
// updateFields = append(updateFields, dao.GetVendorThingIDStructField(model.VendorNames[model.VendorIDMTWM]))
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// db2 := dao.GetDB()
|
||||
// storeCatMap.MtwmSyncStatus = 0
|
||||
// _, err = dao.UpdateEntity(db2, storeCatMap, updateFields...)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, catList)
|
||||
// rootTask.AddChild(task).Run()
|
||||
// _, err = task.GetResult(0)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, 2)
|
||||
// tasksch.AddChild(parentTask, rootTask).Run()
|
||||
// if !isAsync {
|
||||
// hint = utils.Int2Str(num)
|
||||
// _, err = rootTask.GetResult(0)
|
||||
// } else {
|
||||
// hint = rootTask.ID
|
||||
// }
|
||||
// return hint, err
|
||||
// }
|
||||
|
||||
// // 此函数根据门店商品信息重建分类信息
|
||||
// // 远程有,本地无, --> 删除远程
|
||||
// // 远程有,本地有,映射无, --> 添加关联
|
||||
// // 远程有,本地有,映射有, --> 不处理
|
||||
// // 远程无,本地有,映射无, --> 添加本地
|
||||
// // 远程无,本地有,映射有, --> 同步标记改为新增
|
||||
// // hint,如果是异步,返回的是任务ID,如果是同步,返回是本次需要同步的目录数
|
||||
// func (p *PurchaseHandler) SyncLocalStoreCategory(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, isCheckRemote bool, skuIDs []int) (hint string, err error) {
|
||||
// globals.SugarLogger.Debugf("mtwm SyncLocalStoreCategory storeID:%d, userName:%s", storeID, ctx.GetUserName())
|
||||
// if db == nil {
|
||||
// db = dao.GetDB()
|
||||
// }
|
||||
// catMap := make([]map[string]*dao.SkuStoreCatInfo, 2)
|
||||
// for i := 0; i < 2; i++ {
|
||||
// catMap[i] = make(map[string]*dao.SkuStoreCatInfo)
|
||||
// localCats, err := dao.GetSkusCategories(db, model.VendorIDMTWM, storeID, skuIDs, i+1)
|
||||
// // globals.SugarLogger.Debug(utils.Format4Output(localCats, false))
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// for _, cat := range localCats {
|
||||
// catMap[i][cat.ParentCatName+"/"+cat.Name] = cat
|
||||
// }
|
||||
// }
|
||||
// identityCatMap := make(map[int]int) // 这里面表示远程有,本地有,且完全相同,可擦掉本地的修改标记
|
||||
// if isCheckRemote {
|
||||
// storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDMTWM)
|
||||
// if err != nil {
|
||||
// return hint, err
|
||||
// }
|
||||
// vendorStoreID := storeDetail.VendorStoreID
|
||||
// remoteCats, err := api.MtwmAPI.RetailCatList(vendorStoreID)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// if err = TranverseRemoteCatList("", remoteCats, func(level int, parentCatName, catName string) (err error) {
|
||||
// localCat := catMap[level-1][parentCatName+"/"+catName]
|
||||
// // globals.SugarLogger.Debug(parentCatName, " ", catName, " ", localCat)
|
||||
// if localCat == nil { // 本地分类就没有这个名字,直接删除
|
||||
// if globals.EnableMtwmStoreWrite {
|
||||
// globals.SugarLogger.Debugf("RetailCatDelete2 vendorStoreID:%s, catName:%s", vendorStoreID, catName)
|
||||
// if err = api.MtwmAPI.RetailCatDelete(vendorStoreID, catName); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// } else { // 本地分类有这个名字
|
||||
// if localCat.MapID == 0 { // 本地映射没有
|
||||
// localCat.MapID = -1 // 表示远程有同名的
|
||||
// } else { // 本地映射有
|
||||
// identityCatMap[localCat.MapID] = 1
|
||||
// }
|
||||
// }
|
||||
// return nil
|
||||
// }); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// }
|
||||
// dao.Begin(db)
|
||||
// defer func() {
|
||||
// dao.Rollback(db)
|
||||
// }()
|
||||
// num := 0
|
||||
// for i := 0; i < 2; i++ {
|
||||
// for _, v := range catMap[i] {
|
||||
// if v.MapID == -1 || v.MapID == 0 { // 本地缺失
|
||||
// mtwmSyncStatus := int8(model.SyncFlagNewMask)
|
||||
// if v.MapID == -1 { // 远程有同名的,只是简单增加一条本地记录关联
|
||||
// mtwmSyncStatus = 0
|
||||
// }
|
||||
// catMap := &model.StoreSkuCategoryMap{
|
||||
// StoreID: storeID,
|
||||
// CategoryID: v.ID,
|
||||
// MtwmID: v.Name,
|
||||
// MtwmSyncStatus: mtwmSyncStatus,
|
||||
// EbaiSyncStatus: model.SyncFlagNewMask,
|
||||
// ElmSyncStatus: model.SyncFlagNewMask,
|
||||
// WscSyncStatus: model.SyncFlagNewMask,
|
||||
// }
|
||||
// num++
|
||||
// dao.WrapAddIDCULDEntity(catMap, ctx.GetUserName())
|
||||
// if err = dao.CreateEntity(db, catMap); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// } else {
|
||||
// if dao.IsVendorThingIDEmpty(v.VendorCatID) {
|
||||
// num++
|
||||
// }
|
||||
// if isCheckRemote {
|
||||
// catMap := &model.StoreSkuCategoryMap{
|
||||
// MtwmSyncStatus: model.SyncFlagNewMask,
|
||||
// }
|
||||
// updateFields := []string{
|
||||
// model.FieldUpdatedAt,
|
||||
// model.FieldLastOperator,
|
||||
// model.FieldMtwmSyncStatus,
|
||||
// }
|
||||
// if identityCatMap[v.MapID] == 1 { // 如果一样,则要刷新ID(对于MTWM其实就是名字)
|
||||
// catMap.MtwmID = v.Name
|
||||
// catMap.MtwmSyncStatus = 0
|
||||
// updateFields = append(updateFields, model.FieldMtwmID)
|
||||
// }
|
||||
// catMap.ID = v.MapID
|
||||
// num++
|
||||
// dao.WrapUpdateULEntity(catMap, ctx.GetUserName())
|
||||
// if _, err = dao.UpdateEntity(db, catMap, updateFields...); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// dao.Commit(db)
|
||||
// return utils.Int2Str(num), err
|
||||
// }
|
||||
|
||||
// func TranverseRemoteCatList(parentCatName string, remoteCats []*mtwmapi.RetailCategoryInfo, handler func(level int, parentCatName, catName string) error) (err error) {
|
||||
// for _, remoteCat := range remoteCats {
|
||||
// name := utils.Interface2String(remoteCat.Name)
|
||||
// TranverseRemoteCatList(name, remoteCat.Children, handler)
|
||||
// if err = handler(remoteCat.Level, parentCatName, name); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// db := dao.GetDB()
|
||||
// storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDMTWM)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// return p.syncStoreSkus(ctx, parentTask, storeDetail, skuIDs, isAsync, isContinueWhenError)
|
||||
// }
|
||||
|
||||
// // hint,如果是异步,返回的是任务ID,如果是同步,返回是本次需要同步的目录数
|
||||
// func (p *PurchaseHandler) syncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeDetail *dao.StoreDetail, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// storeID := storeDetail.Store.ID
|
||||
// globals.SugarLogger.Debugf("mtwm SyncStoreSkus storeID:%d, skuIDs:%v, isContinueWhenError:%t, userName:%s", storeID, skuIDs, isContinueWhenError, ctx.GetUserName())
|
||||
// db := dao.GetDB()
|
||||
// for i := 0; i < 3; i++ { // 最多重试三次
|
||||
// if hint, err = p.SyncLocalStoreCategory(ctx, db, storeID, false, skuIDs); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// if hint != "0" {
|
||||
// if hint, err = p.SyncStoreCategory(ctx, parentTask, storeID, false); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// }
|
||||
// if hint == "0" {
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// if hint != "0" {
|
||||
// return "", errors.New("同步门店商品所需目录失败")
|
||||
// }
|
||||
// skus, err := dao.GetStoreSkus(db, model.VendorIDMTWM, storeID, skuIDs)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// // globals.SugarLogger.Debug(utils.Format4Output(skus, false))
|
||||
// vendorStoreID := storeDetail.VendorStoreID
|
||||
// rootTask := tasksch.NewParallelTask("美团外卖SyncStoreSkus", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
// func(rootTask *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// foodDataList := make([]map[string]interface{}, len(batchItemList))
|
||||
// // for k, v := range batchItemList {
|
||||
// v := batchItemList[0]
|
||||
// skuItem := v.(*dao.StoreSkuSyncInfo)
|
||||
// updateFields := []string{model.FieldMtwmSyncStatus}
|
||||
// storeSkuBind := &model.StoreSkuBind{}
|
||||
// storeSkuBind.ID = skuItem.BindID
|
||||
// if skuItem.NameID == 0 || skuItem.StoreSkuSyncStatus&model.SyncFlagDeletedMask != 0 {
|
||||
// if skuItem.StoreSkuSyncStatus&model.SyncFlagNewMask == 0 && !dao.IsVendorThingIDEmpty(skuItem.VendorSkuID) {
|
||||
// if globals.EnableMtwmStoreWrite {
|
||||
// if err = api.MtwmAPI.RetailDelete(ctx.GetTrackInfo(), vendorStoreID, skuItem.VendorSkuID); mtwmapi.IsErrSkuNotExist(err) {
|
||||
// err = nil
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// if utils.IsTimeZero(storeSkuBind.DeletedAt) {
|
||||
// storeSkuBind.DeletedAt = time.Now()
|
||||
// updateFields = append(updateFields, model.FieldDeletedAt)
|
||||
// }
|
||||
// if !dao.IsVendorThingIDEmpty(skuItem.VendorSkuID) {
|
||||
// storeSkuBind.MtwmID = 0
|
||||
// updateFields = append(updateFields, model.FieldMtwmID)
|
||||
// }
|
||||
// }
|
||||
// } else if skuItem.StoreSkuSyncStatus&(model.SyncFlagStoreSkuModifiedMask|model.SyncFlagNewMask) != 0 {
|
||||
// foodData := make(map[string]interface{})
|
||||
// foodDataList[0] = foodData
|
||||
// foodData[mtwmapi.KeyAppFoodCode] = utils.Int2Str(skuItem.SkuID)
|
||||
// skus := []map[string]interface{}{
|
||||
// map[string]interface{}{
|
||||
// "sku_id": foodData[mtwmapi.KeyAppFoodCode],
|
||||
// },
|
||||
// }
|
||||
// foodData["skus"] = skus
|
||||
// shouldCallSellStatus := !(skuItem.StoreSkuSyncStatus&(model.SyncFlagModifiedMask|model.SyncFlagNewMask|model.SyncFlagPriceMask) != 0)
|
||||
// if !shouldCallSellStatus {
|
||||
// globals.SugarLogger.Debugf("mtwm SyncStoreSkus3 skuID:%d, SkuSyncStatus:%d", skuItem.SkuID, skuItem.StoreSkuSyncStatus)
|
||||
// mergeStoreSkuStatus := jxutils.MergeSkuStatus(skuItem.Status, skuItem.StoreSkuStatus)
|
||||
// if !(skuItem.StoreSkuSyncStatus&model.SyncFlagNewMask != 0 && mergeStoreSkuStatus != model.SkuStatusNormal) { // 待创建且不可售的,暂不新建
|
||||
// if skuItem.Img == "" {
|
||||
// err = fmt.Errorf("SKUNAME%d:%s没有图片,同步失败", skuItem.NameID, skuItem.Name)
|
||||
// } else {
|
||||
// pricePercentage := jxutils.GetPricePercentage(storeDetail.PricePercentagePackObj, int(skuItem.Price), int(storeDetail.PricePercentage))
|
||||
// // globals.SugarLogger.Debugf("skuID:%d, price:%d, pricePercentage:%d", skuItem.SkuID, skuItem.Price, pricePercentage)
|
||||
// // globals.SugarLogger.Debugf(utils.Format4Output(storeDetail.PricePercentagePackObj, false))
|
||||
// foodData["name"] = jxutils.ComposeSkuName(skuItem.Prefix, skuItem.Name, skuItem.Comment, skuItem.Unit, skuItem.SpecQuality, skuItem.SpecUnit, mtwmapi.MaxSkuNameCharCount)
|
||||
// foodData["description"] = skuItem.Comment
|
||||
// foodData["price"] = jxutils.IntPrice2Standard(int64(jxutils.CaculateSkuVendorPrice(int(skuItem.Price), pricePercentage, skuItem.CatPricePercentage)))
|
||||
// foodData["min_order_count"] = 1
|
||||
// foodData["unit"] = skuItem.Unit
|
||||
// foodData["box_num"] = 0
|
||||
// foodData["box_price"] = 0.0
|
||||
// foodData["category_name"] = skuItem.VendorCatID
|
||||
// foodData["is_sold_out"] = skuStatusJX2Mtwm(mergeStoreSkuStatus)
|
||||
// foodData["picture"] = skuItem.Img
|
||||
// if skuItem.DescImg != "" {
|
||||
// foodData["picture_contents"] = skuItem.DescImg
|
||||
// }
|
||||
// foodData["sequence"] = skuItem.Price
|
||||
// if skuItem.VendorVendorCatID != 0 {
|
||||
// foodData["tag_id"] = utils.Int64ToStr(skuItem.VendorVendorCatID)
|
||||
// } else {
|
||||
// // foodData["tag_id"] = utils.Int64ToStr(defVendorCatID)
|
||||
// }
|
||||
// skus[0]["spec"] = jxutils.ComposeSkuSpec(skuItem.SpecQuality, skuItem.SpecUnit)
|
||||
// skus[0]["price"] = foodData["price"]
|
||||
// skus[0]["stock"] = "*"
|
||||
// skus[0]["upc"] = skuItem.Upc
|
||||
// if foodData["tag_id"] != nil {
|
||||
// skus[0]["weight"] = skuItem.Weight // weight字段仅限服饰鞋帽、美妆、日用品、母婴、生鲜果蔬、生活超市下的便利店/超市门店品类的商家使用
|
||||
// }
|
||||
// if globals.EnableMtwmStoreWrite {
|
||||
// // err = api.MtwmAPI.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList)
|
||||
|
||||
// foodData["skus"] = string(utils.MustMarshal(skus))
|
||||
// err = api.MtwmAPI.RetailInitData(ctx.GetTrackInfo(), vendorStoreID, utils.Int2Str(skuItem.SkuID), foodData)
|
||||
// }
|
||||
// if err == nil {
|
||||
// storeSkuBind.MtwmID = int64(skuItem.SkuID)
|
||||
// updateFields = append(updateFields, model.FieldMtwmID)
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// // 暂不创建
|
||||
// updateFields = nil
|
||||
// }
|
||||
// }
|
||||
// if err != nil {
|
||||
// if isErrModifyPrice(err) {
|
||||
// shouldCallSellStatus = true
|
||||
// }
|
||||
// }
|
||||
// if shouldCallSellStatus {
|
||||
// if skuItem.StoreSkuSyncStatus&(model.SyncFlagSaleMask) != 0 {
|
||||
// globals.SugarLogger.Debugf("mtwm SyncStoreSkus4 skuID:%d, SkuSyncStatus:%d", skuItem.SkuID, skuItem.StoreSkuSyncStatus)
|
||||
// sellStatus := skuStatusJX2Mtwm(jxutils.MergeSkuStatus(skuItem.Status, skuItem.StoreSkuStatus))
|
||||
// if globals.EnableMtwmStoreWrite {
|
||||
// if _, err2 := api.MtwmAPI.RetailSkuSellStatus(ctx.GetTrackInfo(), vendorStoreID, []*mtwmapi.BareStoreFoodInfo{
|
||||
// &mtwmapi.BareStoreFoodInfo{
|
||||
// AppFoodCode: utils.Int2Str(skuItem.SkuID),
|
||||
// Skus: []*mtwmapi.BareStoreSkuInfo{
|
||||
// &mtwmapi.BareStoreSkuInfo{
|
||||
// SkuID: utils.Int2Str(skuItem.SkuID),
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }, sellStatus); err2 != nil {
|
||||
// err = err2
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// if len(updateFields) > 0 {
|
||||
// _, err = dao.UpdateEntity(db, storeSkuBind, updateFields...)
|
||||
// }
|
||||
// } else if isErrModifyPrice(err) {
|
||||
// // err = partner.NewErrorCode(err.Error(), partner.ErrCodeChangePriceFailed, model.VendorIDMTWM)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, skus)
|
||||
// if parentTask != nil {
|
||||
// parentTask.AddChild(rootTask)
|
||||
// }
|
||||
// rootTask.Run()
|
||||
// if !isAsync {
|
||||
// _, err = rootTask.GetResult(0)
|
||||
// hint = utils.Int2Str(len(skus))
|
||||
// } else {
|
||||
// hint = rootTask.ID
|
||||
// }
|
||||
// return hint, err
|
||||
// }
|
||||
|
||||
// func isErrModifyPrice(err error) bool {
|
||||
// if errExt, ok := err.(*utils.ErrorWithCode); ok && errExt.IntCode() == 1 {
|
||||
// for _, v := range []string{
|
||||
// "折扣商品原价不允许修改",
|
||||
// } {
|
||||
// if strings.Index(errExt.ErrMsg(), v) >= 0 {
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
// func (p *PurchaseHandler) RefreshStoresAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool, storeIDs []int) (hint string, err error) {
|
||||
// return hint, err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// userName := ctx.GetUserName()
|
||||
// globals.SugarLogger.Debugf("mtwm FullSyncStoreSkus storeID:%d, isContinueWhenError:%t, userName:%s", storeID, isContinueWhenError, userName)
|
||||
|
||||
// db := dao.GetDB()
|
||||
// storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDMTWM)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
|
||||
// rootTask := tasksch.NewSeqTask("美团外卖FullSyncStoreSkus", ctx,
|
||||
// func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
// switch step {
|
||||
// case 0:
|
||||
// err = p.DeleteStoreAllSkus(ctx, rootTask, storeID, storeDetail.VendorStoreID, isContinueWhenError)
|
||||
// if isContinueWhenError {
|
||||
// err = nil
|
||||
// }
|
||||
// if err == nil {
|
||||
// _, err = dao.SetStoreSkuSyncStatus(db, model.VendorIDMTWM, []int{storeID}, nil, model.SyncFlagNewMask)
|
||||
// }
|
||||
// case 1:
|
||||
// if err = p.DeleteStoreAllCategories(ctx, rootTask, storeID, storeDetail.VendorStoreID, isContinueWhenError); err == nil {
|
||||
// _, err = dao.SetStoreCategorySyncStatus(db, model.VendorIDMTWM, []int{storeID}, nil, model.SyncFlagNewMask)
|
||||
// }
|
||||
// case 2:
|
||||
// _, err = p.SyncLocalStoreCategory(ctx, db, storeID, true, nil)
|
||||
// case 3:
|
||||
// _, err = p.SyncStoreCategory(ctx, rootTask, storeID, false)
|
||||
// case 4:
|
||||
// _, err = p.SyncStoreSkus(ctx, rootTask, storeID, nil, false, isContinueWhenError)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, 5)
|
||||
// tasksch.AddChild(parentTask, rootTask).Run()
|
||||
// if !isAsync {
|
||||
// _, err = rootTask.GetResult(0)
|
||||
// }
|
||||
// return rootTask.ID, err
|
||||
// }
|
||||
@@ -1,313 +0,0 @@
|
||||
package wsc
|
||||
|
||||
// func (p *PurchaseHandler) SyncStoreCategory(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync bool) (hint string, err error) {
|
||||
// strStoreID := utils.Int2Str(storeID)
|
||||
// num := 0
|
||||
// db := dao.GetDB()
|
||||
// rootTask := tasksch.NewSeqTask("微盟微商城SyncStoreCategory step1", ctx,
|
||||
// func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
// level := step + 1
|
||||
// catList, err := dao.GetStoreCategories(db, model.VendorIDWSC, storeID, level)
|
||||
// // globals.SugarLogger.Debug(utils.Format4Output(catList, false))
|
||||
// if len(catList) > 0 {
|
||||
// num += len(catList)
|
||||
// task := tasksch.NewParallelTask(fmt.Sprintf("微盟微商城SyncStoreCategory step2, level=%d", level), nil, ctx,
|
||||
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// updateFields := []string{dao.GetSyncStatusStructField(model.VendorNames[model.VendorIDWSC])}
|
||||
// catInfo := batchItemList[0].(*dao.SkuStoreCatInfo)
|
||||
// storeCatMap := &model.StoreSkuCategoryMap{}
|
||||
// storeCatMap.ID = catInfo.MapID
|
||||
// if catInfo.StoreCatSyncStatus&model.SyncFlagDeletedMask != 0 { // 删除
|
||||
// if catInfo.StoreCatSyncStatus&model.SyncFlagNewMask == 0 && !dao.IsVendorThingIDEmpty(catInfo.VendorCatID) {
|
||||
// globals.SugarLogger.Debugf("UpdateClassify strStoreID:%s, WscID:%s", strStoreID, catInfo.VendorCatID)
|
||||
// if globals.EnableWscStoreWrite {
|
||||
// err = api.WeimobAPI.UpdateClassify(utils.Str2Int64(catInfo.VendorCatID), composeFakeDelName(catInfo.Name), "")
|
||||
// }
|
||||
// }
|
||||
// } else if catInfo.StoreCatSyncStatus&(model.SyncFlagNewMask|model.SyncFlagModifiedMask) != 0 { // 新增
|
||||
// catImg := ""
|
||||
// if level == 2 {
|
||||
// catImg = DefCatImg
|
||||
// }
|
||||
// if globals.EnableWscStoreWrite {
|
||||
// storeCatMap.WscID, err = api.WeimobAPI.AddClassify(catInfo.Name, utils.Str2Int64WithDefault(catInfo.ParentVendorCatID, 0), catImg)
|
||||
// }
|
||||
// if err == nil {
|
||||
// updateFields = append(updateFields, dao.GetVendorThingIDStructField(model.VendorNames[model.VendorIDWSC]))
|
||||
// }
|
||||
// } else if catInfo.StoreCatSyncStatus&(model.SyncFlagModifiedMask) != 0 { // 修改
|
||||
// if globals.EnableWscStoreWrite {
|
||||
// err = api.WeimobAPI.UpdateClassify(utils.Str2Int64(catInfo.VendorCatID), catInfo.Name, "")
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// db2 := dao.GetDB()
|
||||
// storeCatMap.WscSyncStatus = 0
|
||||
// _, err = dao.UpdateEntity(db2, storeCatMap, updateFields...)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, catList)
|
||||
// rootTask.AddChild(task).Run()
|
||||
// _, err = task.GetResult(0)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, 2)
|
||||
// tasksch.AddChild(parentTask, rootTask).Run()
|
||||
// if !isAsync {
|
||||
// hint = utils.Int2Str(num)
|
||||
// _, err = rootTask.GetResult(0)
|
||||
// } else {
|
||||
// hint = rootTask.ID
|
||||
// }
|
||||
// return "", nil
|
||||
// }
|
||||
|
||||
// // 此函数根据门店商品信息重建分类信息
|
||||
// // 远程有,本地无, --> 删除远程
|
||||
// // 远程有,本地有,映射无, --> 添加关联
|
||||
// // 远程有,本地有,映射有, --> 不处理
|
||||
// // 远程无,本地有,映射无, --> 添加本地
|
||||
// // 远程无,本地有,映射有, --> 同步标记改为新增
|
||||
// // hint,如果是异步,返回的是任务ID,如果是同步,返回是本次需要同步的目录数
|
||||
// func (p *PurchaseHandler) SyncLocalStoreCategory(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, isAsync bool) (hint string, err error) {
|
||||
// if db == nil {
|
||||
// db = dao.GetDB()
|
||||
// }
|
||||
// catMap := make([]map[string]*dao.SkuStoreCatInfo, 2)
|
||||
// for i := 0; i < 2; i++ {
|
||||
// catMap[i] = make(map[string]*dao.SkuStoreCatInfo)
|
||||
// localCats, err := dao.GetSkusCategories(db, model.VendorIDWSC, storeID, nil, i+1)
|
||||
// // globals.SugarLogger.Debug(utils.Format4Output(localCats, false))
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// for _, cat := range localCats {
|
||||
// catMap[i][cat.ParentCatName+"/"+cat.Name] = cat
|
||||
// }
|
||||
// }
|
||||
|
||||
// dao.Begin(db)
|
||||
// defer func() {
|
||||
// dao.Rollback(db)
|
||||
// }()
|
||||
// num := 0
|
||||
// for i := 0; i < 2; i++ {
|
||||
// for _, v := range catMap[i] {
|
||||
// if v.MapID == -1 || v.MapID == 0 { // 本地缺失
|
||||
// wscSyncStatus := int8(model.SyncFlagNewMask)
|
||||
// if v.MapID == -1 { // 远程有同名的,只是简单增加一条本地记录关联
|
||||
// wscSyncStatus = 0
|
||||
// }
|
||||
// catMap := &model.StoreSkuCategoryMap{
|
||||
// StoreID: storeID,
|
||||
// CategoryID: v.ID,
|
||||
// WscID: utils.Str2Int64WithDefault(v.VendorCatID, 0),
|
||||
// WscSyncStatus: wscSyncStatus,
|
||||
// MtwmSyncStatus: model.SyncFlagNewMask,
|
||||
// EbaiSyncStatus: model.SyncFlagNewMask,
|
||||
// ElmSyncStatus: model.SyncFlagNewMask,
|
||||
// }
|
||||
// num++
|
||||
// dao.WrapAddIDCULDEntity(catMap, ctx.GetUserName())
|
||||
// if err = dao.CreateEntity(db, catMap); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// } else {
|
||||
// if dao.IsVendorThingIDEmpty(v.VendorCatID) && ((v.StoreCatSyncStatus & model.SyncFlagNewMask) == 0) {
|
||||
// catMap := &model.StoreSkuCategoryMap{}
|
||||
// catMap.ID = v.MapID
|
||||
// if _, err = dao.UpdateEntityLogically(db, catMap, map[string]interface{}{
|
||||
// model.FieldWscSyncStatus: model.SyncFlagNewMask,
|
||||
// }, ctx.GetUserName(), nil); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// dao.Commit(db)
|
||||
// return utils.Int2Str(num), err
|
||||
// }
|
||||
|
||||
// // hint,如果是异步,返回的是任务ID,如果是同步,返回是本次需要同步的目录数
|
||||
// func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// db := dao.GetDB()
|
||||
// for i := 0; i < 3; i++ { // 最多重试三次
|
||||
// if hint, err = p.SyncLocalStoreCategory(ctx, db, storeID, false); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// if hint != "0" {
|
||||
// if hint, err = p.SyncStoreCategory(ctx, parentTask, storeID, false); err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// }
|
||||
// if hint == "0" {
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// if hint != "0" {
|
||||
// return "", errors.New("同步门店商品所需目录失败")
|
||||
// }
|
||||
// storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDWSC)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// skus, err := dao.GetStoreSkus(db, model.VendorIDWSC, storeID, skuIDs)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(skus, false))
|
||||
// rootTask := tasksch.NewParallelTask("微盟微商城SyncStoreSkus", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
// func(rootTask *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// v := batchItemList[0]
|
||||
// skuItem := v.(*dao.StoreSkuSyncInfo)
|
||||
// pricePercentage := jxutils.GetPricePercentage(storeDetail.PricePercentagePackObj, int(skuItem.Price), int(storeDetail.PricePercentage))
|
||||
// updateFields := []string{model.FieldWscSyncStatus}
|
||||
// storeSkuBind := &model.StoreSkuBind{}
|
||||
// storeSkuBind.ID = skuItem.BindID
|
||||
// if skuItem.StoreSkuSyncStatus&model.SyncFlagDeletedMask != 0 {
|
||||
// if skuItem.StoreSkuSyncStatus&model.SyncFlagNewMask == 0 {
|
||||
// goodsID := utils.Str2Int64WithDefault(skuItem.VendorNameID, 0)
|
||||
// if globals.EnableWscStoreWrite {
|
||||
// if err = api.WeimobAPI.UpdateGoodsShelfStatus([]int64{goodsID}, false); err == nil {
|
||||
// err = api.WeimobAPI.UpdateGoodsTitle(goodsID, composeFakeDelName(skuItem.Name))
|
||||
// } else if intErr, ok := err.(*utils.ErrorWithCode); ok && intErr.Code() == "1001930300001" { // 商品不存在错
|
||||
// err = nil // 强制忽略
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else if skuItem.StoreSkuSyncStatus&(model.SyncFlagStoreSkuModifiedMask|model.SyncFlagNewMask) != 0 {
|
||||
// outerGoodsCode := utils.Int2Str(skuItem.NameID)
|
||||
// title := jxutils.ComposeSkuName(skuItem.Prefix, skuItem.Name, skuItem.Comment, skuItem.Unit, skuItem.SpecQuality, skuItem.SpecUnit, 30)
|
||||
// isPutAway := jxutils.MergeSkuStatus(skuItem.Status, skuItem.StoreSkuStatus) == model.SkuStatusNormal
|
||||
// categoryID := skuItem.VendorVendorCatID
|
||||
// if categoryID == 0 {
|
||||
// categoryID = DefVendorCategoryId
|
||||
// }
|
||||
// classifyIDList := []int64{utils.Str2Int64WithDefault(skuItem.VendorCatID, 0)}
|
||||
// if skuItem.SkuVendorCatID != "" {
|
||||
// if int64Value := utils.Str2Int64WithDefault(skuItem.SkuVendorCatID, 0); int64Value > 0 {
|
||||
// classifyIDList = append(classifyIDList, int64Value)
|
||||
// }
|
||||
// }
|
||||
// b2cGoods := &weimobapi.PendingSaveB2CGoodsVo{
|
||||
// FreightTemplateId: DefFreightTemplateId,
|
||||
// DeliveryTypeIdList: []int64{DefDeliveryTypeId},
|
||||
// B2cGoodsType: weimobapi.GoodsTypeNormal,
|
||||
// }
|
||||
// salePrice := int64(jxutils.CaculateSkuVendorPrice(int(skuItem.Price), pricePercentage, skuItem.CatPricePercentage))
|
||||
// skuList := []map[string]interface{}{
|
||||
// map[string]interface{}{
|
||||
// weimobapi.KeyOuterSkuCode: utils.Int2Str(skuItem.ID),
|
||||
// weimobapi.KeyImageURL: skuItem.Img,
|
||||
// weimobapi.KeySalePrice: jxutils.IntPrice2Standard(salePrice),
|
||||
// weimobapi.KeyCostPrice: jxutils.IntPrice2Standard(salePrice * 8 / 10),
|
||||
// weimobapi.KeyOriginalPrice: jxutils.IntPrice2Standard(salePrice * 10 / (6 + rand.Int63n(4))),
|
||||
// weimobapi.KeyEditStockNum: 0, //model.MaxStoreSkuStockQty,
|
||||
// weimobapi.KeyB2cSku: &weimobapi.PendingSaveB2CSkuVo{
|
||||
// Weight: jxutils.IntWeight2Float(skuItem.Weight),
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// if skuItem.StoreSkuSyncStatus&model.SyncFlagNewMask != 0 {
|
||||
// var (
|
||||
// goodsID int64
|
||||
// skuMap map[string]int64
|
||||
// )
|
||||
// if globals.EnableWscStoreWrite {
|
||||
// goodsID, skuMap, err = api.WeimobAPI.AddGoods(outerGoodsCode, title, false, []string{skuItem.Img}, skuItem.Comment, isPutAway, 0, categoryID, classifyIDList, b2cGoods, skuList, nil)
|
||||
// } else {
|
||||
// goodsID = jxutils.GenFakeID()
|
||||
// skuMap = map[string]int64{
|
||||
// utils.Int2Str(skuItem.ID): jxutils.GenFakeID(),
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// storeSkuBind.WscID = skuMap[utils.Int2Str(skuItem.ID)]
|
||||
// storeSkuBind.WscID2 = goodsID
|
||||
// updateFields = append(updateFields, model.FieldWscID, model.FieldWscID2)
|
||||
// }
|
||||
// } else {
|
||||
// goodsID := utils.Str2Int64WithDefault(skuItem.VendorNameID, 0)
|
||||
// goodsInfo, err2 := api.WeimobAPI.QueryGoodsDetail(goodsID)
|
||||
// if err = err2; err == nil {
|
||||
// // http://open.weimob.com/docapi/article?tag=Af
|
||||
// // sku id,如果为空,则新增sku; 如果更新之前的skuId与入参skuId对应,则更新sku; 如果更新之前的skuId没有和入参的skuId对应,删除更新之前的sku
|
||||
// skuList[0][weimobapi.KeySkuID] = utils.Str2Int64WithDefault(skuItem.VendorSkuID, 0)
|
||||
// remoteSkuList := goodsInfo[weimobapi.KeySkuList].([]interface{})
|
||||
// if len(remoteSkuList) > 0 {
|
||||
// // skuList[0][weimobapi.KeyEditStockNum] = model.MaxStoreSkuStockQty - int(utils.MustInterface2Int64(remoteSkuList[0].(map[string]interface{})[weimobapi.KeyAvailableStockNum]))
|
||||
// }
|
||||
// if globals.EnableWscStoreWrite {
|
||||
// _, _, err = api.WeimobAPI.UpdateGoods(goodsID, title, false, []string{skuItem.Img}, skuItem.Comment, isPutAway, 0, categoryID, classifyIDList, b2cGoods, skuList, nil)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if err == nil {
|
||||
// _, err = dao.UpdateEntity(nil, storeSkuBind, updateFields...)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, skus)
|
||||
// if parentTask != nil {
|
||||
// parentTask.AddChild(rootTask)
|
||||
// }
|
||||
// rootTask.Run()
|
||||
// if !isAsync {
|
||||
// _, err = rootTask.GetResult(0)
|
||||
// hint = utils.Int2Str(len(skus))
|
||||
// } else {
|
||||
// hint = rootTask.ID
|
||||
// }
|
||||
// return hint, err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) RefreshStoresAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool, storeIDs []int) (hint string, err error) {
|
||||
// return hint, err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// userName := ctx.GetUserName()
|
||||
// globals.SugarLogger.Debugf("wsc FullSyncStoreSkus storeID:%d, isContinueWhenError:%t, userName:%s", storeID, isContinueWhenError, userName)
|
||||
|
||||
// db := dao.GetDB()
|
||||
// rootTask := tasksch.NewSeqTask("微盟微商城FullSyncStoreSkus", ctx,
|
||||
// func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
// switch step {
|
||||
// case 0:
|
||||
// _, err = dao.SetStoreCategorySyncStatus(db, model.VendorIDWSC, []int{storeID}, nil, model.SyncFlagNewMask)
|
||||
// case 1:
|
||||
// _, err = dao.SetStoreSkuSyncStatus(db, model.VendorIDWSC, []int{storeID}, nil, model.SyncFlagNewMask)
|
||||
// case 2:
|
||||
// _, err = p.SyncLocalStoreCategory(ctx, db, storeID, false)
|
||||
// case 3:
|
||||
// _, err = p.SyncStoreCategory(ctx, rootTask, storeID, false)
|
||||
// case 4:
|
||||
// _, err = p.SyncStoreSkus(ctx, rootTask, storeID, nil, true, isContinueWhenError)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, 5)
|
||||
// tasksch.AddChild(parentTask, rootTask).Run()
|
||||
// if !isAsync {
|
||||
// _, err = rootTask.GetResult(0)
|
||||
// }
|
||||
// return rootTask.ID, err
|
||||
// }
|
||||
|
||||
// func (p *PurchaseHandler) DeleteRemoteStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// return hint, err
|
||||
// }
|
||||
|
||||
// // func SplitGoodsAndSkuIDFromJXVendorSkuID(vendorSkuID string) (goodsID, skuID int64) {
|
||||
// // list := strings.Split(vendorSkuID, ",")
|
||||
// // if len(list) == 2 {
|
||||
// // skuID = utils.Str2Int64WithDefault(list[0], 0)
|
||||
// // goodsID = utils.Str2Int64WithDefault(list[1], 0)
|
||||
// // }
|
||||
// // return goodsID, skuID
|
||||
// // }
|
||||
|
||||
// // // skuID放在前面的原因是存入数据库后,便于以skuID的查找
|
||||
// // func ComposeJXVendorSkuIDFromGoodsAndSkuID(goodsID, skuID int64) (vendorSkuID string) {
|
||||
// // return utils.Int64ToStr(skuID) + "," + utils.Int64ToStr(goodsID)
|
||||
// // }
|
||||
@@ -547,3 +547,18 @@ func (c *StoreController) GetStoreListByLocation() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 老格恢复拓店进度
|
||||
// @Description 老格恢复拓店进度
|
||||
// @Param token header string true "认证token"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /JdStoreInfoCoordinateRecover [post]
|
||||
func (c *StoreController) JdStoreInfoCoordinateRecover() {
|
||||
c.callJdStoreInfoCoordinateRecover(func(params *tStoreJdStoreInfoCoordinateRecoverParams) (retVal interface{}, errCode string, err error) {
|
||||
r := c.Ctx.Request
|
||||
files := r.MultipartForm.File["userfiles"]
|
||||
err = cms.JdStoreInfoCoordinateRecover(params.Ctx, files)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -438,3 +438,20 @@ func (c *StoreSkuController) GetMissingStoreSkuFromOrder() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 根据门店信息查找推荐商品(按销量)
|
||||
// @Description 根据门店信息查找推荐商品(按销量)
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeIDs query string true "门店列表"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetTopSkusByStoreIDs [get]
|
||||
func (c *StoreSkuController) GetTopSkusByStoreIDs() {
|
||||
var storeIDList []int
|
||||
c.callGetTopSkusByStoreIDs(func(params *tStoreSkuGetTopSkusByStoreIDsParams) (retVal interface{}, errCode string, err error) {
|
||||
if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil {
|
||||
retVal, err = cms.GetTopSkusByStoreIDs(params.Ctx, storeIDList)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -411,3 +411,18 @@ func (c *Auth2Controller) UpdateUserByMiniInfo() {
|
||||
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 *User2Controller) GetJdUsers() {
|
||||
c.callGetJdUsers(func(params *tUser2GetJdUsersParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.GetJdUsers(params.Ctx, params.IsAsync, params.IsContinueWhenError)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -858,3 +858,20 @@ func afsSkus2OrderSkus(afsSkuList []*model.OrderFinancialSkuExt) (skuList []*mod
|
||||
}
|
||||
return skuList
|
||||
}
|
||||
|
||||
// @Title 订单门店归属补漏
|
||||
// @Description 订单门店归属补漏
|
||||
// @Param token header string true "认证token"
|
||||
// @Param fromDate formData string false "开始日期"
|
||||
// @Param toDate formData string false "结束日期(缺省不限制)"
|
||||
// @Param isAsync formData bool false "是否异步操作"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /RefreshOrdersWithoutJxStoreID [post]
|
||||
func (c *OrderController) RefreshOrdersWithoutJxStoreID() {
|
||||
c.callRefreshOrdersWithoutJxStoreID(func(params *tOrderRefreshOrdersWithoutJxStoreIDParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = orderman.RefreshOrdersWithoutJxStoreID(params.Ctx, params.FromDate, params.ToDate, params.IsAsync, params.IsContinueWhenError)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
@@ -92,3 +93,25 @@ func (c *JxOrderController) GetMyOrders() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 查询自己的订单状态数量信息
|
||||
// @Description 查询自己的订单状态数量信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param fromDate query string false "开始日期(包含),格式(2006-01-02),如果订单号为空此项必须要求"
|
||||
// @Param toDate query string false "结束日期(包含),格式(2006-01-02),如果订单号为空此项必须要求"
|
||||
// @Param statuss query string false "订单状态列表[1,2,3],缺省不限制"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetMyOrderCountInfo [get]
|
||||
func (c *JxOrderController) GetMyOrderCountInfo() {
|
||||
c.callGetMyOrderCountInfo(func(params *tJxorderGetMyOrderCountInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
timeList, err := jxutils.BatchStr2Time(params.FromDate, params.ToDate)
|
||||
if err == nil {
|
||||
var statuss []int
|
||||
if err = jxutils.Strings2Objs(params.Statuss, &statuss); err == nil {
|
||||
retVal, err = localjx.GetMyOrderCountInfo(params.Ctx, timeList[0], timeList[1], statuss)
|
||||
}
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -352,50 +352,3 @@ func (c *TempOpController) FixMtwmCategory() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 老格恢复拓店进度
|
||||
// @Description 老格恢复拓店进度
|
||||
// @Param token header string true "认证token"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /JdStoreInfoCoordinateRecover [post]
|
||||
func (c *TempOpController) JdStoreInfoCoordinateRecover() {
|
||||
c.callJdStoreInfoCoordinateRecover(func(params *tTempopJdStoreInfoCoordinateRecoverParams) (retVal interface{}, errCode string, err error) {
|
||||
r := c.Ctx.Request
|
||||
files := r.MultipartForm.File["userfiles"]
|
||||
err = tempop.JdStoreInfoCoordinateRecover(params.Ctx, files)
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 订单门店归属补漏
|
||||
// @Description 订单门店归属补漏
|
||||
// @Param token header string true "认证token"
|
||||
// @Param fromDate formData string false "开始日期"
|
||||
// @Param toDate formData string false "结束日期(缺省不限制)"
|
||||
// @Param isAsync formData bool false "是否异步操作"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /RefreshOrdersWithoutJxStoreID [post]
|
||||
func (c *TempOpController) RefreshOrdersWithoutJxStoreID() {
|
||||
c.callRefreshOrdersWithoutJxStoreID(func(params *tTempopRefreshOrdersWithoutJxStoreIDParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = tempop.RefreshOrdersWithoutJxStoreID(params.Ctx, params.FromDate, params.ToDate, params.IsAsync, params.IsContinueWhenError)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -610,6 +610,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetMyOrderCountInfo",
|
||||
Router: `/GetMyOrderCountInfo`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetMyOrders",
|
||||
@@ -1008,6 +1017,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||
beego.ControllerComments{
|
||||
Method: "RefreshOrdersWithoutJxStoreID",
|
||||
Router: `/RefreshOrdersWithoutJxStoreID`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||
beego.ControllerComments{
|
||||
Method: "RefundOrder",
|
||||
@@ -1413,6 +1431,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "JdStoreInfoCoordinateRecover",
|
||||
Router: `/JdStoreInfoCoordinateRecover`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "ScoreStore",
|
||||
@@ -1557,6 +1584,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetTopSkusByStoreIDs",
|
||||
Router: `/GetTopSkusByStoreIDs`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetVendorStoreSkusInfo",
|
||||
@@ -1818,24 +1854,6 @@ 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",
|
||||
Router: `/JdStoreInfoCoordinateRecover`,
|
||||
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: "PrintMsg",
|
||||
@@ -1854,15 +1872,6 @@ 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: "RefreshOrdersWithoutJxStoreID",
|
||||
Router: `/RefreshOrdersWithoutJxStoreID`,
|
||||
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: "RetrieveEbaiShopLicence",
|
||||
@@ -1962,6 +1971,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:User2Controller"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:User2Controller"],
|
||||
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:User2Controller"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:User2Controller"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetMyStoreList",
|
||||
|
||||
Reference in New Issue
Block a user