86 lines
2.7 KiB
Go
86 lines
2.7 KiB
Go
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) {
|
|
if len(mobileList) > 0 {
|
|
errList := errlist.New()
|
|
mobileList = jxutils.StringMap2List(jxutils.StringList2Map(mobileList))
|
|
for _, mobileNum := range mobileList {
|
|
if mobileNum != "" {
|
|
globals.SugarLogger.Debugf("SendSMSMsg mobileNum:%s, templateCode:%s", mobileNum, templateCode)
|
|
if true { //globals.EnableStoreWrite {
|
|
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, true))
|
|
errList.AddErr(fmt.Errorf(errMsg))
|
|
if warningMap[response.Code] == 1 {
|
|
globals.SugarLogger.Warnf(errMsg)
|
|
} else {
|
|
globals.SugarLogger.Infof(errMsg)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
err = errList.GetErrListAsOne()
|
|
}
|
|
return err
|
|
}
|
|
|
|
func getOrderNotifyPhone(order *model.GoodsOrder) (phoneList []string) {
|
|
store := &model.Store{}
|
|
store.ID = jxutils.GetSaleStoreIDFromOrder(order)
|
|
if err := dao.GetEntity(dao.GetDB(), store); err == nil {
|
|
if store.SMSNotify != 0 {
|
|
for _, v := range []string{store.Tel1, store.Tel2} {
|
|
if v != "" {
|
|
phoneList = append(phoneList, v)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return phoneList
|
|
}
|
|
|
|
func NotifyNewOrder(order *model.GoodsOrder) (err error) {
|
|
err = SendSMSMsg(getOrderNotifyPhone(order), "京西菜市", "SMS_175583150", map[string]interface{}{
|
|
"daySeq": order.OrderSeq,
|
|
"consigneeName": order.ConsigneeName,
|
|
"payMoney": jxutils.IntPrice2StandardString(order.ActualPayPrice),
|
|
})
|
|
return err
|
|
}
|
|
|
|
func NotifyOrderCanceled(order *model.GoodsOrder) (err error) {
|
|
err = SendSMSMsg(getOrderNotifyPhone(order), "京西菜市", "SMS_175573134", map[string]interface{}{
|
|
"vendorName": model.VendorChineseNames[order.VendorID],
|
|
"seq": order.OrderSeq,
|
|
"orderID": order.VendorOrderID,
|
|
})
|
|
return err
|
|
}
|