From 9919f6607277174acce25b9df782dd10f36a5f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 19 Feb 2020 18:20:51 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=9C=89=E6=97=A0=E6=89=8B=E6=9C=BA=E5=8F=B7=E8=BF=94=E5=9B=9E?= =?UTF-8?q?tokentype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/auth2/auth2.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/business/auth2/auth2.go b/business/auth2/auth2.go index bcf932354..b61df8e14 100644 --- a/business/auth2/auth2.go +++ b/business/auth2/auth2.go @@ -351,6 +351,9 @@ func RemoveUserInfo(token string) { func GetTokenInfo(token string) (authInfo *AuthInfo, err error) { if authInfo = getFixedTokenName(token); authInfo != nil { + if authInfo.Mobile == "" { + authInfo.TokenType = 2 + } return authInfo, nil } if err = api.Cacher.GetAs(token, &authInfo); err == nil { From 6719daaf05a243fa2baf326e89fbdf4e55000e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 19 Feb 2020 18:25:25 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=9C=89=E6=97=A0=E6=89=8B=E6=9C=BA=E5=8F=B7=E8=BF=94=E5=9B=9E?= =?UTF-8?q?tokentype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/auth2/auth2.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/business/auth2/auth2.go b/business/auth2/auth2.go index b61df8e14..0f9a077c7 100644 --- a/business/auth2/auth2.go +++ b/business/auth2/auth2.go @@ -351,12 +351,12 @@ func RemoveUserInfo(token string) { func GetTokenInfo(token string) (authInfo *AuthInfo, err error) { if authInfo = getFixedTokenName(token); authInfo != nil { - if authInfo.Mobile == "" { - authInfo.TokenType = 2 - } return authInfo, nil } if err = api.Cacher.GetAs(token, &authInfo); err == nil { + if authInfo.Mobile == "" { + authInfo.TokenType = 2 + } return authInfo, nil } return nil, model.ErrTokenIsInvalid From a15102c12b08c028ca166b2bbd57360fdea2dd71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 19 Feb 2020 18:34:29 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=9C=89=E6=97=A0=E6=89=8B=E6=9C=BA=E5=8F=B7=E8=BF=94=E5=9B=9E?= =?UTF-8?q?tokentype=E9=80=80=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/auth2/auth2.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/business/auth2/auth2.go b/business/auth2/auth2.go index 0f9a077c7..bcf932354 100644 --- a/business/auth2/auth2.go +++ b/business/auth2/auth2.go @@ -354,9 +354,6 @@ func GetTokenInfo(token string) (authInfo *AuthInfo, err error) { return authInfo, nil } if err = api.Cacher.GetAs(token, &authInfo); err == nil { - if authInfo.Mobile == "" { - authInfo.TokenType = 2 - } return authInfo, nil } return nil, model.ErrTokenIsInvalid From a1e318aee780d0da5f0063a1fbc7fea4f4c8ef55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 20 Feb 2020 10:34:22 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A5=BF=E9=B2=9C?= =?UTF-8?q?=E8=BE=BE=E5=95=86=E5=93=81=E5=AF=BC=E5=85=A5=EF=BC=8Cbug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sku.go | 136 +++++++++++++++++++++++++- business/jxstore/cms/store_sku.go | 5 +- controllers/cms_sku.go | 17 ++++ routers/commentsRouter_controllers.go | 9 ++ 4 files changed, 163 insertions(+), 4 deletions(-) diff --git a/business/jxstore/cms/sku.go b/business/jxstore/cms/sku.go index 35c118ef1..0a35bfdc5 100644 --- a/business/jxstore/cms/sku.go +++ b/business/jxstore/cms/sku.go @@ -7,6 +7,8 @@ import ( "strings" "time" + "github.com/360EntSecGroup-Skylar/excelize" + "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" "git.rosy.net.cn/baseapi/platformapi/jdapi" @@ -412,8 +414,12 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku bool, params ma } if params["nameIDs"] != nil { var nameIDs []int - if err = utils.UnmarshalUseNumber([]byte(params["nameIDs"].(string)), &nameIDs); err != nil { - return nil, err + if ids, ok := params["nameIDs"].([]int); ok { + nameIDs = ids + } else { + if err = utils.UnmarshalUseNumber([]byte(params["nameIDs"].(string)), &nameIDs); err != nil { + return nil, err + } } if len(nameIDs) > 0 { sql += " AND t1.id IN (" + dao.GenQuestionMarks(len(nameIDs)) + ")" @@ -1471,7 +1477,7 @@ func DeleteSkuNameExPrefixOverdue(db *dao.DaoDB) (err error) { func SumExianDaDepot(ctx *jxcontext.Context) (err error) { db := dao.GetDB() - result, err := api.EbaiAPI.GetExianDaSkuDepot() + result, err := api.EbaiAPI.GetExianDaSkuDepot("") for _, v := range result { skus, err := api.EbaiAPI.GetExianDaSku(utils.Str2Int64(v.ElemeGoodsID)) if err != nil { @@ -1579,3 +1585,127 @@ func CopyEbaiStoreSkusToJx(ctx *jxcontext.Context, baiduShopID string, storeID i UpdateStoresSkusByBind(ctx, nil, storeSkuBindInfo, true, true) return err } + +func AddExdSkuByExcel(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) { + var ( + db = dao.GetDB() + skuMap = make(map[string]string) + ) + taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { + switch step { + case 0: + xlsx, err := excelize.OpenFile("111.xlsx") + // xlsx, err := excelize.OpenReader(reader) + if err != nil { + return result, err + } + rows, _ := xlsx.GetRows(xlsx.GetSheetName(1)) + for rowNum, row := range rows { + if rowNum < 2 { + continue + } + var ( + name string + upc string + ) + for k, cell := range row { + if k == 2 { + name = cell + } + if k == 7 { + upc = cell + } + } + skuMap[upc] = name + } + case 1: + for k, _ := range skuMap { + fmt.Println(k, skuMap[k]) + result, err := api.EbaiAPI.GetExianDaSkuDepot(k) + if err != nil { + return result, err + } + exdSku := result[0] + skus, err := api.EbaiAPI.GetExianDaSku(utils.Str2Int64(exdSku.ElemeGoodsID)) + skuName := &model.SkuName{} + sql2 := ` + SELECT a.* + FROM sku_name a + JOIN sku b ON b.name_id = a.id + WHERE a.upc = ? + AND b.exd_sku_id <> '' + ` + sqlParams2 := []interface{}{ + k, + } + dao.GetRow(db, skuName, sql2, sqlParams2) + dao.Begin(db) + defer func() { + if r := recover(); r != nil { + dao.Rollback(db) + panic(r) + } + }() + //表示京西库中已存在此饿鲜达商品,再判断更不更新名字 + if skuName != nil { + if skuName.Name != skuMap[k] { + skuName.Name = skuMap[k] + _, err = dao.UpdateEntity(db, skuName, "Name") + if err != nil { + dao.Rollback(db) + return result, err + } + } + } else { + //插入 + prefix, _, _, specUnit, unit, specQuality := jxutils.SplitSkuName(exdSku.GoodsName) + skuName2 := &model.SkuName{ + Prefix: prefix, + Name: skuMap[k], + CategoryID: skus.CategoryIDThird, + IsGlobal: 1, + Unit: unit, + SpecQuality: specQuality, + SpecUnit: specUnit, + Price: 100, + Img: exdSku.ImageURL, + Upc: &k, + Status: model.SkuStatusNormal, + } + dao.WrapAddIDCULDEntity(skuName2, ctx.GetUserName()) + err = dao.CreateEntity(db, skuName2) + if err != nil { + dao.Rollback(db) + return result, err + } + sku := &model.Sku{ + NameID: skuName2.ID, + SpecQuality: specQuality, + SpecUnit: specUnit, + Weight: int(utils.Str2Int64(skus.Weight)), + Status: model.SkuStatusNormal, + ExdSkuID: exdSku.ElemeGoodsID, + ExdCategoryThirdID: skus.CategoryIDThird, + } + dao.WrapAddIDCULDEntity(sku, ctx.GetUserName()) + err = dao.CreateEntity(db, sku) + if err != nil { + dao.Rollback(db) + return result, err + } + } + dao.Commit(db) + } + } + return result, err + } + taskSeq := tasksch.NewSeqTask2("创建饿鲜达商品", ctx, isContinueWhenError, taskSeqFunc, 2) + tasksch.HandleTask(taskSeq, nil, true).Run() + if !isAsync { + _, err = taskSeq.GetResult(0) + hint = "1" + } else { + hint = taskSeq.GetID() + } + return hint, err +} diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 06e30d233..28a8b12e5 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -3341,7 +3341,10 @@ func UpdateStoreSkusSpecTagBin(ctx *jxcontext.Context, reader io.Reader, vendorI storeSkuInfos[len(storeSkuInfos)-i-1] = tmp } for _, v := range vendorIDs { - store, _ := dao.GetStoreDetail(db, storeID, v) + store, err := dao.GetStoreDetail(db, storeID, v) + if err != nil || store == nil { + continue + } for _, vv := range apimanager.CurAPIManager.GetAppOrgCodeList(v) { handler := partner.GetPurchasePlatformFromVendorID(v).(partner.IPurchasePlatformStoreSkuHandler) err = handler.UpdateStoreSkusSpecTag(ctx, vv, storeID, store.VendorStoreID, storeSkuMap[storeID]) diff --git a/controllers/cms_sku.go b/controllers/cms_sku.go index a7675d1ab..f88525e98 100644 --- a/controllers/cms_sku.go +++ b/controllers/cms_sku.go @@ -461,3 +461,20 @@ func (c *SkuController) CopyEbaiStoreSkusToJx() { return retVal, "", err }) } + +// @Title 通过Excel创建饿鲜达商品(必须先要在饿鲜达系统中创建) +// @Description 通过Excel创建饿鲜达商品(必须先要在饿鲜达系统中创建) +// @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 /AddExdSkuByExcel [post] +func (c *SkuController) AddExdSkuByExcel() { + c.callAddExdSkuByExcel(func(params *tSkuAddExdSkuByExcelParams) (retVal interface{}, errCode string, err error) { + // r := c.Ctx.Request + // files := r.MultipartForm.File["userfiles"] + retVal, err = cms.AddExdSkuByExcel(params.Ctx, params.IsAsync, params.IsContinueWhenError) + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 688856bed..cafde1267 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1224,6 +1224,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"], + beego.ControllerComments{ + Method: "AddExdSkuByExcel", + Router: `/AddExdSkuByExcel`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"], beego.ControllerComments{ Method: "AddSku", From c7daa3c4790195e0a650a55467bae4e08be40445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 20 Feb 2020 11:06:47 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E7=BE=8E=E5=9B=A2=E5=8A=9B=E8=8D=90?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 28a8b12e5..f9816ad3c 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -3340,16 +3340,21 @@ func UpdateStoreSkusSpecTagBin(ctx *jxcontext.Context, reader io.Reader, vendorI storeSkuInfos[i] = storeSkuInfos[len(storeSkuInfos)-i-1] storeSkuInfos[len(storeSkuInfos)-i-1] = tmp } - for _, v := range vendorIDs { - store, err := dao.GetStoreDetail(db, storeID, v) + for _, v := range storeSkuInfos { + store, err := dao.GetStoreDetail(db, storeID, model.VendorIDMTWM) if err != nil || store == nil { continue } - for _, vv := range apimanager.CurAPIManager.GetAppOrgCodeList(v) { - handler := partner.GetPurchasePlatformFromVendorID(v).(partner.IPurchasePlatformStoreSkuHandler) - err = handler.UpdateStoreSkusSpecTag(ctx, vv, storeID, store.VendorStoreID, storeSkuMap[storeID]) + var foodData = make(map[string]interface{}) + if v.IsSpecialty != 0 && v.IsSpecialty == -1 { + v.IsSpecialty = 0 + } + foodData["is_specialty"] = v.IsSpecialty + if globals.EnableMtwmStoreWrite { + err = api.MtwmAPI.RetailInitData(ctx.GetTrackInfo(), store.VendorStoreID, utils.Int2Str(v.SkuID), foodData) } } + } } return result, err From 4ea2b7d044bd8a3b44bc35a031766fc9c060d394 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 20 Feb 2020 09:24:16 +0800 Subject: [PATCH 6/8] weimob order nameIDs --- business/cs/weimob_order.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/cs/weimob_order.go b/business/cs/weimob_order.go index f487a5290..6cece1baa 100644 --- a/business/cs/weimob_order.go +++ b/business/cs/weimob_order.go @@ -73,7 +73,7 @@ func changeStoreSkusByOrder(order *weimobapi.OrderDetail) { nameIDs = append(nameIDs, v.NameID) } if skuNamesInfo, err := cms.GetSkuNames(ctx, "", false, map[string]interface{}{ - "nameIDs": nameIDs, + "nameIDs": string(utils.MustMarshal(nameIDs)), }, 0, 0); err == nil { for _, skuName := range skuNamesInfo.SkuNames { if skuName.Status != model.SkuStatusNormal { From db1ac781c78c6f9933cd261368a51be07840f337 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 20 Feb 2020 12:10:08 +0800 Subject: [PATCH 7/8] =?UTF-8?q?updateSingleOrderEarningPrice=E4=B8=AD?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8v.SkuID=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 21c2445bf..82326ba96 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -374,7 +374,9 @@ func updateSingleOrderEarningPrice(order *model.GoodsOrder, db *dao.DaoDB) { jxStoreID := jxutils.GetShowStoreIDFromOrder(order) skuIDMap := make(map[int]int) for _, v := range order.Skus { - skuIDMap[v.SkuID] = 1 + if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 { + skuIDMap[skuID] = 1 + } } if len(skuIDMap) > 0 { actStoreSkuList, err := dao.GetEffectiveActStoreSkuInfo(db, 0, []int{order.VendorID}, model.ActTypeAll, []int{jxStoreID}, jxutils.IntMap2List(skuIDMap), order.OrderCreatedAt, order.OrderCreatedAt) From 5af6ecf0c5f980357b50d01ba805e9a35787b09c Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 20 Feb 2020 12:46:36 +0800 Subject: [PATCH 8/8] up --- business/jxcallback/orderman/financial.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/business/jxcallback/orderman/financial.go b/business/jxcallback/orderman/financial.go index f00091462..f253fd30a 100644 --- a/business/jxcallback/orderman/financial.go +++ b/business/jxcallback/orderman/financial.go @@ -111,6 +111,9 @@ func (c *OrderManager) SaveOrderFinancialInfo(order *model.OrderFinancial, opera } if len(order.Skus) > 0 { sku := order.Skus[0] + if sku.SkuID > math.MaxInt32 { + sku.SkuID = 0 + } sku.UserMoney = order.SalePriceMoney - order.DiscountMoney - sku.UserMoney sku.PmSubsidyMoney = platOrderGoodsDiscountMoney + order.SelfDeliveryDiscountMoney - sku.PmSubsidyMoney sku.JxSubsidyMoney = order.JxSubsidyMoney - sku.JxSubsidyMoney