- send weixin msg to me.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
@@ -51,12 +52,19 @@ func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
|
||||
WHERE jxstoreid = ? AND parentid = -1 AND openid IS NOT NULL
|
||||
`, storeID, storeID).ValuesList(&lists)
|
||||
if err != nil || num == 0 {
|
||||
globals.SugarLogger.Infof("can not find openid for store:%s, error:%v", storeID, err)
|
||||
globals.SugarLogger.Infof("can not find openid for store:%d, num:%, error:%v", storeID, num, err)
|
||||
return retVal
|
||||
}
|
||||
for _, v := range lists {
|
||||
retVal = append(retVal, v[0].(string))
|
||||
}
|
||||
// todo,调试,只发给我
|
||||
globals.SugarLogger.Debugf("store:%d, openids:%v", storeID, retVal)
|
||||
if storeID == 100146 {
|
||||
retVal = []string{"oYN_ust9hXKEvEv0X6Mq6nlAWs_E"}
|
||||
} else {
|
||||
retVal = []string{}
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
@@ -64,13 +72,11 @@ func SendMsgToStore(storeID int, templateID, downloadURL string, data interface{
|
||||
openIDs := GetWeixinOpenIDsFromStoreID(storeID)
|
||||
errCount := 0
|
||||
for _, openID := range openIDs {
|
||||
globals.SugarLogger.Debugf("send to:%s, templateID:%s, msg:%s", openID, templateID, string(utils.MustMarshal(data)))
|
||||
// todo
|
||||
// err2 := api.WeixinAPI.MessageTemplateSend(openID, templateID, downloadURL, nil, data)
|
||||
// if err2 != nil {
|
||||
// err = err2
|
||||
// errCount++
|
||||
// }
|
||||
err2 := api.WeixinAPI.MessageTemplateSend(openID, templateID, downloadURL, nil, data)
|
||||
if err2 != nil {
|
||||
err = err2
|
||||
errCount++
|
||||
}
|
||||
}
|
||||
if errCount < len(openIDs) {
|
||||
err = nil // 只要成功一个都当成成功
|
||||
@@ -124,6 +130,7 @@ func NotifyNewOrder(order *model.GoodsOrder) (err error) {
|
||||
func NotifyWaybillStatus(bill *model.Waybill, order *model.GoodsOrder) error {
|
||||
var title string
|
||||
var templateID string
|
||||
remark := ""
|
||||
switch bill.Status {
|
||||
case model.WaybillStatusAccepted:
|
||||
if bill.WaybillVendorID == model.VendorIDMTPS {
|
||||
@@ -131,6 +138,7 @@ func NotifyWaybillStatus(bill *model.Waybill, order *model.GoodsOrder) error {
|
||||
} else if bill.WaybillVendorID == model.VendorIDDada {
|
||||
templateID = WX_DADA_DELIVERY_GRABDONE_TEMPLATE_ID
|
||||
}
|
||||
remark = FormatDeliveryTime(order)
|
||||
title = fmt.Sprintf("%s %s#订单长时间无人配送,我们已安排%s配送员%s电话号码%s负责配送。^_^", model.VendorChineseNames[bill.OrderVendorID], bill.VendorOrderID, model.VendorChineseNames[bill.WaybillVendorID], bill.CourierName, bill.CourierMobile)
|
||||
case model.WaybillStatusDelivered:
|
||||
if bill.WaybillVendorID == model.VendorIDMTPS {
|
||||
@@ -140,7 +148,7 @@ func NotifyWaybillStatus(bill *model.Waybill, order *model.GoodsOrder) error {
|
||||
}
|
||||
title = fmt.Sprintf("%s 第%d号订单的配送完成", model.VendorChineseNames[bill.OrderVendorID], order.OrderSeq)
|
||||
}
|
||||
if title != "" {
|
||||
if templateID != "" {
|
||||
data := map[string]interface{}{
|
||||
"first": map[string]interface{}{
|
||||
"value": title,
|
||||
@@ -159,7 +167,7 @@ func NotifyWaybillStatus(bill *model.Waybill, order *model.GoodsOrder) error {
|
||||
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
|
||||
},
|
||||
"remark": map[string]interface{}{
|
||||
"value": FormatDeliveryTime(order),
|
||||
"value": remark,
|
||||
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user