物料订单增加配送员等

This commit is contained in:
苏尹岚
2020-03-12 16:12:00 +08:00
parent 9fbfa04def
commit bd0480d2b3
3 changed files with 124 additions and 56 deletions

View File

@@ -1179,23 +1179,8 @@ func GetMatterStoreOrderCount(ctx *jxcontext.Context, storeID int) (result *Orde
db = dao.GetDB()
orderPays []*model.OrderPay
orderCount = &OrderCount{}
orderTime time.Time
)
sql2 := `
SELECT COUNT(*) count
FROM goods_order
WHERE IF(store_id = 0,jx_store_id,store_id) = ?
AND order_created_at <= NOW() AND order_created_at >= ?
AND status = ?
`
sqlParams2 := []interface{}{
storeID,
time.Now().AddDate(0, 0, -7),
model.OrderStatusFinished,
}
err = dao.GetRow(db, &orderCount, sql2, sqlParams2)
if err != nil {
return nil, err
}
sql := `
SELECT b.*
FROM goods_order a
@@ -1215,8 +1200,27 @@ func GetMatterStoreOrderCount(ctx *jxcontext.Context, storeID int) (result *Orde
} else {
orderCount.Flag = true
}
orderTime = *orderPay.PayFinishedAt
} else {
orderTime = time.Now().AddDate(0, 0, -7)
orderCount.Flag = true
}
sql2 := `
SELECT COUNT(*) count
FROM goods_order
WHERE IF(store_id = 0,jx_store_id,store_id) = ?
AND order_created_at <= NOW() AND order_created_at >= ?
AND status = ?
`
sqlParams2 := []interface{}{
storeID,
orderTime,
model.OrderStatusFinished,
}
err = dao.GetRow(db, &orderCount, sql2, sqlParams2)
if err != nil {
return nil, err
}
return orderCount, err
}

View File

@@ -4,6 +4,7 @@ import (
"crypto/md5"
"fmt"
"math"
"regexp"
"sort"
"strings"
"time"
@@ -132,6 +133,8 @@ var (
6039387: 200,
6039390: 200,
}
regexpCnameAndCmobile = regexp.MustCompile(`配送员,(.*),手机号,(.*)`)
)
func init() {
@@ -224,7 +227,7 @@ func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType
err = dao.CreateEntity(dao.GetDB(), orderPay)
}
case model.PayTypeTL:
if orderPay, err = pay4OrderByTL(ctx, order, vendorPayType); err == nil {
if orderPay, err = pay4OrderByTL(ctx, order, vendorPayType); err == nil && orderPay != nil {
dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName())
err = dao.CreateEntity(dao.GetDB(), orderPay)
}
@@ -607,11 +610,19 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
}
deliveryAddress.ConsigneeName = storeDetail2.Name
outJxOrder.FromStoreID = fromStoreID
// if outJxOrder.Weight > 5000 {
// _, freightPrice, err := tryToSplitMatterOrder(outJxOrder)
// if err != nil {
// return nil, nil, err
// }
// outJxOrder.FreightPrice = int64(freightPrice)
// } else {
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
@@ -633,6 +644,27 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
return outJxOrder, deliveryAddress, err
}
func tryToSplitMatterOrder(jxOrder *JxOrderInfo) (outOrder []*JxOrderInfo, freightPrice int, err error) {
var (
skus = jxOrder.Skus
weightList []int
weightMap = make(map[int]*JxSkuInfo)
)
for _, v := range skus {
for i := 0; i < v.Count; i++ {
weightList = append(weightList, v.Weight)
}
weightMap[v.Weight] = v
}
sort.Sort(sort.Reverse(sort.IntSlice(weightList)))
for _, v := range weightList {
if weightMap[v] != nil {
}
}
return outOrder, freightPrice, err
}
func matterSkusLimited(skus []*JxSkuInfo, storeID int) (err error) {
result, err := orderman.GetMatterStoreOrderCount(nil, storeID)
sum := 0
@@ -750,46 +782,56 @@ func orderSolutionForWuLiao(order *model.GoodsOrder) (err error) {
return err
}
orderSkus := goods[0].Skus
if order.Weight <= 5000 { //如果总重量小于5kg就直接发单
var (
goodsNos []string
prices []string
quantities []string
)
err = changeOrderStatus(order.VendorOrderID, model.OrderStatusDelivering, "")
for _, v := range orderSkus {
skus, err := dao.GetSkus(db, []int{v.SkuID}, nil, nil, nil, nil)
if err != nil || len(skus) == 0 {
continue
}
goodsNos = append(goodsNos, skus[0].EclpID)
prices = append(prices, "0")
quantities = append(quantities, utils.Int2Str(v.Count))
// if order.Weight <= 5000 { //如果总重量小于5kg就直接发单
var (
goodsNos []string
prices []string
quantities []string
)
err = changeOrderStatus(order.VendorOrderID, model.OrderStatusDelivering, "")
for _, v := range orderSkus {
skus, err := dao.GetSkus(db, []int{v.SkuID}, nil, nil, nil, nil)
if err != nil || len(skus) == 0 {
continue
}
result, err := api.JdEclpAPI.AddOrder(&jdeclpapi.AddOrderParam{
IsvUUID: order.VendorOrderID,
IsvSource: jdeclpapi.IsvSource,
ShopNo: jdeclpapi.ShopNo,
DepartmentNo: jdeclpapi.DepartmentNo,
WarehouseNo: jdeclpapi.WarehouseNo,
SalesPlatformOrderNo: order.VendorOrderID,
SalePlatformSource: jdeclpapi.SalePlatformSource,
ConsigneeName: order.ConsigneeName,
ConsigneeMobile: order.ConsigneeMobile,
ConsigneeAddress: order.ConsigneeAddress,
OrderMark: jdeclpapi.OrderMark,
GoodsNo: strings.Join(goodsNos, ","),
Price: strings.Join(prices, ","),
Quantity: strings.Join(quantities, ","),
})
if err != nil {
return err
}
order.EclpOutID = result
dao.UpdateEntity(db, order, "EclpOutID")
} else { //如果重量超过5kg则需要进行拆单分包商品分包规则。最后一个包不超过5kg,其他包不超过3kg
goodsNos = append(goodsNos, skus[0].EclpID)
prices = append(prices, "0")
quantities = append(quantities, utils.Int2Str(v.Count))
}
result, err := api.JdEclpAPI.AddOrder(&jdeclpapi.AddOrderParam{
IsvUUID: order.VendorOrderID,
IsvSource: jdeclpapi.IsvSource,
ShopNo: jdeclpapi.ShopNo,
DepartmentNo: jdeclpapi.DepartmentNo,
WarehouseNo: jdeclpapi.WarehouseNo,
SalesPlatformOrderNo: order.VendorOrderID,
SalePlatformSource: jdeclpapi.SalePlatformSource,
ConsigneeName: order.ConsigneeName,
ConsigneeMobile: order.ConsigneeMobile,
ConsigneeAddress: order.ConsigneeAddress,
OrderMark: jdeclpapi.OrderMark,
GoodsNo: strings.Join(goodsNos, ","),
Price: strings.Join(prices, ","),
Quantity: strings.Join(quantities, ","),
})
if err != nil {
return err
}
order.EclpOutID = result
dao.UpdateEntity(db, order, "EclpOutID")
waybill := &model.Waybill{
VendorOrderID: order.VendorOrderID,
OrderVendorID: model.VendorIDJX,
VendorWaybillID: order.EclpOutID,
WaybillVendorID: model.VendorIDJDWL,
Status: model.WaybillStatusDelivering,
WaybillCreatedAt: time.Now(),
StatusTime: time.Now(),
}
dao.CreateEntity(db, waybill)
// } else { //如果重量超过5kg则需要进行拆单分包商品分包规则。最后一个包不超过5kg,其他包不超过3kg
// }
//刷新一下库存
for _, v := range goods[0].Skus {
cms.RefreshMatterStock(jxcontext.AdminCtx, v.SkuID)
@@ -1157,5 +1199,27 @@ func GetMatterOrderStatus(ctx *jxcontext.Context, vendorOrderID string) (result
dao.Commit(db)
}
}
if len(getTrackMessagePlusByOrderResult.ResultData) > 0 {
var (
waybillCode = getTrackMessagePlusByOrderResult.ResultData[0].WaybillCode
cName string
cMobile string
)
for _, vv := range getTrackMessagePlusByOrderResult.ResultData {
if vv.OpeTitle == "配送员收货" {
result := regexpCnameAndCmobile.FindAllStringSubmatch(vv.OpeName, -1)
cName = result[0][1]
cMobile = result[0][2]
break
}
}
waybills, _ := dao.GetWayBillByOrderID(db, -1, model.VendorIDJX, -1, vendorOrderID)
if len(waybills) > 0 {
waybills[0].VendorWaybillID = waybillCode
waybills[0].CourierName = cName
waybills[0].CourierMobile = cMobile
dao.UpdateEntity(db, waybills[0], "VendorWaybillID", "CourierName", "CourierMobile")
}
}
return result, err
}

View File

@@ -264,7 +264,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
foodData["min_order_count"] = 1
foodData["unit"] = storeSku.Unit
foodData["box_num"] = 1
foodData["box_price"] = jxutils.IntPrice2Standard(storeSku.BoxFee)
// foodData["box_price"] = jxutils.IntPrice2Standard(storeSku.BoxFee)
catCode := tryCatName2Code(storeSku.VendorCatID)
if catCode != "" {
foodData["category_code"] = catCode