推送app
This commit is contained in:
74
business/jxutils/unipush/push.go
Normal file
74
business/jxutils/unipush/push.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package push
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/unipushapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
func NotifyNewOrder(order *model.GoodsOrder) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
globals.SugarLogger.Debugf("NotifyNewOrder push begin orderID :[%v]", order.VendorOrderID)
|
||||
storePushs, err := dao.GetStorePushClient(db, jxutils.GetSaleStoreIDFromOrder(order), "")
|
||||
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(),
|
||||
})
|
||||
if err = err2; err != nil {
|
||||
globals.SugarLogger.Debugf("NotifyNewOrder push error: [%v]", err)
|
||||
continue
|
||||
}
|
||||
if status == unipushapi.SuccessOffLine {
|
||||
_, err = api.PushAPI.PushToSingle(v.ClientID, true, &unipushapi.Notification{
|
||||
Body: sb.String(),
|
||||
})
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("NotifyNewOrder push2 error: [%v]", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func getOrderDetailBrief(order *model.GoodsOrder) (brief string) {
|
||||
sb := new(strings.Builder)
|
||||
sb.WriteString(order.Skus[0].SkuName)
|
||||
sb.WriteString("等共")
|
||||
sb.WriteString(utils.Int2Str(order.Skus[0].Count))
|
||||
sb.WriteString("份(")
|
||||
sb.WriteString(jxutils.IntPrice2StandardString(order.Skus[0].SalePrice))
|
||||
sb.WriteString("元/份)等,预计收入")
|
||||
//TODO 2020-07-20 果园和菜市不同
|
||||
var price int64
|
||||
if beego.BConfig.RunMode == "jxgy" {
|
||||
price = order.EarningPrice
|
||||
} else {
|
||||
if order.EarningType == model.EarningTypePoints {
|
||||
price = order.ActualPayPrice
|
||||
} else {
|
||||
price = order.ShopPrice
|
||||
}
|
||||
}
|
||||
sb.WriteString(jxutils.IntPrice2StandardString(price))
|
||||
sb.WriteString("元")
|
||||
return sb.String()
|
||||
}
|
||||
Reference in New Issue
Block a user