Merge remote-tracking branch 'origin/jdshop' into jxact

This commit is contained in:
苏尹岚
2020-09-25 11:38:03 +08:00
27 changed files with 428 additions and 156 deletions

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,6 +1,7 @@
package push
import (
"fmt"
"strings"
"git.rosy.net.cn/baseapi/platformapi/unipushapi"
@@ -13,24 +14,22 @@ import (
"github.com/astaxie/beego"
)
func NotifyNewOrder(order *model.GoodsOrder) {
func pushToSingle(content, title string, storeID int) {
var (
db = dao.GetDB()
)
globals.SugarLogger.Debugf("NotifyNewOrder push begin orderID :[%v]", order.VendorOrderID)
storePushs, err := dao.GetStorePushClient(db, jxutils.GetSaleStoreIDFromOrder(order), "")
if !globals.IsProductEnv() {
return
}
storePushs, err := dao.GetStorePushClient(db, storeID, "")
if err != nil {
return
}
for _, v := range storePushs {
sb := new(strings.Builder)
sb.WriteString("老板,")
sb.WriteString(order.ConsigneeName)
sb.WriteString("购买了商品")
sb.WriteString(getOrderDetailBrief(order))
status, err2 := api.PushAPI.PushToSingle(v.ClientID, false, &unipushapi.Notification{
Title: "京西菜市新订单推送",
Body: sb.String(),
Title: title,
Body: content,
})
if err = err2; err != nil {
globals.SugarLogger.Debugf("NotifyNewOrder push error: [%v]", err)
@@ -38,7 +37,7 @@ func NotifyNewOrder(order *model.GoodsOrder) {
}
if status == unipushapi.SuccessOffLine {
_, err = api.PushAPI.PushToSingle(v.ClientID, true, &unipushapi.Notification{
Body: sb.String(),
Body: content,
})
if err != nil {
globals.SugarLogger.Debugf("NotifyNewOrder push2 error: [%v]", err)
@@ -49,6 +48,16 @@ func NotifyNewOrder(order *model.GoodsOrder) {
}
}
func NotifyNewOrder(order *model.GoodsOrder) {
globals.SugarLogger.Debugf("NotifyNewOrder push begin orderID :[%v]", order.VendorOrderID)
sb := new(strings.Builder)
sb.WriteString("老板,")
sb.WriteString(order.ConsigneeName)
sb.WriteString("购买了商品")
sb.WriteString(getOrderDetailBrief(order))
pushToSingle(sb.String(), "京西菜市新订单推送", jxutils.GetSaleStoreIDFromOrder(order))
}
func getOrderDetailBrief(order *model.GoodsOrder) (brief string) {
sb := new(strings.Builder)
sb.WriteString(order.Skus[0].SkuName)
@@ -72,3 +81,15 @@ func getOrderDetailBrief(order *model.GoodsOrder) (brief string) {
sb.WriteString("元")
return sb.String()
}
func NotifyAfsOrder(afsOrder *model.AfsOrder) (err error) {
globals.SugarLogger.Debugf("NotifyAfsOrder push begin orderID :[%v]", afsOrder.VendorOrderID)
pushToSingle("老板,您有新的售后单,请尽快处理!", "京西菜市售后单推送", jxutils.GetSaleStoreIDFromAfsOrder(afsOrder))
return err
}
func NotifyOrderCanceled(order *model.GoodsOrder) (err error) {
title := fmt.Sprintf("老板,您的订单%s第%d号订单, %s被取消了", model.VendorChineseNames[order.VendorID], order.OrderSeq, order.VendorOrderID)
pushToSingle(title, "京西菜市取消单推送", jxutils.GetSaleStoreIDFromOrder(order))
return err
}