- 新订单时,发送短信消息
This commit is contained in:
61
business/jxutils/smsmsg/smsmsg.go
Normal file
61
business/jxutils/smsmsg/smsmsg.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package smsmsg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
aliyunsmsclient "github.com/KenmyZhang/aliyun-communicate"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
"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"
|
||||
)
|
||||
|
||||
var (
|
||||
warningMap = map[string]int{
|
||||
"isv.AMOUNT_NOT_ENOUGH": 1,
|
||||
"isv.ACCOUNT_ABNORMAL": 1,
|
||||
"isv.OUT_OF_SERVICE": 1,
|
||||
"isv.DAY_LIMIT_CONTROL": 1,
|
||||
}
|
||||
)
|
||||
|
||||
func SendSMSMsg(mobileList []string, signName, templateCode string, templateParam map[string]interface{}) (err error) {
|
||||
errList := errlist.New()
|
||||
for _, mobileNum := range mobileList {
|
||||
if mobileNum != "" {
|
||||
globals.SugarLogger.Debugf("SendSMSMsg mobileNum:%s, templateCode:%s", mobileNum, templateCode)
|
||||
if response, err := api.SMSClient.Execute(globals.AliKey, globals.AliSecret, mobileNum, signName, templateCode, string(utils.MustMarshal(templateParam))); err != nil {
|
||||
globals.SugarLogger.Warnf("SendSMSMsg mobileNum:%s failed with error:%v", mobileNum, err)
|
||||
errList.AddErr(err)
|
||||
} else if response.Code != aliyunsmsclient.ResponseCodeOk {
|
||||
errMsg := fmt.Sprintf("SendSMSMsg mobileNum:%s failed with response:%s", mobileNum, utils.Format4Output(response, false))
|
||||
errList.AddErr(fmt.Errorf(errMsg))
|
||||
if warningMap[response.Code] == 1 {
|
||||
globals.SugarLogger.Warnf(errMsg)
|
||||
} else {
|
||||
globals.SugarLogger.Infof(errMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return errList.GetErrListAsOne()
|
||||
}
|
||||
|
||||
func NotifyNewOrder(order *model.GoodsOrder) (err error) {
|
||||
store := &model.Store{}
|
||||
store.ID = jxutils.GetSaleStoreIDFromOrder(order)
|
||||
if err = dao.GetEntity(dao.GetDB(), store); err == nil {
|
||||
if store.SMSNotify != 0 {
|
||||
err = SendSMSMsg([]string{store.Tel1, store.Tel2}, "京西菜市", "SMS_173477895", map[string]interface{}{
|
||||
"daySeq": order.OrderSeq,
|
||||
"consigneeName": order.ConsigneeName,
|
||||
"payMoney": order.ActualPayPrice,
|
||||
})
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user