京西也支持订单转移

This commit is contained in:
苏尹岚
2020-09-23 09:49:07 +08:00
parent 78ae47ce66
commit b5cb571630
4 changed files with 69 additions and 63 deletions

View File

@@ -1593,36 +1593,42 @@ func TransferJdsOrder(ctx *jxcontext.Context, vendorOrderID string, storeID int)
} else {
return "", fmt.Errorf("未查询到该门店对应的平台信息!门店:[%v]", order.StoreID)
}
if len(order.VendorOrderID) > 12 {
var goodsOrders []*model.GoodsOrder
sql := `
SELECT * FROM goods_order WHERE vendor_order_id2 = ? ORDER BY vendor_order_id DESC
`
sqlParams := []interface{}{order.VendorOrderID2}
err = dao.GetRows(db, &goodsOrders, sql, sqlParams)
if goodsOrders[0].Status != model.OrderStatusCanceled {
err = jdshop.ChangeOrderStatus(goodsOrders[0].VendorOrderID, model.OrderStatusCanceled, "订单转移被取消")
if order.VendorID == model.VendorIDJDShop {
if len(order.VendorOrderID) > 12 {
var goodsOrders []*model.GoodsOrder
sql := `
SELECT * FROM goods_order WHERE vendor_order_id2 = ? ORDER BY vendor_order_id DESC
`
sqlParams := []interface{}{order.VendorOrderID2}
err = dao.GetRows(db, &goodsOrders, sql, sqlParams)
if goodsOrders[0].Status != model.OrderStatusCanceled {
err = jdshop.ChangeOrderStatus(goodsOrders[0].VendorOrderID, model.OrderStatusCanceled, "订单转移被取消")
}
// suffix := utils.Str2Int(goodsOrders[0].VendorOrderID[12:len(goodsOrders[0].VendorOrderID)])
// suffix++
if len(order.VendorOrderID2) > 18 {
order.VendorOrderID2 = order.VendorOrderID2[0:12]
}
order.VendorOrderID = utils.Int64ToStr(utils.Str2Int64(order.VendorOrderID2)*10000) + utils.Int2Str(time.Now().Second())
if len(order.VendorOrderID) < 18 {
order.VendorOrderID = order.VendorOrderID + "0"
}
}
// suffix := utils.Str2Int(goodsOrders[0].VendorOrderID[12:len(goodsOrders[0].VendorOrderID)])
// suffix++
if len(order.VendorOrderID2) > 18 {
order.VendorOrderID2 = order.VendorOrderID2[0:12]
}
order.VendorOrderID = utils.Int64ToStr(utils.Str2Int64(order.VendorOrderID2)*10000) + utils.Int2Str(time.Now().Second())
if len(order.VendorOrderID) < 18 {
order.VendorOrderID = order.VendorOrderID + "0"
if storeID != model.JdShopMainStoreID {
order.DeliveryFlag = model.NO
}
} else {
order.VendorOrderID2 = order.VendorOrderID
order.VendorOrderID = utils.Int64ToStr(jxutils.GenOrderNo())
order.DeliveryFlag = model.NO
}
for _, sku := range skus {
sku.VendorOrderID = order.VendorOrderID
sku.ID = 0
order.Skus = append(order.Skus, sku)
}
if storeID != model.JdShopMainStoreID {
order.DeliveryFlag = model.NO
}
order.Status = model.OrderStatusNew
setJdsOrderSeq(order)
order.Status = model.OrderStatusNew
err = partner.CurOrderManager.OnOrderNew(order, model.Order2Status(order))
vendorOrderIDJds = order.VendorOrderID
return vendorOrderIDJds, err

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/aes"
"crypto/md5"
"encoding/base64"
"fmt"
"io/ioutil"
@@ -26,9 +27,10 @@ import (
)
var (
routinePool *routinepool.Pool
skuNamePat *regexp.Regexp
emailPat *regexp.Regexp
routinePool *routinepool.Pool
skuNamePat *regexp.Regexp
emailPat *regexp.Regexp
orderNoBeginTimestamp int64
resourceTypeMap = map[int][]string{
model.VendorIDQiNiuCloud: []string{
@@ -75,6 +77,7 @@ func init() {
// https://stackoverflow.com/questions/38933898/error-parsing-regexp-invalid-or-unsupported-perl-syntax
skuNamePat = regexp.MustCompile(`([\(\[【][^\(\[【\)\]】]*[\)\]】])?(.*?)([(].*[)])?\s*约?([1-9][\d\.]*)(g|G|kg|kG|Kg|KG|l|L|ml|mL|Ml|ML|克)\s*([(].*[)])?\s*(?:\/||)\s*([^\s()]{0,2})(\s.*)?$\s*([(].*[)])?$`)
emailPat = regexp.MustCompile(`[A-Za-z0-9_\-.]+@(?:[A-Za-z0-9_\-]+\.)+[A-Za-z]+`)
orderNoBeginTimestamp = utils.Str2Time("2010-01-01 00:00:00").Unix()
}
func getJxStoreIDFromOrder(order *model.GoodsOrder) (retVal int) {
@@ -168,6 +171,36 @@ func GetPossibleVendorIDFromVendorOrderID(vendorOrderID string) (vendorID int) {
return vendorID
}
func GenOrderNo() (orderNo int64) {
const prefix = 88
const randPartNum = 1000
orderNo = time.Now().Unix() - orderNoBeginTimestamp
orderNo = orderNo * randPartNum
md5Bytes := md5.Sum([]byte(utils.GetUUID()))
randPart := 0
for k, v := range md5Bytes {
randPart += int(v) << ((k % 3) * 8)
}
orderNo += int64(randPart % randPartNum)
orderNo += int64(math.Pow10(int(math.Log10(float64(orderNo)))+1)) * prefix
return orderNo
}
func GenAfsOrderNo() (orderNo int64) {
const prefix = 80
const randPartNum = 100
orderNo = time.Now().Unix() - orderNoBeginTimestamp
orderNo = orderNo * randPartNum
md5Bytes := md5.Sum([]byte(utils.GetUUID()))
randPart := 0
for k, v := range md5Bytes {
randPart += int(v) << ((k % 3) * 8)
}
orderNo += int64(randPart % randPartNum)
orderNo += int64(math.Pow10(int(math.Log10(float64(orderNo)))+1)) * prefix
return orderNo
}
func GetPossibleVendorIDFromAfsOrderID(afsOrderID string) (vendorID int) {
vendorID = model.VendorIDUnknown
if afsOrderIDInt64 := utils.Str2Int64WithDefault(afsOrderID, 0); afsOrderIDInt64 > 0 {

View File

@@ -1,7 +1,6 @@
package localjx
import (
"crypto/md5"
"fmt"
"math"
"regexp"
@@ -140,8 +139,6 @@ type MatterOrderStatus struct {
}
var (
orderNoBeginTimestamp int64
weekdayMap = map[int]string{
1: "一",
2: "二",
@@ -174,7 +171,6 @@ var (
)
func init() {
orderNoBeginTimestamp = utils.Str2Time("2010-01-01 00:00:00").Unix()
}
func GetMyOrders(ctx *jxcontext.Context, fromDateStr, toDateStr string, params map[string]interface{}, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
@@ -250,7 +246,7 @@ func CreateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64,
if jxOrder.IsPriceDefend == model.YES {
outJxOrder.OrderID = jxOrder.OrderID
} else {
outJxOrder.OrderID = GenOrderNo(ctx)
outJxOrder.OrderID = jxutils.GenOrderNo()
}
order, err2 := jxOrder2GoodsOrder(ctx, outJxOrder, deliveryAddress, "", IsDeliverySelf)
if err = err2; err == nil {
@@ -273,7 +269,7 @@ func buildDefendPriceOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, address
)
issue = jxutils.GetDefendPriceIssue()
priceDefendOrder := &model.PriceDefendOrder{
VendorOrderID: utils.Int64ToStr(GenOrderNo(ctx)),
VendorOrderID: utils.Int64ToStr(jxutils.GenOrderNo()),
StoreID: jxOrder.StoreID,
SkuID: jxOrder.Skus[0].SkuID,
AddressID: addressID,
@@ -471,37 +467,6 @@ func OnPayFinished(orderPay *model.OrderPay) (err error) {
return err
}
func GenOrderNo(ctx *jxcontext.Context) (orderNo int64) {
const prefix = 88
const randPartNum = 1000
orderNo = time.Now().Unix() - orderNoBeginTimestamp
// fmt.Println(orderNo)
orderNo = orderNo * randPartNum
md5Bytes := md5.Sum([]byte(utils.GetUUID()))
randPart := 0
for k, v := range md5Bytes {
randPart += int(v) << ((k % 3) * 8)
}
orderNo += int64(randPart % randPartNum)
orderNo += int64(math.Pow10(int(math.Log10(float64(orderNo)))+1)) * prefix
return orderNo
}
func GenAfsOrderNo(ctx *jxcontext.Context) (orderNo int64) {
const prefix = 80
const randPartNum = 100
orderNo = time.Now().Unix() - orderNoBeginTimestamp
orderNo = orderNo * randPartNum
md5Bytes := md5.Sum([]byte(utils.GetUUID()))
randPart := 0
for k, v := range md5Bytes {
randPart += int(v) << ((k % 3) * 8)
}
orderNo += int64(randPart % randPartNum)
orderNo += int64(math.Pow10(int(math.Log10(float64(orderNo)))+1)) * prefix
return orderNo
}
func GenPayOrderID(order *model.GoodsOrder) (payOrderID int64) {
return utils.Str2Int64(order.VendorOrderID)
}
@@ -2007,7 +1972,7 @@ func CreateOrderByPriceDefend(ctx *jxcontext.Context) (err error) {
BuyerComment: "守价订单",
StoreID: vv[0].StoreID,
IsPriceDefend: model.YES,
OrderID: GenOrderNo(ctx),
OrderID: jxutils.GenOrderNo(),
UserID: address.UserID,
}
for _, priceDefend := range vv {

View File

@@ -5,6 +5,8 @@ import (
"strings"
"time"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/business/model/dao"
@@ -142,7 +144,7 @@ func (c *PurchaseHandler) PartRefundOrder(ctx *jxcontext.Context, order *model.G
func buildOrderStatus(ctx *jxcontext.Context, order *model.GoodsOrder, reason string, isJxShop bool) (orderStatus *model.OrderStatus) {
orderStatus = &model.OrderStatus{
VendorOrderID: utils.Int64ToStr(localjx.GenAfsOrderNo(ctx)), // 是售后单ID不是订单ID订单ID在RefVendorOrderID中
VendorOrderID: utils.Int64ToStr(jxutils.GenAfsOrderNo()), // 是售后单ID不是订单ID订单ID在RefVendorOrderID中
VendorID: order.VendorID,
OrderType: model.OrderTypeAfsOrder,
RefVendorOrderID: order.VendorOrderID,