This commit is contained in:
苏尹岚
2020-08-12 15:45:40 +08:00
34 changed files with 474 additions and 190 deletions

View File

@@ -126,7 +126,7 @@ func StoreDetail2ShopInfo(storeDetail *dao.StoreDetail2) (shopInfo *dadaapi.Shop
}
shopInfo = &dadaapi.ShopInfo{
OriginShopID: storeDetail.VendorStoreID,
StationName: storeDetail.Name,
StationName: globals.StoreName + "-" + storeDetail.Name,
Business: dadaapi.BusinessTypeConvStore, // 故意设置成这个的
CityName: cityName,
AreaName: districtName,

View File

@@ -59,7 +59,7 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
<BR>
商品明细: <BR>
品名 数量 <BR>
品名 数量 单价 小计<BR>
--------------------------------<BR>`
// <BOLD>实际支付:</BOLD>%s<BR>
orderParams := []interface{}{
@@ -79,9 +79,8 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
for _, sku := range order.Skus {
orderFmt += `%s<BR>`
orderFmt += `%8s<BR>`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count))
//jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count))
orderFmt += `%8s%10s%10s<BR>`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
}
orderFmt += `<BR>
<BOLD>共%d种%d件商品</BOLD>
@@ -134,7 +133,7 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
<BR>
<B>商品明细: <BR></B>
<B>品名 数量<BR></B>
<B>品名数量单价小计<BR></B>
--------------------------------<BR>`
// <B><BOLD>实际支付:</BOLD></B><B>%s<BR></B>
orderParams := []interface{}{
@@ -154,9 +153,8 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
for _, sku := range order.Skus {
orderFmt += `<B>%s<BR></B>`
orderFmt += `<B>%s<BR><BR></B>`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count))
//jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count))
orderFmt += `<B>%s %s %s<BR><BR></B>`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
}
orderFmt += `<BR>
<B><BOLD>共%d种%d件商品</BOLD></B>

View File

@@ -60,7 +60,7 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
客户备注: *
<big>%s*
商品明细: *
品名 数量
品名 数量 单价 小计
--------------------------------*
`
// <S011>实际支付: %s*
@@ -81,8 +81,7 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
for _, sku := range order.Skus {
orderFmt += `%s*`
orderFmt += `%8s%10s%10s*`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count))
// jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count))
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
}
orderFmt += `
*
@@ -136,7 +135,7 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
<big>客户备注: *
<big>%s*
<big>商品明细: *
<big>品名 数量*
<big>品名数量单价小计*
--------------------------------*
`
// <big>实际支付: %s*
@@ -156,9 +155,8 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
}
for _, sku := range order.Skus {
orderFmt += `<big>%s*`
orderFmt += `<big>%s*`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count))
// jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count))
orderFmt += `<big>%s %s %s*`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
}
orderFmt += `
<big>共%d种%d件商品*

View File

@@ -58,7 +58,7 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
\n
\n
商品明细: \n
品名 数量 \n
品名 数量 单价 小计\n
--------------------------------\n`
// <FB>实际支付:</FB>%s\n
orderParams := []interface{}{
@@ -78,9 +78,8 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
for _, sku := range order.Skus {
orderFmt += `%s\n`
orderFmt += `%8s\n`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count))
//jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count))
orderFmt += `%8s%10s%10s\n`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
}
orderFmt += `\n
<FB>共%d种%d件商品</FB>
@@ -127,7 +126,7 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
\n
\n
<FS2>商品明细: \n</FS2>
<FS2>品名 数量\n</FS2>
<FS2>品名数量单价小计\n</FS2>
--------------------------------\n`
// <FS2><FB>实际支付:</FB>%s\n</FS2>
orderParams := []interface{}{
@@ -147,9 +146,8 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
for _, sku := range order.Skus {
orderFmt += `<FS2>%s\n</FS2>`
orderFmt += `<FS2>%s\n\n</FS2>`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count))
//jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count))
orderFmt += `<FS2>%s %s %s\n\n</FS2>`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
}
orderFmt += `\n
<FS2><FB>共%d种%d件商品</FB></FS2>

View File

@@ -123,7 +123,7 @@ func result2Orders(msg *jdshopapi.CallBackResult) (order *model.GoodsOrder, err
order.ExpectedDeliveredTime = order.OrderCreatedAt.Add(time.Hour)
order.BusinessType = model.BusinessTypeImmediate
} else {
globals.SugarLogger.Warnf("暂不支持的京东商城订单类型type: %v", msg.OrderState)
globals.SugarLogger.Debugf("暂不支持的京东商城订单类型type: %v", msg.OrderState)
return nil, err
}

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"math"
"regexp"
"sort"
"strings"
"time"
@@ -33,7 +32,6 @@ 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"
)
const (
@@ -113,6 +111,7 @@ type JxOrderInfo struct {
Weight int `json:"weight"`
FromStoreID int `json:"fromStoreID"`
EarningType int `json:"earningType"`
OrderType int `json:"orderType"`
}
type DeliveryTimeItem struct {
@@ -220,7 +219,7 @@ func GetMyOrderCountInfo(ctx *jxcontext.Context, fromDate, toDate time.Time, sta
}
//fromStoreID 为0 表示非物料订单(京西商城订单等)
//fromStoreID 为 门店ID 表示是物料订单fromStoreID表示是哪个门店申请的物料
//fromStoreID 为 门店ID 表示是物料订单fromStoreID表示是哪个门店申请的物料,或者进货方门店
//fromStoreID 为-1 表示也是物料订单,但是不是门店申请,是个人申请的
//fromStoreID 在后面 generateOrder中有用
func CreateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64, createType int, fromStoreID int, IsDeliverySelf bool) (outJxOrder *JxOrderInfo, err error) {
@@ -373,10 +372,12 @@ func OnPayFinished(orderPay *model.OrderPay) (err error) {
order.StatusTime = *orderPay.PayFinishedAt
err = callNewOrder(order)
//如果是物料的订单,直接到拣货完成,配送中的状态
// if order.OrderType != model.OrderTypeNormal {
if order.FromStoreID != 0 {
netprinter.PrintOrderByOrder(jxcontext.AdminCtx, order)
PickupGoods(order, false, "jxadmin")
}
// }
}
return err
}
@@ -509,10 +510,6 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
return nil, nil, fmt.Errorf("预订单只能预定当天或第二天")
}
}
// if !isTimeInOpTime(storeDetail.OpenTime1, storeDetail.CloseTime1, storeDetail.OpenTime2, storeDetail.CloseTime2, checkTime) {
// return nil, nil, fmt.Errorf("门店:%s不在营业时间范围", storeDetail.Name)
// }
outJxOrder2 := *jxOrder
outJxOrder2.Skus = nil
outJxOrder2.OrderPrice = 0
@@ -549,7 +546,7 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
}
skuMap := make(map[int]*model.SkuAndName)
for _, v := range skuList {
if fromStoreID != 0 {
if jxOrder.OrderType == model.OrderTypeMatter {
if v.EclpID == "" {
return nil, nil, fmt.Errorf("此商品物料编码为空请联系管理员skuID:[%v]", v.ID)
}
@@ -561,7 +558,7 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
sum int //申请物料的店的最近销量,以下会根据销量计算具体袋子的价格
flag = false //新店袋子拆分当个参数
)
if fromStoreID != 0 && fromStoreID != -1 {
if jxOrder.OrderType == model.OrderTypeMatter && fromStoreID != -1 {
result, _ = orderman.GetMatterStoreOrderCount(nil, fromStoreID)
sum = result.Count
}
@@ -573,7 +570,7 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
}
for _, v := range skus {
if storeSkuBind := storeSkuMap[v.SkuID]; storeSkuBind != nil {
if fromStoreID != 0 {
if jxOrder.OrderType == model.OrderTypeMatter {
result2, _ := api.JdEclpAPI.QueryStock(storeSkuBind.EclpID)
if len(result2) > 0 {
if result2[0].UsableNum < v.Count {
@@ -611,7 +608,7 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
}
}
if jxSku != nil {
if fromStoreID == 0 || fromStoreID == -1 {
if jxOrder.OrderType != model.OrderTypeMatter || (jxOrder.OrderType == model.OrderTypeMatter && fromStoreID == -1) {
outJxOrder.Skus = append(outJxOrder.Skus, jxSku)
outJxOrder.OrderPrice += int64(jxSku.Count) * jxSku.SalePrice
} else { //以下else为物料订单袋子金额和数量处理
@@ -710,15 +707,13 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
}
}
}
//物料订单的配送费另算,所以排除了免得多算一次
if fromStoreID == 0 {
sort.Sort(JxSkuInfoList(outJxOrder.Skus))
outJxOrder.FreightPrice, _, err = delivery.CalculateDeliveryFee(dao.GetDB(), jxOrder.StoreID, "",
jxutils.StandardCoordinate2Int(deliveryAddress.Lng), jxutils.StandardCoordinate2Int(deliveryAddress.Lat),
model.CoordinateTypeMars, outJxOrder.Weight, checkTime)
}
// if jxOrder.StoreID == specialStoreID {
// outJxOrder.FreightPrice = 0
// if fromStoreID == 0 {
// sort.Sort(JxSkuInfoList(outJxOrder.Skus))
// outJxOrder.FreightPrice, _, err = delivery.CalculateDeliveryFee(dao.GetDB(), jxOrder.StoreID, "",
// jxutils.StandardCoordinate2Int(deliveryAddress.Lng), jxutils.StandardCoordinate2Int(deliveryAddress.Lat),
// model.CoordinateTypeMars, outJxOrder.Weight, checkTime)
//TODO 2020-08-06 配送费固定5元
outJxOrder.FreightPrice = 500
// }
} else {
outJxOrder.FreightPrice = 0
@@ -729,28 +724,24 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
if err = err2; err != nil {
return nil, nil, fmt.Errorf("fromStoreID有误,[%v]", fromStoreID)
}
outJxOrder.FromStoreID = fromStoreID
if jxOrder.OrderType == model.OrderTypeMatter {
//TODO 修改配送费规则2020-04-28
//3kg 5元每多1kg加2元
//配送费要按分包规则计算
if outJxOrder.Weight <= 3000 {
outJxOrder.FreightPrice = 500
} else if outJxOrder.Weight > 3000 && outJxOrder.Weight <= splitMatterOrderMinWeight {
outJxOrder.FreightPrice = utils.Float64TwoInt64(500 + math.Ceil((utils.Int2Float64(outJxOrder.Weight)-3000)/1000)*200)
} else {
_, freightPrice, _ := tryToSplitMatterOrder(jxOrder)
outJxOrder.FreightPrice = freightPrice
}
}
//要求配送人姓名填门店名
if fromStoreID != -1 {
deliveryAddress.ConsigneeName = storeDetail2.Name
}
outJxOrder.FromStoreID = fromStoreID
//TODO 修改配送费规则2020-04-28
//3kg 5元每多1kg加2元
//配送费要按分包规则计算
if outJxOrder.Weight <= 3000 {
outJxOrder.FreightPrice = 500
} else if outJxOrder.Weight > 3000 && outJxOrder.Weight <= splitMatterOrderMinWeight {
outJxOrder.FreightPrice = utils.Float64TwoInt64(500 + math.Ceil((utils.Int2Float64(outJxOrder.Weight)-3000)/1000)*200)
} else {
_, freightPrice, _ := tryToSplitMatterOrder(jxOrder)
outJxOrder.FreightPrice = freightPrice
}
///规则为: 配送费用规则。起价5元(含2kg)之后每kg+2元不足1kg按1kg计算。
// if outJxOrder.Weight <= 2000 {
// outJxOrder.FreightPrice = 500
// } else {
// outJxOrder.FreightPrice = utils.Float64TwoInt64(500 + math.Ceil((utils.Int2Float64(outJxOrder.Weight)-2000)/1000)*200)
// }
} else {
if outJxOrder.FreightPrice > specialFreightPrice {
outJxOrder.FreightPrice = specialFreightPrice
@@ -831,6 +822,7 @@ func jxOrder2GoodsOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, deliveryAd
DeliveryType: model.OrderDeliveryTypeStoreSelf,
StatusTime: time.Now(),
EarningType: jxOrder.EarningType,
OrderType: jxOrder.OrderType,
}
if userID == "" {
order.UserID = ctx.GetUserID()
@@ -862,10 +854,12 @@ func jxOrder2GoodsOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, deliveryAd
order.TotalShopMoney = utils.Float64TwoInt64(float64(order.TotalShopMoney) * jdshopapi.JdsPayPercentage)
if jxOrder.FromStoreID != 0 {
order.FromStoreID = jxOrder.FromStoreID
order.WaybillVendorID = model.VendorIDJDWL
order.DeliveryFlag = model.OrderDeliveryFlagMaskScheduleDisabled
order.ConsigneeAddress = deliveryAddress.Address
order.Flag = 1
if jxOrder.OrderType == model.OrderTypeMatter {
order.WaybillVendorID = model.VendorIDJDWL
order.ConsigneeAddress = deliveryAddress.Address
}
}
//如果是自提单就设置
if IsDeliverySelf {
@@ -891,16 +885,17 @@ func AdjustOrder(ctx *jxcontext.Context, order *model.GoodsOrder, removedSkuList
func PickupGoods(order *model.GoodsOrder, isSelfDelivery bool, userName string) (err error) {
err = changeOrderStatus(order.VendorOrderID, model.OrderStatusFinishedPickup, "")
//如果是物料订单则直接进行京东物流的发单,并且状态直接变为配送中
//如果是进货的订单,直接变为配送中
err = orderSolutionForWuLiao(order)
return err
}
func orderSolutionForWuLiao(order *model.GoodsOrder) (err error) {
if order.FromStoreID != 0 {
err = changeOrderStatus(order.VendorOrderID, model.OrderStatusDelivering, "")
if order.OrderType == model.OrderTypeMatter {
var (
db = dao.GetDB()
)
err = changeOrderStatus(order.VendorOrderID, model.OrderStatusDelivering, "")
goods, err := dao.QueryOrders(db, order.VendorOrderID, -1, []int{model.VendorIDJX}, -1, utils.ZeroTimeValue, utils.ZeroTimeValue)
if err != nil || len(goods) == 0 {
return err
@@ -1080,7 +1075,7 @@ func CancelOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string)
}
func CancelMatterOrder(db *dao.DaoDB, order *model.GoodsOrder, reason string) (err error) {
if order.FromStoreID != 0 {
if order.OrderType == model.OrderTypeMatter {
if order.EclpOutID != "" {
//表示是京西的物料订单的子订单(拆分后的订单)
if len(order.VendorOrderID) == 16 && order.VendorID == model.VendorIDJX {
@@ -1814,5 +1809,14 @@ func buildJxOrderInfo(order *model.GoodsOrder, orderSkus []*model.OrderSku) (jxO
}
jxOrder.Skus = skus
jxOrder.Weight = weight
jxOrder.OrderType = model.OrderTypeMatter
return jxOrder
}
func GetSupplySupportStoreSkus(ctx *jxcontext.Context, fromDate, toDate string, fromStoreID, storeID int, percentage string) (orderSkus []*model.OrderSku, err error) {
var (
db = dao.GetDB()
)
orderSkus, err = dao.GetSupplySupportStoreSkus(db, utils.Str2Time(fromDate), utils.Str2Time(toDate), fromStoreID, storeID, utils.Str2Float64(percentage))
return orderSkus, err
}