Merge remote-tracking branch 'origin/mark' into su
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 && storeDetail.VendorStatus != 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.Floor(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 {
|
||||
@@ -503,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 {
|
||||
@@ -519,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)
|
||||
@@ -687,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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user