From 7ab34ae366309dc16c3e81b687c11495fce4888c Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 7 Nov 2019 18:37:49 +0800 Subject: [PATCH 1/4] =?UTF-8?q?OnWaybillStatusChanged=E4=B8=AD=E6=94=B6?= =?UTF-8?q?=E5=88=B0=E8=BF=90=E5=8D=95=E6=8E=A5=E5=8D=95=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=BC=BA=E5=88=B6=E8=AE=BE=E7=BD=AE=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=97=B6=EF=BC=8C=E8=A6=81=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=98=AF=E5=90=A6=E5=B7=B2=E7=BB=8F=E7=BB=93?= =?UTF-8?q?=E6=9D=9F=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/scheduler/defsch/defsch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxcallback/scheduler/defsch/defsch.go b/business/jxcallback/scheduler/defsch/defsch.go index 5712d2eeb..bedb1b640 100644 --- a/business/jxcallback/scheduler/defsch/defsch.go +++ b/business/jxcallback/scheduler/defsch/defsch.go @@ -467,7 +467,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo s.cancelOtherWaybillsCheckOrderDeliveryFlag(savedOrderInfo, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime) if model.IsWaybillPlatformOwn(bill) { - if bill.Status == model.WaybillStatusDelivering { + if bill.Status == model.WaybillStatusDelivering && order.Status < model.OrderStatusEndBegin { // 强制将订单状态置为配送中? order.Status = model.OrderStatusDelivering partner.CurOrderManager.UpdateOrderStatusAndDeliveryFlag(order) From 025ead8c0506b1cae623d735306e6dc9df3e7efc Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 7 Nov 2019 23:00:48 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E4=BB=B7=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E5=AD=98=E7=9A=84=EF=BC=8C=E4=B8=8D=E9=87=8D=E6=96=B0=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=20=E4=B8=8D=E5=90=8C=E6=AD=A5=E7=9A=84=E9=97=A8?= =?UTF-8?q?=E5=BA=97=E6=88=96=E7=A6=81=E7=94=A8=E7=9A=84=E9=97=A8=E5=BA=97?= =?UTF-8?q?=E4=B8=8D=E5=88=9B=E5=BB=BA=E6=B4=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/act/act.go | 107 ++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 46 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index 85c1d6e6f..9a14ebd6f 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -72,6 +72,18 @@ func init() { partner.InitActManager(FixedActManager) } +func getVendorPriceFromStoreSkuBind(bind *model.StoreSkuBind, vendorID int) (vendorPrice int) { + switch vendorID { + case model.VendorIDJD: + vendorPrice = bind.JdPrice + case model.VendorIDMTWM: + vendorPrice = bind.MtwmPrice + case model.VendorIDEBAI: + vendorPrice = bind.EbaiPrice + } + return vendorPrice +} + func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Act, vendorIDs []int, actStoreSku []*ActStoreSkuParam) (validVendorIDs []int, actStoreSkuList []*model.ActStoreSku, actStoreSkuMapList []*model.ActStoreSkuMap, err error) { wholeValidVendorMap := make(map[int]int) if len(actStoreSku) > 0 { @@ -119,59 +131,62 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac for _, vendorID := range vendorIDs { storeDetail, err2 := dao.GetStoreDetail(db, storeID, vendorID) if err = err2; err == nil { - for _, v := range oneStoreSkuParam { - validVendorMap[vendorID] = 1 - validSkuMap[v.SkuID] = 1 - v.ActID = act.ID - actSkuMap := &model.ActStoreSkuMap{ - ActID: act.ID, - StoreID: storeID, - SkuID: v.SkuID, - VendorID: vendorID, - } - v.OriginalPrice = actSkuMap.VendorPrice - storeSkuInfo := storeSkuMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] - if storeSkuInfo != nil { - jxPrice := storeSkuInfo.Price - pricePercentage := jxutils.GetPricePercentage(storeDetail.PricePercentagePackObj, jxPrice, int(storeDetail.PricePercentage)) - actSkuMap.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(jxPrice, pricePercentage)) - v.OriginalPrice = int64(jxPrice) - } - var err2 error - if act.Type != model.ActSkuFake { - if storeSkuInfo == nil { - v.ErrMsg = fmt.Sprintf("门店:%d没有关注商品:%d", v.StoreID, v.SkuID) - wrongSkuList = append(wrongSkuList, v) - continue + if storeDetail.IsSync != 0 && storeDetail.Status != model.StoreStatusDisabled { + for _, v := range oneStoreSkuParam { + validVendorMap[vendorID] = 1 + validSkuMap[v.SkuID] = 1 + v.ActID = act.ID + actSkuMap := &model.ActStoreSkuMap{ + ActID: act.ID, + StoreID: storeID, + SkuID: v.SkuID, + VendorID: vendorID, } - actSkuMap.SyncStatus = model.SyncFlagNewMask - if v.ActPrice != 0 { - actSkuMap.ActualActPrice = v.ActPrice - } else { - percentage := act.PricePercentage - if v.PricePercentage != 0 { - percentage = v.PricePercentage + v.OriginalPrice = actSkuMap.VendorPrice + storeSkuInfo := storeSkuMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] + if storeSkuInfo != nil { + jxPrice := storeSkuInfo.Price + // pricePercentage := jxutils.GetPricePercentage(storeDetail.PricePercentagePackObj, jxPrice, int(storeDetail.PricePercentage)) + // actSkuMap.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(jxPrice, pricePercentage)) + actSkuMap.VendorPrice = int64(getVendorPriceFromStoreSkuBind(storeSkuInfo, vendorID)) + v.OriginalPrice = int64(jxPrice) + } + var err2 error + if act.Type != model.ActSkuFake { + if storeSkuInfo == nil { + v.ErrMsg = fmt.Sprintf("门店:%d没有关注商品:%d", v.StoreID, v.SkuID) + wrongSkuList = append(wrongSkuList, v) + continue } - actSkuMap.ActualActPrice = int64(jxutils.CaculateSkuVendorPrice(int(actSkuMap.VendorPrice), percentage)) - if actSkuMap.ActualActPrice > 10 { - actSkuMap.ActualActPrice = int64(math.Round(float64(actSkuMap.ActualActPrice)/10) * 10) + actSkuMap.SyncStatus = model.SyncFlagNewMask + if v.ActPrice != 0 { + actSkuMap.ActualActPrice = v.ActPrice + } else { + percentage := act.PricePercentage + if v.PricePercentage != 0 { + percentage = v.PricePercentage + } + actSkuMap.ActualActPrice = int64(jxutils.CaculateSkuVendorPrice(int(actSkuMap.VendorPrice), percentage)) + if actSkuMap.ActualActPrice > 10 { + actSkuMap.ActualActPrice = int64(math.Round(float64(actSkuMap.ActualActPrice)/10) * 10) + } + } + if actSkuMap.ActualActPrice <= 0 { + actSkuMap.ActualActPrice = 1 + } + if err2 = checkDiscountValidation(act.Type, float64(actSkuMap.ActualActPrice)*100/float64(actSkuMap.VendorPrice)); err2 != nil { + v.ErrMsg = err2.Error() + v.ActualActPrice = actSkuMap.ActualActPrice + wrongSkuList = append(wrongSkuList, v) } } - if actSkuMap.ActualActPrice <= 0 { - actSkuMap.ActualActPrice = 1 - } - if err2 = checkDiscountValidation(act.Type, float64(actSkuMap.ActualActPrice)*100/float64(actSkuMap.VendorPrice)); err2 != nil { - v.ErrMsg = err2.Error() - v.ActualActPrice = actSkuMap.ActualActPrice - wrongSkuList = append(wrongSkuList, v) + if err2 == nil { + dao.WrapAddIDCULDEntity(actSkuMap, ctx.GetUserName()) + actStoreSkuMapList = append(actStoreSkuMapList, actSkuMap) } } - if err2 == nil { - dao.WrapAddIDCULDEntity(actSkuMap, ctx.GetUserName()) - actStoreSkuMapList = append(actStoreSkuMapList, actSkuMap) - } + wholeValidVendorMap[vendorID] = 1 } - wholeValidVendorMap[vendorID] = 1 } else if !dao.IsNoRowsError(err) { return nil, nil, nil, err } else { From f85c182f44b8f7022e36874cc1333d86bc2eb18e Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 8 Nov 2019 09:01:59 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=A6=81=E7=94=A8=E4=B8=8E=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=9A=84=E9=97=A8=E5=BA=97=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E6=97=B6=E6=8E=92=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/act/act.go | 4 ++-- business/jxstore/cms/store.go | 21 +++++---------------- business/jxutils/jxutils.go | 21 ++++++++++++++++++++- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index 9a14ebd6f..9b6907fb2 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -131,7 +131,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac for _, vendorID := range vendorIDs { storeDetail, err2 := dao.GetStoreDetail(db, storeID, vendorID) if err = err2; err == nil { - if storeDetail.IsSync != 0 && storeDetail.Status != model.StoreStatusDisabled { + if storeDetail.IsSync != 0 && storeDetail.Status != model.StoreStatusDisabled && storeDetail.VendorStatus != model.StoreStatusDisabled { for _, v := range oneStoreSkuParam { validVendorMap[vendorID] = 1 validSkuMap[v.SkuID] = 1 @@ -168,7 +168,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac } actSkuMap.ActualActPrice = int64(jxutils.CaculateSkuVendorPrice(int(actSkuMap.VendorPrice), percentage)) if actSkuMap.ActualActPrice > 10 { - actSkuMap.ActualActPrice = int64(math.Round(float64(actSkuMap.ActualActPrice)/10) * 10) + actSkuMap.ActualActPrice = int64(math.Floor(float64(actSkuMap.ActualActPrice)/10) * 10) } } if actSkuMap.ActualActPrice <= 0 { diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index c2e101aa0..fd96c1695 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -203,7 +203,9 @@ func getStoresSql(ctx *jxcontext.Context, keyword string, params map[string]inte sqlVendorStoreCond += " AND ( 1 = 0" } } - sqlFrom += "\nLEFT JOIN " + tableName + " " + tableAlias + " ON " + tableAlias + ".vendor_id = ? AND " + tableAlias + ".store_id = t1.id AND " + tableAlias + ".deleted_at = ?" + sqlFrom += "\nLEFT JOIN " + tableName + " " + tableAlias + " ON " + tableAlias + ".vendor_id = ? AND " + + tableAlias + ".store_id = t1.id AND " + tableAlias + ".deleted_at = ? AND " + + tableAlias + ".is_sync <> 0 " sqlFromParams = append(sqlFromParams, vendor, utils.DefaultTimeValue) if cond == 1 { sqlVendorStoreCond += " " + mapCond + " " + tableAlias + ".id IS NOT NULL" @@ -2102,21 +2104,8 @@ func GetStoreListByLocation(ctx *jxcontext.Context, lng, lat float64, needWalkDi if err = dao.GetRows(dao.GetDB(), &storeList1, sql, sqlParams...); err == nil { var storeList2 []*Store4User for _, v := range storeList1 { - isStoreOK := false - v.FloatLng = jxutils.IntCoordinate2Standard(v.Lng) - v.FloatLat = jxutils.IntCoordinate2Standard(v.Lat) - if v.DeliveryRangeType == model.DeliveryRangeTypeRadius { - maxDistance := int(utils.Str2Int64WithDefault(v.DeliveryRange, 0)) - v.Distance = int(jxutils.EarthDistance(lng, lat, v.FloatLng, v.FloatLat) * 1000) - isStoreOK = v.Distance <= maxDistance - } else { - points := jxutils.CoordinateStr2Points(v.DeliveryRange) - if utils.IsPointInPolygon(lng, lat, points) { - v.Distance = int(jxutils.EarthDistance(lng, lat, v.FloatLng, v.FloatLat) * 1000) - isStoreOK = true - } - } - if isStoreOK { + if distance := jxutils.Point2StoreDistance(lng, lat, v.Lng, v.Lat, v.DeliveryRangeType, v.DeliveryRange); distance > 0 { + v.Distance = distance storeList2 = append(storeList2, v) } } diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index 8f20044d5..0fe81a89c 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -235,7 +235,7 @@ func IntCoordinate2MarsStandard(gpsLng, gpsLat int, coordinateType int) (marsLng case model.CoordinateTypeGPS: coordSys = autonavi.CoordSysGPS case model.CoordinateTypeMars: - coordSys = autonavi.CoordSysAutonavi + return marsLng, marsLat, nil case model.CoordinateTypeBaiDu: coordSys = autonavi.CoordSysBaidu case model.CoordinateTypeMapbar: @@ -779,3 +779,22 @@ func GetOneEmailFromStr(str string) (email string) { } return email } + +// 计算一个坐标点距离一个门店的距离,单位为米,如果不在有效范围内,则返回0 +func Point2StoreDistance(lng, lat float64, intStoreLng, intStoreLat int, deliveryRangeType int8, deliveryRange string) (distance int) { + storeLng := IntCoordinate2Standard(intStoreLng) + storeLat := IntCoordinate2Standard(intStoreLat) + if deliveryRangeType == model.DeliveryRangeTypeRadius { + maxDistance := int(utils.Str2Int64WithDefault(deliveryRange, 0)) + distance = int(EarthDistance(lng, lat, storeLng, storeLat) * 1000) + if distance > maxDistance { + distance = 0 + } + } else { + points := CoordinateStr2Points(deliveryRange) + if utils.IsPointInPolygon(lng, lat, points) { + distance = int(EarthDistance(lng, lat, storeLng, storeLat) * 1000) + } + } + return distance +} From ae8b6a32c1ed7eb979fdb07d6bb1a518de3822eb Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 8 Nov 2019 09:39:43 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BA=AC=E4=B8=9C=E5=88=B0=E5=AE=B6?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E6=B6=88=E6=81=AF=E5=9B=9E=E8=B0=83=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E5=88=9B=E5=BB=BA=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E7=9A=84=E6=B4=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/act/act.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index 9b6907fb2..7f62439dd 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -518,6 +518,21 @@ func (a *ActManager) CreateActFromVendor(ctx *jxcontext.Context, act2 *model.Act } func createActFromVendor(ctx *jxcontext.Context, db *dao.DaoDB, act2 *model.Act2, actStoreSku []*model.ActStoreSku2) (actID int, err error) { + actMap := &model.ActMap{ + VendorID: act2.VendorID, + VendorActID: act2.VendorActID, + SyncStatus: 0, + } + dao.WrapAddIDCULDEntity(actMap, ctx.GetUserName()) + if actMap.VendorActID != "" { + if err = dao.GetEntity(db, actMap, model.FieldVendorActID, model.FieldVendorID, model.FieldDeletedAt); err == nil { + return actMap.ActID, nil + } else if !dao.IsNoRowsError(err) { + return 0, err + } + err = nil + } + dao.Begin(db) defer func() { if r := recover(); r != nil { @@ -534,13 +549,7 @@ func createActFromVendor(ctx *jxcontext.Context, db *dao.DaoDB, act2 *model.Act2 return 0, err } - actMap := &model.ActMap{ - ActID: act.ID, - VendorID: act2.VendorID, - VendorActID: act2.VendorActID, - SyncStatus: 0, - } - dao.WrapAddIDCULDEntity(actMap, ctx.GetUserName()) + actMap.ActID = act.ID err = dao.CreateEntity(db, actMap) if err != nil { dao.Rollback(db) @@ -702,7 +711,7 @@ func DeleteActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, act } } - if isNeedCancelAct { + if isNeedCancelAct && act.Type != model.ActSkuFake { act := &model.Act{} act.ID = actID if _, err = dao.UpdateEntityLogically(db, act,