Merge remote-tracking branch 'origin/mark' into don
This commit is contained in:
@@ -65,12 +65,12 @@ func TransferLegacyWeixins(mobile string) (err error) {
|
||||
user := &model.User{
|
||||
UserID2: v.Tel,
|
||||
Name: v.NickName,
|
||||
Mobile: v.Tel,
|
||||
Mobile: &v.Tel,
|
||||
Type: model.UserTypeStoreBoss,
|
||||
Remark: remark4Transfer,
|
||||
}
|
||||
if user.Name == "" {
|
||||
user.Name = user.Mobile
|
||||
user.Name = user.GetMobile()
|
||||
}
|
||||
userList, _, err2 := dao.GetUsers(db, 0, "", nil, "", v.Tel, 0, -1)
|
||||
if err = err2; err != nil {
|
||||
|
||||
@@ -185,12 +185,7 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
|
||||
city.name city_name,
|
||||
district.name district_name,
|
||||
CONCAT('[', GROUP_CONCAT(DISTINCT CONCAT('{"vendorStoreID":"', m1.vendor_store_id, '", "vendorID":', m1.vendor_id,
|
||||
', "status":', m1.status, ', "pricePercentage":', m1.price_percentage, ', "pricePercentagePack":"', m1.price_percentage_pack, '", "vendorStoreName":"',
|
||||
CASE m1.vendor_id
|
||||
WHEN 0 THEN IF(jd.name IS NULL, '', jd.name)
|
||||
WHEN 3 THEN IF(eb.col_name IS NULL, '', eb.col_name)
|
||||
ELSE ''
|
||||
END,
|
||||
', "status":', m1.status, ', "pricePercentage":', m1.price_percentage, ', "pricePercentagePack":"', m1.price_percentage_pack, '", "vendorStoreName":"', m1.store_name,
|
||||
'", "isSync":', m1.is_sync,
|
||||
', "fakeOpenStart":', m1.fake_open_start, ', "fakeOpenStop":', m1.fake_open_stop, '}')), ']') store_map_str,
|
||||
CONCAT('[', GROUP_CONCAT(DISTINCT CONCAT('{"vendorStoreID":"', m2.vendor_store_id, '", "vendorID":', m2.vendor_id,
|
||||
@@ -201,8 +196,6 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
|
||||
LEFT JOIN place province ON province.code = city.parent_code AND province.level = 1
|
||||
LEFT JOIN place district ON t1.district_code = district.code AND district.level = 3
|
||||
LEFT JOIN store_map m1 ON t1.id = m1.store_id AND m1.deleted_at = ?
|
||||
LEFT JOIN ebde_shops eb ON eb.col_baidu_shop_id = m1.vendor_store_id
|
||||
LEFT JOIN jde_store jd ON jd.jdid = m1.vendor_store_id
|
||||
LEFT JOIN store_courier_map m2 ON t1.id = m2.store_id AND m2.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
|
||||
@@ -3,6 +3,7 @@ package cms
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -189,6 +190,7 @@ func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSk
|
||||
|
||||
Status: inSku.MergedStatus,
|
||||
VendorPrice: inSku.VendorPrice,
|
||||
Seq: inSku.Seq,
|
||||
}
|
||||
if !isStoreSkuSyncNeedDelete(inSku) {
|
||||
outSku.Stock = model.MaxStoreSkuStockQty
|
||||
@@ -197,10 +199,12 @@ func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSk
|
||||
}
|
||||
|
||||
func calVendorPrice4StoreSku(inSku *dao.StoreSkuSyncInfo, pricePercentagePack model.PricePercentagePack, pricePercentage int) (outSku *dao.StoreSkuSyncInfo) {
|
||||
pricePercentage = jxutils.GetPricePercentage(pricePercentagePack, int(inSku.Price), pricePercentage)
|
||||
inSku.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(int(inSku.Price), pricePercentage, 0))
|
||||
if inSku.VendorPrice <= 0 {
|
||||
inSku.VendorPrice = 1 // 最少1分钱
|
||||
if inSku.VendorPrice <= 0 { // 避免重新计算
|
||||
pricePercentage = jxutils.GetPricePercentage(pricePercentagePack, int(inSku.Price), pricePercentage)
|
||||
inSku.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(int(inSku.Price), pricePercentage, 0))
|
||||
if inSku.VendorPrice <= 0 {
|
||||
inSku.VendorPrice = 1 // 最少1分钱
|
||||
}
|
||||
}
|
||||
return inSku
|
||||
}
|
||||
@@ -292,16 +296,22 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
|
||||
singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
storeSkuHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
|
||||
reorderHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IStoreSkuSorter)
|
||||
|
||||
var (
|
||||
createList, updateList []*dao.StoreSkuSyncInfo
|
||||
deleteList, stockList, onlineList, offlineList, priceList []*partner.StoreSkuInfo
|
||||
updateItems []*dao.KVUpdateItem
|
||||
reorderSkuMap map[string][]*dao.StoreSkuSyncInfo
|
||||
)
|
||||
skuMap := make(map[*partner.StoreSkuInfo]*dao.StoreSkuSyncInfo)
|
||||
if reorderHandler != nil {
|
||||
reorderSkuMap = make(map[string][]*dao.StoreSkuSyncInfo)
|
||||
}
|
||||
|
||||
for _, sku := range skus {
|
||||
var bareSku *partner.StoreSkuInfo
|
||||
isNeedReorder := false
|
||||
if isStoreSkuSyncNeedDelete(sku) {
|
||||
if !dao.IsVendorThingIDEmpty(sku.VendorSkuID) {
|
||||
bareSku = storeSkuSyncInfo2Bare(sku)
|
||||
@@ -330,6 +340,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
createList = append(createList, sku)
|
||||
}
|
||||
}
|
||||
isNeedReorder = true
|
||||
} else {
|
||||
if dao.IsVendorThingIDEmpty(sku.VendorSkuID) {
|
||||
err = fmt.Errorf("门店:%d,修改没有创建的商品:%d", storeID, sku.SkuID)
|
||||
@@ -340,7 +351,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
} else {
|
||||
isAdded2Update := false
|
||||
// 修改商品信息时不改价(以免活动引起的失败),而用单独的改价来改
|
||||
if model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) && singleStoreHandler != nil {
|
||||
if (model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) || (model.IsSyncStatusSec(sku.StoreSkuSyncStatus) && reorderHandler == nil)) && singleStoreHandler != nil {
|
||||
isAdded2Update = true
|
||||
updateList = append(updateList, calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)))
|
||||
}
|
||||
@@ -367,8 +378,12 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
}
|
||||
}
|
||||
}
|
||||
isNeedReorder = model.IsSyncStatusSec(sku.StoreSkuSyncStatus)
|
||||
}
|
||||
}
|
||||
if isNeedReorder && reorderHandler != nil && sku.VendorCatID != "" {
|
||||
reorderSkuMap[sku.VendorCatID] = append(reorderSkuMap[sku.VendorCatID], sku)
|
||||
}
|
||||
if bareSku != nil {
|
||||
skuMap[bareSku] = sku
|
||||
}
|
||||
@@ -500,9 +515,32 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
return nil, len(successList), err
|
||||
}, ctx, task, priceList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusPrice), isContinueWhenError)
|
||||
}
|
||||
case 7:
|
||||
if len(reorderSkuMap) > 0 {
|
||||
var vendorCatIDs []string
|
||||
for vendorCatID := range reorderSkuMap {
|
||||
vendorCatIDs = append(vendorCatIDs, vendorCatID)
|
||||
}
|
||||
reorderTask := tasksch.NewParallelTask("门店商品排序", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorCatID := batchItemList[0].(string)
|
||||
skuList := reorderSkuMap[vendorCatID]
|
||||
var bareList []*partner.StoreSkuInfo
|
||||
for _, v := range skuList {
|
||||
bareList = append(bareList, storeSkuSyncInfo2Bare(calVendorPrice4StoreSku(v, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage))))
|
||||
}
|
||||
sort.Sort(partner.BareStoreSkuInfoList(bareList))
|
||||
if err = reorderHandler.ReorderStoreSkus(ctx, storeID, vendorStoreID, vendorCatID, bareList); err == nil {
|
||||
updateStoreSku(dao.GetDB(), vendorID, skuList, model.SyncFlagSeqMask)
|
||||
}
|
||||
return retVal, err
|
||||
}, vendorCatIDs)
|
||||
tasksch.HandleTask(reorderTask, task, true).Run()
|
||||
_, err = reorderTask.GetResult(0)
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, []int{0, 1, 2, 3, 4, 5, 6})
|
||||
}, []int{0, 1, 2, 3, 4, 5, 6, 7})
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
return err
|
||||
|
||||
@@ -101,8 +101,8 @@ func init() {
|
||||
auth2.Init(userProvider)
|
||||
}
|
||||
|
||||
func RegisterUser(user *model.User, mobileVerifyCode string, inAuthInfo *auth2.AuthInfo) (outAuthInfo *auth2.AuthInfo, err error) {
|
||||
mobileAuth, err2 := auth2.Login(auth2.AuthTypeMobile, user.Mobile, auth2.UserIDMobile, mobileVerifyCode)
|
||||
func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVerifyCode string, inAuthInfo *auth2.AuthInfo) (outAuthInfo *auth2.AuthInfo, err error) {
|
||||
mobileAuth, err2 := auth2.Login(auth2.AuthTypeMobile, user.GetMobile(), auth2.UserIDMobile, mobileVerifyCode)
|
||||
if err = err2; err == nil {
|
||||
if !mobileAuth.IsUserEmpty() {
|
||||
return nil, jsonerr.New(mobileAuth, model.ErrCodeJsonUserAlreadyExist)
|
||||
@@ -113,7 +113,7 @@ func RegisterUser(user *model.User, mobileVerifyCode string, inAuthInfo *auth2.A
|
||||
} else {
|
||||
user.Type |= model.UserTypeStoreBoss
|
||||
}
|
||||
if err = CreateUser(user, "RegisterUser"); err == nil {
|
||||
if err = CreateUser(user, utils.LimitUTF8StringLen(ctx.GetRealRemoteIP()+","+inAuthInfo.GetAuthID(), 32)); err == nil {
|
||||
if outAuthInfo, err = auth2.BindUser(mobileAuth, user); err == nil && inAuthInfo != nil {
|
||||
err = auth2.AddAuthBind(&outAuthInfo.UserBasic, inAuthInfo)
|
||||
}
|
||||
@@ -124,6 +124,65 @@ func RegisterUser(user *model.User, mobileVerifyCode string, inAuthInfo *auth2.A
|
||||
return outAuthInfo, err
|
||||
}
|
||||
|
||||
func HandleOrder4Consignee(order *model.GoodsOrder) (err error) {
|
||||
var user *model.User
|
||||
authType := jxutils.GetAuthType4Vendor(order.VendorID)
|
||||
if authType == "" {
|
||||
msg := fmt.Sprintf("平台ID:%d当前不支持", order.VendorID)
|
||||
globals.SugarLogger.Warn(msg)
|
||||
return fmt.Errorf(msg)
|
||||
}
|
||||
|
||||
oeratorName := order.VendorOrderID
|
||||
mobileNumber := jxutils.GetRealMobile4Order(order)
|
||||
db := dao.GetDB()
|
||||
if mobileNumber != "" {
|
||||
userList, _, err2 := dao.GetUsers(db, 0, "", nil, "", mobileNumber, 0, 0)
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
if len(userList) > 0 {
|
||||
user = userList[0]
|
||||
}
|
||||
}
|
||||
|
||||
vendorUserID := order.VendorUserID
|
||||
if err == nil {
|
||||
authList, err2 := dao.GetUserBindAuthInfo(db, "", model.AuthBindTypeID, "", []string{authType})
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
if len(authList) > 0 {
|
||||
if user, err = dao.GetUserByID(db, "UserID", authList[0].UserID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if user == nil {
|
||||
user = &model.User{
|
||||
UserID2: mobileNumber,
|
||||
Name: order.ConsigneeName,
|
||||
Mobile: &mobileNumber,
|
||||
Type: model.UserTypeConsumer,
|
||||
Remark: order.VendorOrderID,
|
||||
}
|
||||
user.Type = model.UserTypeConsumer
|
||||
err = CreateUser(user, oeratorName)
|
||||
}
|
||||
if err == nil && vendorUserID != "" {
|
||||
authBind := &model.AuthBind{
|
||||
UserID: user.GetID(),
|
||||
BindType: model.AuthBindTypeID,
|
||||
AuthID: vendorUserID,
|
||||
Type: authType,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(authBind, oeratorName)
|
||||
authBind.Status = model.AuthBindStatusNormal
|
||||
err = dao.CreateEntity(nil, authBind)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, err error) {
|
||||
authInfo, err := ctx.GetV2AuthInfo()
|
||||
if err == nil {
|
||||
@@ -133,7 +192,7 @@ func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, er
|
||||
}
|
||||
|
||||
func CreateUser(user *model.User, creatorName string) (err error) {
|
||||
if user == nil || user.UserID2 == "" || user.Name == "" || user.Mobile == "" {
|
||||
if user == nil || user.UserID2 == "" || user.Name == "" || user.GetMobile() == "" {
|
||||
return ErrUserIDAndNameMustGiven
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(user, creatorName)
|
||||
@@ -165,7 +224,7 @@ func OnDingDingMsg(msg map[string]interface{}) (callbackResponse *dingdingapi.Ca
|
||||
for _, userID := range msg[dingdingapi.KeyUserID].([]interface{}) {
|
||||
userIDStr := utils.Interface2String(userID)
|
||||
globals.SugarLogger.Debugf("OnDingDingMsg dingding user:%s left company", userIDStr)
|
||||
if authBind, err = dao.GetAuthBind(db, "", dingding.AuthTypeStaff, userIDStr); err == nil { // 直接找到了
|
||||
if authBind, err = dao.GetAuthBind(db, "", model.AuthBindTypeAuth, dingding.AuthTypeStaff, userIDStr); err == nil { // 直接找到了
|
||||
globals.SugarLogger.Debugf("OnDingDingMsg dingding user:%s, userID:%s left company", userIDStr, authBind.UserID)
|
||||
if err = DisableUser(jxcontext.AdminCtx, authBind.UserID); err != nil {
|
||||
globals.SugarLogger.Errorf("OnDingDingMsg failed with error:%v", err)
|
||||
|
||||
@@ -152,7 +152,7 @@ func RefreshRealMobile(ctx *jxcontext.Context, vendorID int, fromTime, toTime ti
|
||||
mobile, err2 := handler.GetOrderRealMobile(ctx, order)
|
||||
if err = err2; err == nil {
|
||||
mobile = jxutils.FormalizeMobile(mobile)
|
||||
if !jxutils.IsMobileFake(mobile) && strings.Index(order.ConsigneeMobile, mobile) == -1 {
|
||||
if jxutils.IsStringLikeMobile(mobile) && strings.Index(order.ConsigneeMobile, mobile) == -1 {
|
||||
order.ConsigneeMobile2 = mobile
|
||||
_, err = dao.UpdateEntity(db, order, "ConsigneeMobile2")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user