From c607fa931c81d64aa96d5b1f9cb8956aec3ade1d Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 08:56:02 +0800 Subject: [PATCH 01/11] + JdPageAPI --- business/netspider/netspider.go | 2 +- business/partner/purchase/jd/net_spider.go | 5 +++-- globals/api/api.go | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/business/netspider/netspider.go b/business/netspider/netspider.go index 796800164..1fa9d1f7e 100644 --- a/business/netspider/netspider.go +++ b/business/netspider/netspider.go @@ -53,7 +53,7 @@ func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask, if handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformNetSpiderHandler); handler != nil { mainStoreIDList, _ := handler.GetStoreIDListByCoordinates(ctx, coordList[0]) if len(mainStoreIDList) > 0 { - task1 := tasksch.NewParallelTask(fmt.Sprintf("GetStoreListByCoordinate[%s] get list", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, + task1 := tasksch.NewParallelTask(fmt.Sprintf("GetStoreListByCoordinate[%s] get list", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true).SetParallelCount(1), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { pos := batchItemList[0].(*ditu.Coordinate) storeIDList, err := handler.GetStoreIDListByCoordinates(ctx, pos) diff --git a/business/partner/purchase/jd/net_spider.go b/business/partner/purchase/jd/net_spider.go index 924ff64e0..f9e566a26 100644 --- a/business/partner/purchase/jd/net_spider.go +++ b/business/partner/purchase/jd/net_spider.go @@ -12,8 +12,9 @@ import ( ) func (c *PurchaseHandler) GetStoreIDListByCoordinates(ctx *jxcontext.Context, coord *ditu.Coordinate) (storeIDList []string, err error) { - shopListInfo, err := api.JdAPI.GetStoreList(fmt.Sprintf("%.6f", coord.Lng), fmt.Sprintf("%.6f", coord.Lat)) + shopListInfo, err := api.JdPageAPI.GetStoreList(fmt.Sprintf("%.6f", coord.Lng), fmt.Sprintf("%.6f", coord.Lat)) if err != nil { + // time.Sleep(5 * time.Second) return nil, err } if shopListInfo != nil { @@ -27,7 +28,7 @@ func (c *PurchaseHandler) GetStoreIDListByCoordinates(ctx *jxcontext.Context, co } func (c *PurchaseHandler) GetStorePageInfo(ctx *jxcontext.Context, cityInfo, storeID string) (storePageInfo *model.PageShop, err error) { - shopInfo, err2 := api.JdAPI.GetStoreInfo2(storeID) + shopInfo, err2 := api.JdPageAPI.GetStoreInfo2(storeID) if err = err2; err == nil && shopInfo != nil { var lng, lat float64 districtCode := 0 diff --git a/globals/api/api.go b/globals/api/api.go index b4a8d3d2f..dd14840a1 100644 --- a/globals/api/api.go +++ b/globals/api/api.go @@ -28,6 +28,7 @@ import ( var ( JdAPI *jdapi.API + JdPageAPI *jdapi.API ElmAPI *elmapi.API EbaiAPI *ebaiapi.API MtpsAPI *mtpsapi.API @@ -67,6 +68,10 @@ func Init() { cookieValue := beego.AppConfig.DefaultString("jdStorePageCookie", "") JdAPI.SetCookie("shop.o2o.jd.com1", cookieValue) JdAPI.SetCookie("lsp-store1.jddj.com", cookieValue) + + conf := platformapi.NewDefAPIConfig() + conf.MaxSleepSecondWhenExceedLimit = 60 * 30 // 最大重试间隙30分钟 + JdPageAPI = jdapi.NewPageOnly(cookieValue, conf) } else { JdAPI = nil } From 3c5f25b839abf798906d3cb2ffe4c7b5781a35a7 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 12:40:14 +0800 Subject: [PATCH 02/11] + SyncStoresQualify --- business/jxstore/cms/store.go | 32 ++++++++ business/partner/partner_store.go | 10 ++- business/partner/purchase/jd/store.go | 87 ++++++++++++++++++++++ business/partner/purchase/jd/store_test.go | 12 +++ controllers/cms_store.go | 20 +++++ routers/commentsRouter_controllers.go | 9 +++ 6 files changed, 169 insertions(+), 1 deletion(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 4f8686350..f2387ff2b 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -1707,3 +1707,35 @@ func SaveAndSendAlarmVendorSnapshot(ctx *jxcontext.Context, vendorIDs, storeIDs } return err } + +func SyncStoresQualify(ctx *jxcontext.Context, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) { + if len(storeIDs) > 0 { + db := dao.GetDB() + task := tasksch.NewParallelTask("上传门店资质", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, + func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + vendorID := model.VendorIDJD + if handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IStoreSyncQualifyHandler); handler != nil { + storeID := batchItemList[0].(int) + storeDetail, err := dao.GetStoreDetail(db, storeID, vendorID) + if err == nil { + if err = handler.SyncQualify(ctx, storeDetail); err == nil { + retVal = []int{1} + } + } + } else { + err = fmt.Errorf("平台%s不支持此操作", model.VendorChineseNames[vendorID]) + } + return retVal, err + }, storeIDs) + tasksch.HandleTask(task, nil, true).Run() + if isAsync { + hint = task.GetID() + } else { + resultList, err2 := task.GetResult(0) + if err = err2; err == nil { + hint = utils.Int2Str(len(resultList)) + } + } + } + return hint, err +} diff --git a/business/partner/partner_store.go b/business/partner/partner_store.go index 37994fb41..7f961b837 100644 --- a/business/partner/partner_store.go +++ b/business/partner/partner_store.go @@ -1,6 +1,9 @@ package partner -import "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" +import ( + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + "git.rosy.net.cn/jx-callback/business/model/dao" +) type IStoreHandler interface { GetAllStoresVendorID(ctx *jxcontext.Context) (vendorStoreIDs []string, err error) @@ -9,3 +12,8 @@ type IStoreHandler interface { // opTime格式为整数1130代表11:30 UpdateStoreOpTime(ctx *jxcontext.Context, storeID int, vendorStoreID string, opTimeList []int16) (err error) } + +// 同步资质信息至平台 +type IStoreSyncQualifyHandler interface { + SyncQualify(ctx *jxcontext.Context, storeDetail *dao.StoreDetail) (err error) +} diff --git a/business/partner/purchase/jd/store.go b/business/partner/purchase/jd/store.go index 7e3f3a380..2d35e75d3 100644 --- a/business/partner/purchase/jd/store.go +++ b/business/partner/purchase/jd/store.go @@ -357,3 +357,90 @@ func (c *PurchaseHandler) GetAllStoresVendorID(ctx *jxcontext.Context) (vendorSt vendorStoreIDs, err = api.JdAPI.GetStationsByVenderId() return vendorStoreIDs, err } + +func (c *PurchaseHandler) storeUploadImgByURL(inImgURL string) (imgURL string, err error) { + if globals.EnableJdStoreWrite { + imgURL, err = api.JdPageAPI.StoreUploadImgByURL(inImgURL) + } else { + imgURL = utils.GetUUID() + } + return imgURL, err +} + +func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.StoreDetail) (err error) { + if storeDetail.LicenceCode == "" || storeDetail.Licence == "" { + return fmt.Errorf("营业执照信息不全") + } + if storeDetail.IDCode == "" || storeDetail.IDCardFront == "" || storeDetail.IDCardBack == "" || storeDetail.IDValid == "" { + return fmt.Errorf("个人信息不全") + } + var qualifyList []*jdapi.QualifyItem + licenceDetail, err := api.JdPageAPI.GetCorporationInfo(storeDetail.VendorStoreID, storeDetail.LicenceCode) + if err != nil { + return err + } + licenceURL, err := c.storeUploadImgByURL(storeDetail.Licence) + if err != nil { + return err + } + qualifyList = append(qualifyList, &jdapi.QualifyItem{ + QualifyType: jdapi.QualifyTypeCompany, + QualifyURL: licenceURL, + QualifyExpireStart: licenceDetail.StartDate, + QualifyExpireForever: 0, + QualifyName: licenceDetail.OperName, + LicenceType: "-1", + QualifyNumber: storeDetail.LicenceCode, + QualifyAddress: licenceDetail.Address, + LicenceName: licenceDetail.Name, + EconKind: licenceDetail.EconKind, + Scope: licenceDetail.Scope, + }) + if licenceDetail.EconKind == jdapi.LincenceEconKindPerson { // 个人 + idFrondURL, err := c.storeUploadImgByURL(storeDetail.IDCardFront) + if err != nil { + return err + } + personQualify := &jdapi.QualifyItem{ + QualifyType: jdapi.QualifyTypePerson, + QualifyURL: idFrondURL, + QualifyExpireStart: storeDetail.IDValid, + QualifyNumber: storeDetail.IDCode, + QualifyOwner: storeDetail.LicenceOwnerName, + } + if storeDetail.IDExpire == "" { + personQualify.QualifyExpireForever = 0 + } else { + personQualify.QualifyExpireForever = 1 + personQualify.QualifyExpireEnd = storeDetail.IDExpire + } + qualifyList = append(qualifyList, personQualify) + } else { + idFrondURL, err := c.storeUploadImgByURL(storeDetail.IDCardFront) + if err != nil { + return err + } + qualifyList = append(qualifyList, &jdapi.QualifyItem{ + QualifyType: jdapi.QualifyTypeAddInfo, + QualifyURL: idFrondURL, + QualifyExpireForever: 1, + }) + } + if storeDetail.IDExpire == "" { + idBackURL, err := c.storeUploadImgByURL(storeDetail.IDCardBack) + if err != nil { + return err + } + qualifyList = append(qualifyList, &jdapi.QualifyItem{ + QualifyType: jdapi.QualifyTypeAddInfo, + QualifyURL: idBackURL, + QualifyExpireForever: 1, + }) + } + globals.SugarLogger.Debug(utils.Format4Output(qualifyList, false)) + if globals.EnableJdStoreWrite { + // err = api.JdPageAPI.SaveQualify(storeDetail.VendorStoreID, jdapi.SaveQualifyActionTypeCommit, qualifyList) + err = api.JdPageAPI.SaveQualify(storeDetail.VendorStoreID, jdapi.SaveQualifyActionTypeSave, qualifyList) + } + return err +} diff --git a/business/partner/purchase/jd/store_test.go b/business/partner/purchase/jd/store_test.go index eac91d3e8..a18f80ec4 100644 --- a/business/partner/purchase/jd/store_test.go +++ b/business/partner/purchase/jd/store_test.go @@ -5,6 +5,7 @@ import ( "testing" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/model/dao" @@ -81,3 +82,14 @@ func TestUpdateStore2(t *testing.T) { // t.Fatal("result doesn't match") // } // } + +func TestSyncQualify(t *testing.T) { + storeDetail, err := dao.GetStoreDetail(dao.GetDB(), 102610, model.VendorIDJD) + if err != nil { + t.Fatal(err.Error()) + } + err = curPurchaseHandler.SyncQualify(jxcontext.AdminCtx, storeDetail) + if err != nil { + t.Fatal(err.Error()) + } +} diff --git a/controllers/cms_store.go b/controllers/cms_store.go index 9dcae6060..3e309b1bc 100644 --- a/controllers/cms_store.go +++ b/controllers/cms_store.go @@ -400,3 +400,23 @@ func (c *StoreController) BindPrinter() { return retVal, "", err }) } + +// @Title 同步门店资质信息至平台(当前只支持京东) +// @Description 同步门店资质信息至平台(当前只支持京东) +// @Param token header string true "认证token" +// @Param storeIDs formData string true "京西门店ID列表,必须非空值" +// @Param isAsync formData bool true "是否异步操作" +// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /SyncStoresQualify [post] +func (c *StoreController) SyncStoresQualify() { + c.callSyncStoresQualify(func(params *tStoreSyncStoresQualifyParams) (retVal interface{}, errCode string, err error) { + var storeIDs []int + err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs) + if err == nil { + retVal, err = cms.SyncStoresQualify(params.Ctx, storeIDs, params.IsAsync, params.IsContinueWhenError) + } + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 8fd2aa156..a9259ea78 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1258,6 +1258,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: "SyncStoresQualify", + Router: `/SyncStoresQualify`, + 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: "TmpGetJxBadComments", From 26484d45e381419c8c267eeff4bc2335c02df86c Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 15:38:59 +0800 Subject: [PATCH 03/11] =?UTF-8?q?-=20jd.SyncQualify=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/jd/store.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/business/partner/purchase/jd/store.go b/business/partner/purchase/jd/store.go index 2d35e75d3..0d36535db 100644 --- a/business/partner/purchase/jd/store.go +++ b/business/partner/purchase/jd/store.go @@ -439,8 +439,8 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S } globals.SugarLogger.Debug(utils.Format4Output(qualifyList, false)) if globals.EnableJdStoreWrite { - // err = api.JdPageAPI.SaveQualify(storeDetail.VendorStoreID, jdapi.SaveQualifyActionTypeCommit, qualifyList) - err = api.JdPageAPI.SaveQualify(storeDetail.VendorStoreID, jdapi.SaveQualifyActionTypeSave, qualifyList) + err = api.JdPageAPI.SaveQualify(storeDetail.VendorStoreID, jdapi.SaveQualifyActionTypeCommit, qualifyList) + // err = api.JdPageAPI.SaveQualify(storeDetail.VendorStoreID, jdapi.SaveQualifyActionTypeSave, qualifyList) } return err } From dd201a58fb024a53a8f3f80b8d8c3836c8d3c5b2 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 15:50:13 +0800 Subject: [PATCH 04/11] - up --- business/jxstore/cms/store.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index f2387ff2b..edf11d8fe 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -1716,8 +1716,8 @@ func SyncStoresQualify(ctx *jxcontext.Context, storeIDs []int, isAsync, isContin vendorID := model.VendorIDJD if handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IStoreSyncQualifyHandler); handler != nil { storeID := batchItemList[0].(int) - storeDetail, err := dao.GetStoreDetail(db, storeID, vendorID) - if err == nil { + storeDetail, err2 := dao.GetStoreDetail(db, storeID, vendorID) + if err = err2; err == nil { if err = handler.SyncQualify(ctx, storeDetail); err == nil { retVal = []int{1} } From 7aa548e1dcdc80628f684fdcaad2841f674510fc Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 16:29:26 +0800 Subject: [PATCH 05/11] =?UTF-8?q?-=20=E4=BA=AC=E4=B8=9C=E5=88=B0=E5=AE=B6?= =?UTF-8?q?=E8=B5=84=E8=B4=A8=E7=9B=B8=E5=85=B3=E7=9A=84=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/jd/store.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/business/partner/purchase/jd/store.go b/business/partner/purchase/jd/store.go index 0d36535db..ac7e91514 100644 --- a/business/partner/purchase/jd/store.go +++ b/business/partner/purchase/jd/store.go @@ -386,7 +386,7 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S qualifyList = append(qualifyList, &jdapi.QualifyItem{ QualifyType: jdapi.QualifyTypeCompany, QualifyURL: licenceURL, - QualifyExpireStart: licenceDetail.StartDate, + QualifyExpireStart: utils.Time2Str(utils.Str2Time(licenceDetail.StartDate)), QualifyExpireForever: 0, QualifyName: licenceDetail.OperName, LicenceType: "-1", @@ -404,7 +404,7 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S personQualify := &jdapi.QualifyItem{ QualifyType: jdapi.QualifyTypePerson, QualifyURL: idFrondURL, - QualifyExpireStart: storeDetail.IDValid, + QualifyExpireStart: utils.Time2Str(utils.Str2Time(storeDetail.IDValid)), QualifyNumber: storeDetail.IDCode, QualifyOwner: storeDetail.LicenceOwnerName, } @@ -412,7 +412,7 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S personQualify.QualifyExpireForever = 0 } else { personQualify.QualifyExpireForever = 1 - personQualify.QualifyExpireEnd = storeDetail.IDExpire + personQualify.QualifyExpireEnd = utils.Time2Str(utils.Str2Time(storeDetail.IDExpire)) } qualifyList = append(qualifyList, personQualify) } else { From 89ee6b5006ad6f322caff720c292d28fd9347f64 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 16:41:05 +0800 Subject: [PATCH 06/11] =?UTF-8?q?-=20SyncQualify=E4=B8=AD=E6=A0=B9?= =?UTF-8?q?=E6=8D=AEStore.LicenceType=E6=9D=A5=E5=88=A4=E6=96=AD=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=98=AF=E4=B8=AA=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/jd/store.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/business/partner/purchase/jd/store.go b/business/partner/purchase/jd/store.go index ac7e91514..940d52720 100644 --- a/business/partner/purchase/jd/store.go +++ b/business/partner/purchase/jd/store.go @@ -396,7 +396,8 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S EconKind: licenceDetail.EconKind, Scope: licenceDetail.Scope, }) - if licenceDetail.EconKind == jdapi.LincenceEconKindPerson { // 个人 + // 个体经营,个体工商户 + if storeDetail.LicenceType == 0 { // 个人 idFrondURL, err := c.storeUploadImgByURL(storeDetail.IDCardFront) if err != nil { return err From f92ff76b6102f51533fd9463efbfe97be0f76721 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 16:47:55 +0800 Subject: [PATCH 07/11] =?UTF-8?q?-=20=E6=B7=BB=E5=8A=A0alpha=E7=9A=84?= =?UTF-8?q?=E4=BA=AC=E4=B8=9C=E7=BD=91=E9=A1=B5cookie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/app.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/app.conf b/conf/app.conf index 65b4fe750..ee021b122 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -248,7 +248,7 @@ httpport = 8088 jdToken = "df97f334-f7d8-4b36-9664-5784d8ae0baf" jdAppKey = "06692746f7224695ad4788ce340bc854" jdSecret = "d6b42a35a7414a5490d811654d745c84" - +jdStorePageCookie = "5EOCZRXVCRXBTYD5EPV6FOXRCQWFFQO75FRMJ3BAKZ5JXY6XTJECMWXK5OZIPLZTUWZKZKXHXA6I7G3WMIKSWOHZIHRLNE5FZY3NBD6G5IMBOYHMJSJR3RF4TMZB2JEW2DF755YPFUSA6BMWI3KNLT3I4EAP2Z4JA6ZWAA34MNQX5P6LOI4EGG76QJU3G3VW7QFE6BAVAONMKBEHKNXNZGX3RQF7PHXDXSPJSY5XQEGM7IV2L7LKIG3M2D6QVSPEGQW4NV7SZ4TX32D2XQA7PIX46M" disableElm = true ebaiSource = "62289" From 5e6c087ba2740743654d5d356436962cf4bde856 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 17:14:23 +0800 Subject: [PATCH 08/11] =?UTF-8?q?-=20jd.SyncQualify=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/jd/store.go | 44 +++++++++++++++------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/business/partner/purchase/jd/store.go b/business/partner/purchase/jd/store.go index 940d52720..0d5aa3894 100644 --- a/business/partner/purchase/jd/store.go +++ b/business/partner/purchase/jd/store.go @@ -396,36 +396,39 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S EconKind: licenceDetail.EconKind, Scope: licenceDetail.Scope, }) + + idFrondURL, err := c.storeUploadImgByURL(storeDetail.IDCardFront) + if err != nil { + return err + } // 个体经营,个体工商户 if storeDetail.LicenceType == 0 { // 个人 - idFrondURL, err := c.storeUploadImgByURL(storeDetail.IDCardFront) - if err != nil { - return err - } personQualify := &jdapi.QualifyItem{ - QualifyType: jdapi.QualifyTypePerson, - QualifyURL: idFrondURL, - QualifyExpireStart: utils.Time2Str(utils.Str2Time(storeDetail.IDValid)), - QualifyNumber: storeDetail.IDCode, - QualifyOwner: storeDetail.LicenceOwnerName, + QualifyType: jdapi.QualifyTypePerson, + QualifyURL: idFrondURL, + QualifyExpireStart: utils.Time2Str(utils.Str2Time(storeDetail.IDValid)), + QualifyExpireForever: 0, + + QualifyNumber: storeDetail.IDCode, + QualifyOwner: storeDetail.LicenceOwnerName, } - if storeDetail.IDExpire == "" { - personQualify.QualifyExpireForever = 0 - } else { + if storeDetail.IDExpire != "" { personQualify.QualifyExpireForever = 1 personQualify.QualifyExpireEnd = utils.Time2Str(utils.Str2Time(storeDetail.IDExpire)) } qualifyList = append(qualifyList, personQualify) } else { - idFrondURL, err := c.storeUploadImgByURL(storeDetail.IDCardFront) - if err != nil { - return err - } - qualifyList = append(qualifyList, &jdapi.QualifyItem{ + addInfo := &jdapi.QualifyItem{ QualifyType: jdapi.QualifyTypeAddInfo, QualifyURL: idFrondURL, - QualifyExpireForever: 1, - }) + QualifyExpireStart: utils.Time2Str(utils.Str2Time(storeDetail.IDValid)), + QualifyExpireForever: 0, + } + if storeDetail.IDExpire != "" { + addInfo.QualifyExpireForever = 1 + addInfo.QualifyExpireEnd = utils.Time2Str(utils.Str2Time(storeDetail.IDExpire)) + } + qualifyList = append(qualifyList, addInfo) } if storeDetail.IDExpire == "" { idBackURL, err := c.storeUploadImgByURL(storeDetail.IDCardBack) @@ -435,7 +438,8 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S qualifyList = append(qualifyList, &jdapi.QualifyItem{ QualifyType: jdapi.QualifyTypeAddInfo, QualifyURL: idBackURL, - QualifyExpireForever: 1, + QualifyExpireStart: utils.Time2Str(utils.Str2Time(storeDetail.IDValid)), + QualifyExpireForever: 0, }) } globals.SugarLogger.Debug(utils.Format4Output(qualifyList, false)) From b36f8b3ae1ab60ab6acf2ee74a2a0e7e716626f6 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 18:43:55 +0800 Subject: [PATCH 09/11] =?UTF-8?q?-=20UpdateStoresSkusSale=E4=B8=AD?= =?UTF-8?q?=E5=AF=B9=E4=BA=8EautoSaleAt=E6=8C=89=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E8=AE=BE=E7=BD=AE=E5=A4=84=E7=90=86=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E7=AE=A1=E5=AE=A2=E6=88=B7=E7=AB=AF=E4=BC=A0=E7=9A=84=E5=85=B7?= =?UTF-8?q?=E4=BD=93=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 12 ++++++++++++ business/jxstore/misc/misc.go | 2 +- business/model/api_config.go | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index ef0b820f2..9d904f2e1 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -163,6 +163,8 @@ type tGetStoresSkusInfo struct { const ( maxStoreNameBind = 3000 // 最大门店SkuName bind个数 maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数 + + AutoSaleAtStr = "20:25:00" ) func GetStoreSkus(ctx *jxcontext.Context, storeID int, skuIDs []int, isFocus bool, keyword string, isBySku bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) { @@ -1307,6 +1309,15 @@ func getSkuSaleStatus(inSkuBind *StoreSkuBindSkuInfo, skuBindInfo *StoreSkuBindI return model.StoreSkuBindStatusNA } +func formatAutoSaleTime(autoSaleTime time.Time) (outAutoSaleTime time.Time) { + if utils.IsTimeZero(autoSaleTime) { + outAutoSaleTime = utils.DefaultTimeValue + } else { + outAutoSaleTime = jxutils.GetNextTimeFromList(time.Now(), []string{AutoSaleAtStr}) + } + return outAutoSaleTime +} + // todo 应该用updateStoresSkusWithoutSync实现 func updateStoreSkusSaleWithoutSync(ctx *jxcontext.Context, storeID int, skuBindSkuInfos []*StoreSkuBindSkuInfo, autoSaleTime time.Time, userName string) (needSyncSkus []int, err error) { var num int64 @@ -1331,6 +1342,7 @@ func updateStoreSkusSaleWithoutSync(ctx *jxcontext.Context, storeID int, skuBind dao.Rollback(db) return nil, err } + autoSaleTime = formatAutoSaleTime(autoSaleTime) for _, skuBind := range storeSkuList { if v := skuBindSkuInfosMap[skuBind.SkuID]; v != nil && v.IsSale != 0 { if v.IsSale == 1 { diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 398cb170d..7895ca639 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -52,7 +52,7 @@ var ( } autoSaleStoreSkuTimeList = []string{ - "20:20:00", + cms.AutoSaleAtStr, } importantTaskMap = &sync.Map{} diff --git a/business/model/api_config.go b/business/model/api_config.go index 1aad8ff93..3c879208f 100644 --- a/business/model/api_config.go +++ b/business/model/api_config.go @@ -3,9 +3,9 @@ package model type AppKeyConfig struct { ModelIDCULD VendorID int - AppKey string // 同一平台下不同的Key + AppCode string // 同一平台下不同的商户代码 - Name string + AppName string AppType int Value1 string Value2 string From 14e3594455f70d90ca8f6ce7dc84564dfae3c3d9 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 16 Aug 2019 11:08:09 +0800 Subject: [PATCH 10/11] =?UTF-8?q?-=20GetStoresOrderSaleInfo=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=94=AE=E5=90=8E=E5=8D=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 30 ++++++------- business/jxcallback/orderman/orderman_ext.go | 2 +- business/jxutils/jxutils.go | 2 + business/model/dao/dao_order.go | 44 ++++++++++++++++---- business/model/order.go | 4 +- business/model/order_financial.go | 7 ++++ 6 files changed, 62 insertions(+), 27 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index ce452d802..df4209051 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -236,7 +236,7 @@ func (c *OrderManager) SaveOrder(order *model.GoodsOrder, isAdjust bool, db *dao return isDuplicated, err } -func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.DaoDB) (err error) { +func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.DaoDB, storePayPercentage int) (err error) { globals.SugarLogger.Debugf("updateOrderSkuOtherInfo orderID:%s, VendorStoreID:%s", order.VendorOrderID, order.VendorStoreID) jxStoreID := jxutils.GetShowStoreIDFromOrder(order) var opNumStr string @@ -316,10 +316,10 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao. v.JxSkuID = skuBindInfo.SkuID v.ShopPrice = int64(skuBindInfo.Price) v.Weight = skuBindInfo.Weight // 以本地信息中的WEIGHT为准 - order.ShopPrice += v.ShopPrice * int64(v.Count) if skuBindInfo.Price == 0 { globals.SugarLogger.Infof("updateOrderSkuOtherInfo [运营%s]%s订单sku门店价格为零(一般原因为没有门店价格信息),orderID:%s, StoreID:%d, SkuID:%d, sku:%v", opNumStr, model.VendorChineseNames[order.VendorID], order.VendorOrderID, jxStoreID, v.JxSkuID, v) } + v.EarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage) } } @@ -335,7 +335,7 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao. if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 { if actStoreSku := actStoreSkuMap.GetActStoreSku(jxStoreID, skuID, order.VendorID); actStoreSku != nil { v.EarningPrice = actStoreSku.EarningPrice - if v.StoreSubName != "" { + if true { //v.StoreSubName != "" { // 之前这里为什么要加判断? v.StoreSubID = actStoreSku.ActID } } @@ -361,24 +361,24 @@ func (c *OrderManager) updateOrderOtherInfo(order *model.GoodsOrder, db *dao.Dao order.JxStoreID = storeDetail.Store.ID payPercentage = storeDetail.PayPercentage } - if err = c.updateOrderSkuOtherInfo(order, db); err == nil { + if err = c.updateOrderSkuOtherInfo(order, db, payPercentage); err == nil { jxutils.RefreshOrderSkuRelated(order) - caculateOrderEarningPrice(order, payPercentage) + // caculateOrderEarningPrice(order, payPercentage) } return err } // 计算结算给门店的金额 -func caculateOrderEarningPrice(order *model.GoodsOrder, storePayPercentage int) { - order.EarningPrice = 0 - for _, v := range order.Skus { - skuEarningPrice := v.EarningPrice - if skuEarningPrice == 0 { - skuEarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage) - } - order.EarningPrice += skuEarningPrice * int64(v.Count) - } -} +// func caculateOrderEarningPrice(order *model.GoodsOrder, storePayPercentage int) { +// order.EarningPrice = 0 +// for _, v := range order.Skus { +// skuEarningPrice := v.EarningPrice +// if skuEarningPrice == 0 { +// skuEarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage) +// } +// order.EarningPrice += skuEarningPrice * int64(v.Count) +// } +// } func (c *OrderManager) addOrderStatus(orderStatus *model.OrderStatus, db *dao.DaoDB) (isDuplicated bool, order *model.GoodsOrder, err error) { globals.SugarLogger.Debugf("addOrderStatus refOrderID:%s, orderID:%s", orderStatus.RefVendorOrderID, orderStatus.VendorOrderID) diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index 5c33c44e4..3b2ace132 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -907,7 +907,7 @@ func (c *OrderManager) getAfsOrderSkuInfo4ExportOrders(ctx *jxcontext.Context, f SELECT t2.* FROM afs_order t1 JOIN order_sku_financial t2 ON t2.vendor_order_id = t1.vendor_order_id AND t2.vendor_id = t1.vendor_id AND t2.is_afs_order = 1 - WHERE t1.afs_created_at >= ? AND t1.afs_created_at <= ? AND t1.status = ? + WHERE t1.afs_finished_at >= ? AND t1.afs_finished_at <= ? AND t1.status = ? ` sqlParams := []interface{}{ fromDate, diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index 2a15f0379..5c20f947c 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -479,6 +479,7 @@ func RefreshOrderSkuRelated(order *model.GoodsOrder) *model.GoodsOrder { order.GoodsCount = 0 order.SalePrice = 0 order.VendorPrice = 0 + order.ShopPrice = 0 order.Weight = 0 for _, sku := range order.Skus { if sku.SkuID > math.MaxInt32 { @@ -489,6 +490,7 @@ func RefreshOrderSkuRelated(order *model.GoodsOrder) *model.GoodsOrder { order.GoodsCount += sku.Count order.SalePrice += sku.SalePrice * int64(sku.Count) order.VendorPrice += sku.VendorPrice * int64(sku.Count) + order.ShopPrice += sku.ShopPrice * int64(sku.Count) order.Weight += sku.Weight * sku.Count } return order diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index ccb41cc44..f85b62587 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -8,6 +8,10 @@ import ( "git.rosy.net.cn/jx-callback/business/model" ) +const ( + AfsOrderStatus = -1 +) + type StoresOrderSaleInfo struct { StoreID int `orm:"column(store_id)" json:"storeID"` VendorID int `orm:"column(vendor_id)" json:"vendorID"` @@ -122,6 +126,7 @@ func GetAfsOrders(db *DaoDB, vendorID int, vendorOrderID, afsOrderID string) (af return afsOrderList, err } +// 时间范围是订单完成时间 func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, toTime time.Time, statusList []int) (saleInfoList []*StoresOrderSaleInfo, err error) { if utils.IsTimeZero(fromTime) { return nil, fmt.Errorf("查询订单信息必须指定起始时间") @@ -135,13 +140,13 @@ func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, to // 用int64类型去取float型的数据库返回值,会取不到 sql := fmt.Sprintf(` - SELECT IF(t1.jx_store_id > 0, t1.jx_store_id, t1.store_id) store_id, t1.vendor_id, IF(t1.status < ?, 0, t1.status) status, - COUNT(*) count, SUM(t1.shop_price) shop_price, SUM(t1.vendor_price) vendor_price, SUM(t1.sale_price) sale_price, SUM(t1.actual_pay_price) actual_pay_price, - CAST(SUM(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, %d) / 100)) AS SIGNED) earning_price - FROM goods_order t1 - LEFT JOIN store t5 ON t5.id = IF(t1.jx_store_id <> 0, t1.jx_store_id, t1.store_id) - WHERE t1.order_finished_at >= ? AND t1.order_finished_at <= ? - `, model.DefaultEarningPricePercentage) + SELECT IF(t1.jx_store_id > 0, t1.jx_store_id, t1.store_id) store_id, t1.vendor_id, IF(t1.status < ?, 0, t1.status) status, + COUNT(*) count, SUM(t1.shop_price) shop_price, SUM(t1.vendor_price) vendor_price, SUM(t1.sale_price) sale_price, SUM(t1.actual_pay_price) actual_pay_price, + CAST(SUM(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, %d) / 100)) AS SIGNED) earning_price + FROM goods_order t1 + LEFT JOIN store t5 ON t5.id = IF(t1.jx_store_id <> 0, t1.jx_store_id, t1.store_id) + WHERE t1.order_finished_at >= ? AND t1.order_finished_at <= ? + `, model.DefaultEarningPricePercentage) sqlParams := []interface{}{ model.OrderStatusEndBegin, fromTime, @@ -156,8 +161,29 @@ func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, to sqlParams = append(sqlParams, statusList) } sql += ` - GROUP BY 1,2,3 - ORDER BY 1,2,3` + GROUP BY 1,2,3` + sql += fmt.Sprintf(` + UNION + SELECT IF(t0.jx_store_id > 0, t0.jx_store_id, t0.store_id) store_id, t0.vendor_id, -1 status, + COUNT(*) count, SUM(t1.shop_price) shop_price, SUM(t1.vendor_price) vendor_price, SUM(t1.sale_price) sale_price, 0 actual_pay_price, + CAST(SUM(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, %d) / 100)) AS SIGNED) earning_price + FROM afs_order t0 + JOIN order_sku_financial t2 ON t2.afs_order_id = t0.afs_order_id AND t2.vendor_id = t0.vendor_id AND t2.is_afs_order = 1 + JOIN order_sku t1 ON t1.vendor_order_id = t2.vendor_order_id AND t1.vendor_id = t2.vendor_id AND t1.sku_id = t2.sku_id + LEFT JOIN store t5 ON t5.id = IF(t0.jx_store_id <> 0, t0.jx_store_id, t0.store_id) + WHERE t0.afs_finished_at >= ? AND t0.afs_finished_at <= ?`, model.DefaultEarningPricePercentage) + sqlParams = append(sqlParams, []interface{}{ + fromTime, + toTime, + }) + if len(storeIDList) > 0 { + sql += " AND IF(t0.jx_store_id > 0, t0.jx_store_id, t0.store_id) IN (" + GenQuestionMarks(len(storeIDList)) + ")" + sqlParams = append(sqlParams, storeIDList) + } + sql += ` + GROUP BY 1,2,3` + + sql += " ORDER BY 1,2,3" err = GetRows(db, &saleInfoList, sql, sqlParams...) return saleInfoList, err } diff --git a/business/model/order.go b/business/model/order.go index b3dbcbdb6..861757d15 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -84,7 +84,7 @@ type OrderSku struct { ID int64 `orm:"column(id)" json:"-"` VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` VendorID int `orm:"column(vendor_id)" json:"vendorID"` - StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // 当前这个字段被当成活动ID用 + StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // 当前这个字段被当成结算活动ID用 StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType Count int `json:"count"` VendorSkuID string `orm:"column(vendor_sku_id);size(48)" json:"vendorSkuID"` @@ -94,7 +94,7 @@ type OrderSku struct { ShopPrice int64 `json:"shopPrice"` // 京西价 VendorPrice int64 `json:"vendorPrice"` // 平台价 SalePrice int64 `json:"salePrice"` // 售卖价 - EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱 + EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱,如果结算活动ID为0,是按结算比例算的,否则就是结算表中的值 Weight int `json:"weight"` // 单位为克 SkuType int `json:"skuType"` // 当前如果为gift就为1,否则缺省为0 PromotionType int `json:"promotionType"` // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换 diff --git a/business/model/order_financial.go b/business/model/order_financial.go index 8b2b6b6b0..ea883e033 100644 --- a/business/model/order_financial.go +++ b/business/model/order_financial.go @@ -155,6 +155,13 @@ type OrderSkuFinancial struct { StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType } +// todo +// func (o *OrderSkuFinancial) TableUnique() [][]string { +// return [][]string{ +// []string{"AfsOrderID", "VendorSkuID", "VendorID", "IsAfsOrder"}, +// } +// } + func (o *OrderSkuFinancial) TableIndex() [][]string { return [][]string{ []string{"VendorOrderID", "VendorSkuID"}, From 9a5bde9d09864dbed2bf39966c4ce47677f3b478 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 16 Aug 2019 11:26:58 +0800 Subject: [PATCH 11/11] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8DgetOrders=E6=8C=89?= =?UTF-8?q?=E5=9F=8E=E5=B8=82=E6=9F=A5=E8=AF=A2=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/orderman_ext.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index 3b2ace132..c6675c700 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -382,8 +382,7 @@ func (c *OrderManager) getOrders(ctx *jxcontext.Context, isIncludeSku bool, from return nil, 0, err } if len(cities) > 0 { - sql += " JOIN store st ON t1.store_id = st.id" - sqlWhere += " AND st.city_code IN (" + dao.GenQuestionMarks(len(cities)) + ")" + sqlWhere += " AND t5.city_code IN (" + dao.GenQuestionMarks(len(cities)) + ") AND t5.id IS NOT NULL" sqlParams = append(sqlParams, cities) } }