Merge remote-tracking branch 'origin/mark' into yonghui
This commit is contained in:
@@ -31,7 +31,7 @@ const (
|
||||
minute2Schedule3rdCarrier4Ebai = 30 // 饿百的最少转自配送需要的时间(分钟)
|
||||
minMinute2Schedule3rdCarrier = 5 // 转三方配送最少等待时间(分钟)
|
||||
|
||||
time2AutoPickupMin = 15 * time.Minute // 自动拣货等待时间,这个只有在没有PickDeadline信息才有用,否则会根据PickDeadline设置
|
||||
time2AutoPickupMin = 14 * time.Minute // 自动拣货等待时间,这个只有在没有PickDeadline信息才有用,否则会根据PickDeadline设置
|
||||
second2AutoPickupGap = 60 //随机60秒
|
||||
time2AutoPickupAhead = 20 * time.Second // 有最后拣货时间的提前值
|
||||
|
||||
|
||||
@@ -81,6 +81,8 @@ func getVendorPriceFromStoreSkuBind(bind *model.StoreSkuBind, vendorID int) (ven
|
||||
vendorPrice = bind.MtwmPrice
|
||||
case model.VendorIDEBAI:
|
||||
vendorPrice = bind.EbaiPrice
|
||||
case model.VendorIDJX:
|
||||
vendorPrice = bind.JxPrice
|
||||
}
|
||||
return vendorPrice
|
||||
}
|
||||
@@ -158,7 +160,9 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac
|
||||
wrongSkuList = append(wrongSkuList, v)
|
||||
continue
|
||||
}
|
||||
actSkuMap.SyncStatus = model.SyncFlagNewMask
|
||||
if !(vendorID == model.VendorIDJX || act.Type == model.ActSkuFake) {
|
||||
actSkuMap.SyncStatus = model.SyncFlagNewMask
|
||||
}
|
||||
if v.ActPrice != 0 {
|
||||
actSkuMap.ActualActPrice = v.ActPrice
|
||||
} else {
|
||||
@@ -428,11 +432,9 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules
|
||||
actMap := &model.ActMap{
|
||||
ActID: act.ID,
|
||||
VendorID: vendorID,
|
||||
|
||||
SyncStatus: model.SyncFlagNewMask,
|
||||
}
|
||||
if act.Type == model.ActSkuFake {
|
||||
actMap.SyncStatus = 0
|
||||
if !(vendorID == model.VendorIDJX || act.Type == model.ActSkuFake) {
|
||||
actMap.SyncStatus = model.SyncFlagNewMask
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(actMap, ctx.GetUserName())
|
||||
actMapList = append(actMapList, actMap)
|
||||
|
||||
@@ -119,6 +119,10 @@ func JxOperationTime2StrTime(value int16) string {
|
||||
return fmt.Sprintf("%02d:%02d", value/100, value%100)
|
||||
}
|
||||
|
||||
func JxOperationTime2TimeByDate(value int16, tm time.Time) (outTm time.Time) {
|
||||
return utils.Str2TimeWithDefault(fmt.Sprintf("%s %02d:%02d:00", utils.Time2DateStr(tm), value/100, value%100), utils.DefaultTimeValue)
|
||||
}
|
||||
|
||||
func GetPolygonFromCircle(lng, lat, distance float64, pointCount int) (points [][2]float64) {
|
||||
points = make([][2]float64, pointCount)
|
||||
for k := range points {
|
||||
|
||||
@@ -171,8 +171,8 @@ const (
|
||||
OrderStatusUndoApplyCancel = -10
|
||||
OrderStatusApplyCancel = -5
|
||||
|
||||
OrderStatusUnknown = 0
|
||||
|
||||
OrderStatusUnknown = 0
|
||||
OrderStatusPayed = 2 // 已支付
|
||||
OrderStatusNew = 5 // 新订单,实际是已经支付
|
||||
OrderStatusAccepted = 10 // 已经接单,也即待出库,待拣货
|
||||
OrderStatusFinishedPickup = 15 // 拣货完成
|
||||
|
||||
@@ -75,7 +75,7 @@ func GetActStoreSkuVendorList(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs
|
||||
pageSize = FormalizePageSize(pageSize)
|
||||
|
||||
leftOrEmpty := ""
|
||||
if len(vendorIDs) == 1 && vendorIDs[0] == -1 {
|
||||
if len(vendorIDs) == 1 && (vendorIDs[0] == -1 || vendorIDs[0] == model.VendorIDJX) {
|
||||
leftOrEmpty = "LEFT"
|
||||
}
|
||||
sql := fmt.Sprintf(`
|
||||
@@ -102,19 +102,19 @@ func GetActStoreSkuVendorList(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs
|
||||
actID,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t2.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
|
||||
sql += fmt.Sprintf(`
|
||||
%s JOIN store_map t3 ON t3.store_id = t1.store_id AND t3.vendor_id = t2.vendor_id AND t3.deleted_at = ?
|
||||
sql += `
|
||||
LEFT JOIN store_map t3 ON t3.store_id = t1.store_id AND t3.vendor_id = t2.vendor_id AND t3.deleted_at = ?
|
||||
JOIN sku t4 ON t4.id = t1.sku_id
|
||||
LEFT JOIN store_sku_bind t5 ON t5.sku_id = t1.sku_id AND t5.store_id = t1.store_id AND t5.deleted_at = ?
|
||||
LEFT JOIN store t6 ON t6.id = t1.store_id
|
||||
JOIN sku_name t7 ON t7.id = t4.name_id
|
||||
WHERE t1.act_id = ?
|
||||
`, leftOrEmpty)
|
||||
`
|
||||
sqlParams = append(sqlParams,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
|
||||
@@ -104,6 +104,9 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID string) (sto
|
||||
storeDetail.AutoPickup = 1
|
||||
storeDetail.DeliveryType = model.StoreDeliveryTypeByStore
|
||||
storeDetail.DeliveryCompetition = 1
|
||||
if vendorID == model.VendorIDJX {
|
||||
storeDetail.IsSync = 1
|
||||
}
|
||||
}
|
||||
return storeDetail, nil
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
const (
|
||||
actMapDuration = 2 * time.Hour
|
||||
)
|
||||
|
||||
type LogicUpdateInfo struct {
|
||||
Item interface{}
|
||||
KVs map[string]interface{}
|
||||
@@ -31,6 +35,8 @@ var (
|
||||
jdapi.PromotionStateCanceled: model.ActStatusCanceled,
|
||||
jdapi.PromotionStateEnded: model.ActStatusEnded,
|
||||
}
|
||||
|
||||
actMap jxutils.SyncMapWithTimeout
|
||||
)
|
||||
|
||||
func splitPromotionSku(skus []*jdapi.PromotionSku, maxCount int) (skusList [][]*jdapi.PromotionSku) {
|
||||
@@ -62,22 +68,25 @@ func jdSkuActStatus2Jx(jdActState int) int {
|
||||
func CreatePromotionInfos(promotionType int, name string, beginDate, endDate time.Time, outInfoId, advertising, traceId string) (infoId int64, err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return getAPI("").CreatePromotionInfosSingle(name, beginDate, endDate, outInfoId, advertising, traceId)
|
||||
infoId, err = getAPI("").CreatePromotionInfosSingle(name, beginDate, endDate, outInfoId, advertising, traceId)
|
||||
} else {
|
||||
return getAPI("").CreatePromotionInfosLimitTime(name, beginDate, endDate, outInfoId, advertising, traceId)
|
||||
infoId, err = getAPI("").CreatePromotionInfosLimitTime(name, beginDate, endDate, outInfoId, advertising, traceId)
|
||||
}
|
||||
} else {
|
||||
infoId = jxutils.GenFakeID()
|
||||
}
|
||||
if err == nil {
|
||||
actMap.StoreWithTimeout(infoId, 1, actMapDuration)
|
||||
}
|
||||
return infoId, err
|
||||
}
|
||||
|
||||
func CreatePromotionRules(promotionType int, infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return getAPI("").CreatePromotionRulesSingle(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
||||
err = getAPI("").CreatePromotionRulesSingle(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
||||
} else {
|
||||
return getAPI("").CreatePromotionRulesLimitTime(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
||||
err = getAPI("").CreatePromotionRulesLimitTime(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
||||
}
|
||||
}
|
||||
return err
|
||||
@@ -133,9 +142,9 @@ func ConfirmPromotion(promotionType int, infoId int64, outInfoId, traceId string
|
||||
func CancelPromotion(promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return getAPI("").CancelPromotionSingle(infoId, outInfoId, traceId)
|
||||
err = getAPI("").CancelPromotionSingle(infoId, outInfoId, traceId)
|
||||
} else {
|
||||
return getAPI("").CancelPromotionLimitTime(infoId, outInfoId, traceId)
|
||||
err = getAPI("").CancelPromotionLimitTime(infoId, outInfoId, traceId)
|
||||
}
|
||||
}
|
||||
return err
|
||||
@@ -144,9 +153,9 @@ func CancelPromotion(promotionType int, infoId int64, outInfoId, traceId string)
|
||||
func AdjustPromotionTime(promotionType int, infoId int64, outInfoId string, endDate time.Time, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return getAPI("").AdjustPromotionTimeSingle(infoId, outInfoId, endDate, traceId)
|
||||
err = getAPI("").AdjustPromotionTimeSingle(infoId, outInfoId, endDate, traceId)
|
||||
} else {
|
||||
return getAPI("").AdjustPromotionTimeLimitTime(infoId, outInfoId, endDate, traceId)
|
||||
err = getAPI("").AdjustPromotionTimeLimitTime(infoId, outInfoId, endDate, traceId)
|
||||
}
|
||||
}
|
||||
return err
|
||||
@@ -155,9 +164,9 @@ func AdjustPromotionTime(promotionType int, infoId int64, outInfoId string, endD
|
||||
func AdjustPromotionSku(promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return getAPI("").AdjustPromotionSkuSingle(infoId, outInfoId, skus, traceId)
|
||||
skusResult, err = getAPI("").AdjustPromotionSkuSingle(infoId, outInfoId, skus, traceId)
|
||||
} else {
|
||||
return getAPI("").AdjustPromotionSkuLimitTime(infoId, outInfoId, skus, traceId)
|
||||
skusResult, err = getAPI("").AdjustPromotionSkuLimitTime(infoId, outInfoId, skus, traceId)
|
||||
}
|
||||
}
|
||||
return skusResult, err
|
||||
@@ -189,7 +198,7 @@ func createSkuAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.
|
||||
if err = err2; err == nil {
|
||||
vendorActID = utils.Int64ToStr(infoID)
|
||||
if err = CreatePromotionRules(act.Type, infoID, "", act.LimitUser, act.LimitUser, act.LimitCount, 1, traceInfo); err == nil {
|
||||
if _, err = CreatePromotionSku(act.Type, infoID, "", storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceInfo); err == nil {
|
||||
if _, err = CreatePromotionSku(act.Type, infoID, utils.Int2Str(act.ID), storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceInfo); err == nil {
|
||||
if err = ConfirmPromotion(act.Type, infoID, "", traceInfo); err == nil {
|
||||
for _, v := range actStoreSku {
|
||||
v.VendorActID = vendorActID
|
||||
@@ -312,19 +321,22 @@ func OnActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
func (c *PurchaseHandler) onActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
if msg.StatusID == jdapi.PromotionStatusSingleOK || msg.StatusID == jdapi.PromotionStatusLimitTimeOK {
|
||||
promotionID := msg.BillID
|
||||
// 等几秒再执行的原因是防止通过后台自己创建时,本地还没有建好,消息就过来,导致重复记录
|
||||
// 可能的问题是在重启时丢失消息
|
||||
utils.AfterFuncWithRecover(5*time.Second, func() {
|
||||
if !partner.CurActManager.IsVendorActExist(jxcontext.AdminCtx, promotionID, model.VendorIDJD) {
|
||||
act, actStoreSkuList, err := getActFromJD(promotionID)
|
||||
if err == nil && len(actStoreSkuList) > 0 {
|
||||
_, err = partner.CurActManager.CreateActFromVendor(jxcontext.AdminCtx, act, actStoreSkuList)
|
||||
intPromotionID := utils.Str2Int64(promotionID)
|
||||
if _, ok := actMap.Load(intPromotionID); !ok {
|
||||
utils.CallFuncAsync(func() {
|
||||
if !partner.CurActManager.IsVendorActExist(jxcontext.AdminCtx, promotionID, model.VendorIDJD) {
|
||||
act, actStoreSkuList, err := getActFromJD(promotionID)
|
||||
if err == nil && len(actStoreSkuList) > 0 {
|
||||
_, err = partner.CurActManager.CreateActFromVendor(jxcontext.AdminCtx, act, actStoreSkuList)
|
||||
}
|
||||
if err != nil {
|
||||
retVal = jdapi.Err2CallbackResponse(err, promotionID)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
retVal = jdapi.Err2CallbackResponse(err, promotionID)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
actMap.Delete(intPromotionID)
|
||||
}
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/delivery"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
@@ -19,7 +21,8 @@ const (
|
||||
OrderCreateTypePre = 0 // 预创建
|
||||
OrderCreateTypeNormal = 1 // 正常创建
|
||||
|
||||
PayWaitingTime = 10 * time.Minute // 等待支付的最长时间
|
||||
PayWaitingTime = 10 * time.Minute // 等待支付的最长时间
|
||||
DingShiDaMinTime = 1 * time.Hour
|
||||
)
|
||||
|
||||
type JxSkuInfo struct {
|
||||
@@ -29,15 +32,33 @@ type JxSkuInfo struct {
|
||||
Price int64 `json:"price,omitempty"` // 原价
|
||||
SalePrice int64 `json:"salePrice,omitempty"` // 售卖价
|
||||
|
||||
Name string `json:"name"`
|
||||
Name string `json:"name"`
|
||||
Weight int `json:"weight"`
|
||||
}
|
||||
|
||||
type JxSkuInfoList []*JxSkuInfo
|
||||
|
||||
func (l JxSkuInfoList) Len() int {
|
||||
return len(l)
|
||||
}
|
||||
|
||||
func (l JxSkuInfoList) Less(i, j int) bool {
|
||||
if l[i].SkuID == l[j].SkuID {
|
||||
return l[i].SalePrice < l[j].SalePrice
|
||||
}
|
||||
return l[i].SkuID < l[j].SkuID
|
||||
}
|
||||
|
||||
func (l JxSkuInfoList) Swap(i, j int) {
|
||||
l[i], l[j] = l[j], l[i]
|
||||
}
|
||||
|
||||
type JxOrderInfo struct {
|
||||
BuyerComment string
|
||||
BuyerComment string `json:"buyerComment"`
|
||||
StoreID int `json:"storeID"`
|
||||
Skus []*JxSkuInfo `json:"skus"`
|
||||
|
||||
ExpectedDeliveredTime *time.Time `orm:"type(datetime)" json:"expectedDeliveredTime"` // 预期送达时间
|
||||
ExpectedDeliveredTimestamp int64 `json:"expectedDeliveredTimestamp"` // 预期送达时间
|
||||
|
||||
TotalPrice int64 `json:"totalPrice"` // 单位为分 订单总价
|
||||
FreightPrice int64 `json:"freightPrice"` // 单位为分 订单配送费
|
||||
@@ -46,10 +67,33 @@ type JxOrderInfo struct {
|
||||
|
||||
OrderID int64 `json:"orderID"`
|
||||
StoreName string `json:"storeName"`
|
||||
Weight int `json:"weight"`
|
||||
}
|
||||
|
||||
type DeliveryTimeItem struct {
|
||||
ViewTime string `json:"viewTime"`
|
||||
UnixTime int64 `json:"unixTime"`
|
||||
ViewShippingFee string `json:"viewShippingFee"`
|
||||
}
|
||||
|
||||
type DeliveryDayTimeInfo struct {
|
||||
Date string `json:"date"`
|
||||
TimeList []*DeliveryTimeItem `json:"timeList"`
|
||||
}
|
||||
|
||||
var (
|
||||
orderNoBeginTimestamp int64
|
||||
|
||||
weekdayMap = map[int]string{
|
||||
1: "一",
|
||||
2: "二",
|
||||
3: "三",
|
||||
4: "四",
|
||||
5: "五",
|
||||
6: "六",
|
||||
7: "七",
|
||||
}
|
||||
dayList = []string{"今天", "明天"}
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -68,6 +112,7 @@ func CreateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64,
|
||||
outJxOrder.OrderID = GenOrderNo(ctx)
|
||||
order, err2 := jxOrder2GoodsOrder(ctx, outJxOrder, deliveryAddress)
|
||||
if err = err2; err == nil {
|
||||
order.Status = model.OrderStatusPayed
|
||||
partner.CurOrderManager.OnOrderNew(order, model.Order2Status(order))
|
||||
}
|
||||
}
|
||||
@@ -89,6 +134,57 @@ func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType
|
||||
return orderPay, err
|
||||
}
|
||||
|
||||
func time2ShortTimeStr(t time.Time) string {
|
||||
return t.Format("15:04")
|
||||
}
|
||||
|
||||
func GetAvailableDeliverTime(ctx *jxcontext.Context, storeID int) (deliverTimerList []*DeliveryDayTimeInfo, err error) {
|
||||
db := dao.GetDB()
|
||||
storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDJX)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if storeDetail.Status != model.StoreStatusOpened {
|
||||
return nil, fmt.Errorf("门店:%s不是营业状态,状态是:%s", storeDetail.Name, model.StoreStatusName[storeDetail.Status])
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
beginDate := utils.Time2Date(now)
|
||||
minDingShiDaTime := now.Add(DingShiDaMinTime)
|
||||
for i := 0; i < 2; i++ {
|
||||
openTime1 := jxutils.JxOperationTime2TimeByDate(storeDetail.OpenTime1, beginDate)
|
||||
closeTime1 := jxutils.JxOperationTime2TimeByDate(storeDetail.CloseTime1, beginDate)
|
||||
openTime2 := jxutils.JxOperationTime2TimeByDate(storeDetail.OpenTime2, beginDate)
|
||||
closeTime2 := jxutils.JxOperationTime2TimeByDate(storeDetail.CloseTime2, beginDate)
|
||||
timeInfo := &DeliveryDayTimeInfo{
|
||||
Date: fmt.Sprintf("%s(周%s)", dayList[i], weekdayMap[int(beginDate.Weekday())]),
|
||||
}
|
||||
if i == 0 {
|
||||
timeInfo.TimeList = append(timeInfo.TimeList, &DeliveryTimeItem{
|
||||
ViewTime: "立即送出",
|
||||
UnixTime: 0,
|
||||
ViewShippingFee: "约6.6元配送费",
|
||||
})
|
||||
}
|
||||
deliverTimerList = append(deliverTimerList, timeInfo)
|
||||
for j := 0; j < 24*3; j++ {
|
||||
deliveryTime := beginDate.Add(time.Duration(j) * 20 * time.Minute)
|
||||
if deliveryTime.Sub(minDingShiDaTime) >= 0 {
|
||||
if (deliveryTime.Sub(openTime1) >= 0 && deliveryTime.Sub(closeTime1) <= 0) ||
|
||||
(storeDetail.OpenTime2 > 0 && deliveryTime.Sub(openTime2) >= 0 && deliveryTime.Sub(closeTime2) <= 0) {
|
||||
timeInfo.TimeList = append(timeInfo.TimeList, &DeliveryTimeItem{
|
||||
ViewTime: time2ShortTimeStr(deliveryTime),
|
||||
UnixTime: deliveryTime.Unix(),
|
||||
ViewShippingFee: "约6.6元配送费",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
beginDate = beginDate.Add(24 * time.Hour)
|
||||
}
|
||||
return deliverTimerList, err
|
||||
}
|
||||
|
||||
func OnPayFinished(orderPay *model.OrderPay) (err error) {
|
||||
order, err := partner.CurOrderManager.LoadOrder(orderPay.VendorOrderID, orderPay.VendorID)
|
||||
if err == nil {
|
||||
@@ -181,16 +277,19 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
|
||||
}
|
||||
|
||||
// 营业状态及时间检查
|
||||
if storeDetail.Status == model.StoreStatusDisabled {
|
||||
if storeDetail.Status != model.StoreStatusOpened { // model.StoreStatusDisabled {
|
||||
return nil, nil, fmt.Errorf("门店:%s状态是:%s", storeDetail.Name, model.StoreStatusName[storeDetail.Status])
|
||||
}
|
||||
checkTime := time.Now()
|
||||
if jxOrder.ExpectedDeliveredTime == nil {
|
||||
if jxOrder.ExpectedDeliveredTimestamp == 0 {
|
||||
if storeDetail.Status != model.StoreStatusOpened {
|
||||
return nil, nil, fmt.Errorf("门店:%s不是营业状态,状态是:%s", storeDetail.Name, model.StoreStatusName[storeDetail.Status])
|
||||
}
|
||||
} else {
|
||||
checkTime = *jxOrder.ExpectedDeliveredTime
|
||||
checkTime = utils.Timestamp2Time(jxOrder.ExpectedDeliveredTimestamp)
|
||||
if checkTime.Sub(time.Now()) < DingShiDaMinTime {
|
||||
return nil, nil, fmt.Errorf("预订单只能在1小时后")
|
||||
}
|
||||
if utils.Time2Date(time.Now()).Sub(utils.Time2Date(checkTime)) > 24*time.Hour {
|
||||
return nil, nil, fmt.Errorf("预订单只能预定当天或第二天")
|
||||
}
|
||||
@@ -238,15 +337,23 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
|
||||
Count: v.Count,
|
||||
Price: int64(storeSkuBind.JxPrice),
|
||||
SalePrice: int64(storeSkuBind.JxPrice), // todo 考虑活动价
|
||||
Weight: sku.Weight,
|
||||
Name: jxutils.ComposeSkuName(sku.Prefix, sku.Name, sku.Comment, sku.Unit, sku.SpecQuality, sku.SpecUnit, 0),
|
||||
}
|
||||
outJxOrder.Skus = append(outJxOrder.Skus, jxSku)
|
||||
outJxOrder.OrderPrice += int64(v.Count) * jxSku.SalePrice
|
||||
outJxOrder.Weight = v.Count * jxSku.Weight
|
||||
}
|
||||
}
|
||||
}
|
||||
outJxOrder.TotalPrice = outJxOrder.OrderPrice + outJxOrder.FreightPrice
|
||||
outJxOrder.ActualPayPrice = outJxOrder.TotalPrice
|
||||
sort.Sort(JxSkuInfoList(outJxOrder.Skus))
|
||||
|
||||
if outJxOrder.FreightPrice, _, err = delivery.CalculateDeliveryFee(dao.GetDB(), jxOrder.StoreID, "",
|
||||
jxutils.StandardCoordinate2Int(deliveryAddress.Lng), jxutils.StandardCoordinate2Int(deliveryAddress.Lat),
|
||||
model.CoordinateTypeMars, outJxOrder.Weight, checkTime); err == nil {
|
||||
outJxOrder.TotalPrice = outJxOrder.OrderPrice + outJxOrder.FreightPrice
|
||||
outJxOrder.ActualPayPrice = outJxOrder.TotalPrice
|
||||
}
|
||||
return outJxOrder, deliveryAddress, err
|
||||
}
|
||||
|
||||
@@ -277,8 +384,8 @@ func jxOrder2GoodsOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, deliveryAd
|
||||
}
|
||||
order.OrderCreatedAt = order.StatusTime
|
||||
order.VendorUserID = order.UserID
|
||||
if jxOrder.ExpectedDeliveredTime != nil {
|
||||
order.ExpectedDeliveredTime = *jxOrder.ExpectedDeliveredTime
|
||||
if jxOrder.ExpectedDeliveredTimestamp == 0 {
|
||||
order.ExpectedDeliveredTime = utils.Timestamp2Time(jxOrder.ExpectedDeliveredTimestamp)
|
||||
order.BusinessType = model.BusinessTypeDingshida
|
||||
} else {
|
||||
order.ExpectedDeliveredTime = utils.DefaultTimeValue
|
||||
|
||||
@@ -3,10 +3,24 @@ package localjx
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||
)
|
||||
|
||||
func init() {
|
||||
testinit.Init()
|
||||
}
|
||||
|
||||
func TestGenOrderNo(t *testing.T) {
|
||||
orderNo := GenOrderNo(jxcontext.AdminCtx)
|
||||
t.Log(orderNo)
|
||||
}
|
||||
|
||||
func TestGetAvailableDeliverTime(t *testing.T) {
|
||||
timeInfo, err := GetAvailableDeliverTime(jxcontext.AdminCtx, 100118)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(timeInfo, false))
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/wxpay"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
@@ -30,6 +31,9 @@ func pay4OrderByWX(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp
|
||||
TimeStart: wxpay.Time2PayTime(payCreatedAt),
|
||||
// TimeExpire: wxpay.Time2PayTime(payCreatedAt.Add(PayWaitingTime)),
|
||||
}
|
||||
if authInfo, err := ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini {
|
||||
param.OpenID = authInfo.GetAuthID()
|
||||
}
|
||||
result, err := api.WxpayAPI.CreateUnifiedOrder(param)
|
||||
if err == nil {
|
||||
orderPay = &model.OrderPay{
|
||||
|
||||
@@ -44,3 +44,17 @@ func (c *JxOrderController) Pay4Order() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 查询网络打印机状态
|
||||
// @Description 查询网络打印机状态
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeID query int true "门店ID"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetAvailableDeliverTime [get]
|
||||
func (c *JxOrderController) GetAvailableDeliverTime() {
|
||||
c.callGetAvailableDeliverTime(func(params *tJxorderGetAvailableDeliverTimeParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = localjx.GetAvailableDeliverTime(params.Ctx, params.StoreID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -592,6 +592,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetAvailableDeliverTime",
|
||||
Router: `/GetAvailableDeliverTime`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"],
|
||||
beego.ControllerComments{
|
||||
Method: "Pay4Order",
|
||||
|
||||
Reference in New Issue
Block a user