+GetAvailableDeliverTime
This commit is contained in:
@@ -119,6 +119,10 @@ func JxOperationTime2StrTime(value int16) string {
|
|||||||
return fmt.Sprintf("%02d:%02d", value/100, value%100)
|
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) {
|
func GetPolygonFromCircle(lng, lat, distance float64, pointCount int) (points [][2]float64) {
|
||||||
points = make([][2]float64, pointCount)
|
points = make([][2]float64, pointCount)
|
||||||
for k := range points {
|
for k := range points {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"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"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/partner/delivery"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,7 +20,8 @@ const (
|
|||||||
OrderCreateTypePre = 0 // 预创建
|
OrderCreateTypePre = 0 // 预创建
|
||||||
OrderCreateTypeNormal = 1 // 正常创建
|
OrderCreateTypeNormal = 1 // 正常创建
|
||||||
|
|
||||||
PayWaitingTime = 10 * time.Minute // 等待支付的最长时间
|
PayWaitingTime = 10 * time.Minute // 等待支付的最长时间
|
||||||
|
DingShiDaMinTime = 1 * time.Hour
|
||||||
)
|
)
|
||||||
|
|
||||||
type JxSkuInfo struct {
|
type JxSkuInfo struct {
|
||||||
@@ -29,11 +31,12 @@ type JxSkuInfo struct {
|
|||||||
Price int64 `json:"price,omitempty"` // 原价
|
Price int64 `json:"price,omitempty"` // 原价
|
||||||
SalePrice int64 `json:"salePrice,omitempty"` // 售卖价
|
SalePrice int64 `json:"salePrice,omitempty"` // 售卖价
|
||||||
|
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Weight int `json:"weight"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JxOrderInfo struct {
|
type JxOrderInfo struct {
|
||||||
BuyerComment string
|
BuyerComment string `json:"buyerComment"`
|
||||||
StoreID int `json:"storeID"`
|
StoreID int `json:"storeID"`
|
||||||
Skus []*JxSkuInfo `json:"skus"`
|
Skus []*JxSkuInfo `json:"skus"`
|
||||||
|
|
||||||
@@ -46,10 +49,33 @@ type JxOrderInfo struct {
|
|||||||
|
|
||||||
OrderID int64 `json:"orderID"`
|
OrderID int64 `json:"orderID"`
|
||||||
StoreName string `json:"storeName"`
|
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 (
|
var (
|
||||||
orderNoBeginTimestamp int64
|
orderNoBeginTimestamp int64
|
||||||
|
|
||||||
|
weekdayMap = map[int]string{
|
||||||
|
1: "一",
|
||||||
|
2: "二",
|
||||||
|
3: "三",
|
||||||
|
4: "四",
|
||||||
|
5: "五",
|
||||||
|
6: "六",
|
||||||
|
7: "七",
|
||||||
|
}
|
||||||
|
dayList = []string{"今天", "明天"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -89,6 +115,50 @@ func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType
|
|||||||
return orderPay, err
|
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())]),
|
||||||
|
}
|
||||||
|
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) {
|
func OnPayFinished(orderPay *model.OrderPay) (err error) {
|
||||||
order, err := partner.CurOrderManager.LoadOrder(orderPay.VendorOrderID, orderPay.VendorID)
|
order, err := partner.CurOrderManager.LoadOrder(orderPay.VendorOrderID, orderPay.VendorID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -181,7 +251,7 @@ 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])
|
return nil, nil, fmt.Errorf("门店:%s状态是:%s", storeDetail.Name, model.StoreStatusName[storeDetail.Status])
|
||||||
}
|
}
|
||||||
checkTime := time.Now()
|
checkTime := time.Now()
|
||||||
@@ -191,6 +261,9 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
checkTime = *jxOrder.ExpectedDeliveredTime
|
checkTime = *jxOrder.ExpectedDeliveredTime
|
||||||
|
if checkTime.Sub(time.Now()) < DingShiDaMinTime {
|
||||||
|
return nil, nil, fmt.Errorf("预订单只能在1小时后")
|
||||||
|
}
|
||||||
if utils.Time2Date(time.Now()).Sub(utils.Time2Date(checkTime)) > 24*time.Hour {
|
if utils.Time2Date(time.Now()).Sub(utils.Time2Date(checkTime)) > 24*time.Hour {
|
||||||
return nil, nil, fmt.Errorf("预订单只能预定当天或第二天")
|
return nil, nil, fmt.Errorf("预订单只能预定当天或第二天")
|
||||||
}
|
}
|
||||||
@@ -238,15 +311,22 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
|
|||||||
Count: v.Count,
|
Count: v.Count,
|
||||||
Price: int64(storeSkuBind.JxPrice),
|
Price: int64(storeSkuBind.JxPrice),
|
||||||
SalePrice: int64(storeSkuBind.JxPrice), // todo 考虑活动价
|
SalePrice: int64(storeSkuBind.JxPrice), // todo 考虑活动价
|
||||||
|
Weight: sku.Weight,
|
||||||
Name: jxutils.ComposeSkuName(sku.Prefix, sku.Name, sku.Comment, sku.Unit, sku.SpecQuality, sku.SpecUnit, 0),
|
Name: jxutils.ComposeSkuName(sku.Prefix, sku.Name, sku.Comment, sku.Unit, sku.SpecQuality, sku.SpecUnit, 0),
|
||||||
}
|
}
|
||||||
outJxOrder.Skus = append(outJxOrder.Skus, jxSku)
|
outJxOrder.Skus = append(outJxOrder.Skus, jxSku)
|
||||||
outJxOrder.OrderPrice += int64(v.Count) * jxSku.SalePrice
|
outJxOrder.OrderPrice += int64(v.Count) * jxSku.SalePrice
|
||||||
|
outJxOrder.Weight = v.Count * jxSku.Weight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outJxOrder.TotalPrice = outJxOrder.OrderPrice + outJxOrder.FreightPrice
|
|
||||||
outJxOrder.ActualPayPrice = outJxOrder.TotalPrice
|
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
|
return outJxOrder, deliveryAddress, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,24 @@ package localjx
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"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) {
|
func TestGenOrderNo(t *testing.T) {
|
||||||
orderNo := GenOrderNo(jxcontext.AdminCtx)
|
orderNo := GenOrderNo(jxcontext.AdminCtx)
|
||||||
t.Log(orderNo)
|
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))
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,3 +44,17 @@ func (c *JxOrderController) Pay4Order() {
|
|||||||
return retVal, "", err
|
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,
|
Filters: nil,
|
||||||
Params: 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.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "Pay4Order",
|
Method: "Pay4Order",
|
||||||
|
|||||||
Reference in New Issue
Block a user