品牌余额不足10快发通知

This commit is contained in:
suyl
2021-08-31 14:52:49 +08:00
parent 637efdc421
commit 5a658dd646
4 changed files with 71 additions and 13 deletions

View File

@@ -7,6 +7,7 @@ import (
aliyunsmsclient "github.com/KenmyZhang/aliyun-communicate"
dyvmsapiclient "github.com/alibabacloud-go/dyvmsapi-20170525-2.0.2/client"
"github.com/alibabacloud-go/tea/tea"
"time"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/baseapi/utils/errlist"
@@ -54,7 +55,7 @@ func SendSMSMsg(mobileList []string, signName, templateCode string, templatePara
return err
}
func SendVoiceMsg(mobileList []string, templateParam map[string]interface{}) (err error) {
func SendVoiceMsg(mobileList []string, templateCode string, templateParam map[string]interface{}) (err error) {
if len(mobileList) > 0 {
errList := errlist.New()
mobileList = jxutils.StringMap2List(jxutils.StringList2Map(mobileList))
@@ -62,7 +63,7 @@ func SendVoiceMsg(mobileList []string, templateParam map[string]interface{}) (er
if mobileNum != "" {
request := &dyvmsapiclient.SingleCallByTtsRequest{
CalledNumber: tea.String(mobileNum),
TtsCode: tea.String(globals.SMSVoicePickOrderTemplate),
TtsCode: tea.String(templateCode),
TtsParam: tea.String(string(utils.MustMarshal(templateParam))),
}
res, _err := api.VoiceClient.SingleCallByTts(request)
@@ -150,7 +151,7 @@ func NotifyPickOrder(order *model.GoodsOrder) (err error) {
store.MarketManPhone = "18048531223"
}
if store.BrandIsOpen&model.BrandOpenVoice != 0 && balance >= model.BrandBalanceLimit {
if err = SendVoiceMsg(mobileList, map[string]interface{}{
if err = SendVoiceMsg(mobileList, globals.SMSPickOrderTemplate, map[string]interface{}{
"tel": store.MarketManPhone,
}); err == nil {
err = updateSth(order, store, model.BrandBillFeeTypeVoice)
@@ -300,3 +301,45 @@ func NotifyJxOrder(order *model.GoodsOrder, bill *model.Waybill) (err error) {
}, order)
return err
}
//品牌余额不足发送
func NotifyBrandBalance(brandID int) (err error) {
var (
db = dao.GetDB()
)
bindUsers, err := dao.GetBrandUser(db, brandID, "")
if err != nil {
return err
}
list := errlist.New()
count := 0
for _, v := range bindUsers {
if user, err := dao.GetUserByID(db, "user_id", v.UserID); err == nil && user != nil {
if err = SendVoiceMsg([]string{*user.Mobile}, globals.SMSVoiceBrandBalanceTemplate, map[string]interface{}{
"money": model.BrandBalanceLimit,
}); err != nil {
list.AddErr(err)
} else {
count++
}
if err = SendSMSMsg([]string{*user.Mobile}, globals.SMSSignName, globals.SMSBrandBalanceTemplate, map[string]interface{}{
"money": model.BrandBalanceLimit,
}, nil); err != nil {
list.AddErr(err)
} else {
count++
}
}
}
err = list.GetErrListAsOne()
if err == nil {
//每个品牌每天通知一次用redis吧
if mark := api.Cacher.Get("brandID" + utils.Int2Str(brandID)); mark == nil {
err = api.Cacher.Set("brandID"+utils.Int2Str(brandID), 1, utils.Str2Time(time.Now().AddDate(0, 0, 1).Format("2006-01-02")+"00:00:00").Sub(time.Now()))
}
if count > 0 {
partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, brandID, 5*count, model.BrandBillTypeExpend, model.BrandBillFeeTypeSys, "", "")
}
}
return err
}