123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_clpt/models"
- "hongze/hongze_clpt/utils"
- "strconv"
- "strings"
- "time"
- )
- // 约访专家的请求
- func AddArticleApplyAppointmentExpert(user *models.WxUserItem, articleId int) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("约访专家的请求失败"+err.Error(), 2)
- }
- }()
- item := new(models.CygxArticleApplyAppointmentExpert)
- item.UserId = user.UserId
- item.ArticleId = articleId
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.RegisterPlatform = utils.REGISTER_PLATFORM
- sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return
- }
- item.RealName = user.RealName
- if sellerItem != nil {
- item.SellerName = sellerItem.RealName
- }
- _, e := models.AddCygxArticleApplyAppointmentExpert(item)
- if e != nil {
- err = errors.New("AddCygxArticleApplyAppointmentExpert, Err: " + e.Error())
- return
- }
- return
- }
- // 用户约访专家的请求,向对应销售发送模版消息
- func SendArticleApplyAppointmentExpertTemplateMsg(user *models.WxUserItem, articleId int) (err error) {
- var msg string
- msg = fmt.Sprint(user, articleId)
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("活动带问提醒发送模版消息失败"+msg, 2)
- }
- }()
- //文章详情
- detailArticle, e := models.GetArticleDetailById(articleId)
- if e != nil {
- err = errors.New("GetArticleDetailById, Err: " + e.Error())
- return
- }
- var mobiles []string
- //获取权益销售
- sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if e != nil {
- err = errors.New("GetAdminByRoleName, Err: " + e.Error())
- return
- }
- //内容组全员手机号
- configCode := utils.TPL_MSG_NEI_RONG_ZU
- cnf, e := models.GetConfigByCode(configCode)
- if e != nil {
- err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
- return
- }
- //汪洋手机号
- cnfWangYang, e := models.GetConfigByCode(utils.TPL_MSG_WANG_YANG)
- if e != nil {
- err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
- return
- }
- mobiles = append(mobiles, sellerItem.Mobile)
- mobiles = append(mobiles, cnfWangYang.ConfigValue)
- listMobile := strings.Split(cnf.ConfigValue, ",")
- for _, v := range listMobile {
- mobiles = append(mobiles, v)
- }
- openIdList, e := models.GetWxOpenIdByMobileSliceList(mobiles)
- if e != nil {
- err = errors.New("GetWxOpenIdByMobileSliceList, Err: " + e.Error() + configCode)
- return
- }
- if len(openIdList) == 0 {
- return
- }
- if len(openIdList) == 0 {
- return
- }
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- var keyword1 string
- var keyword2 string
- var keyword3 string
- var keyword4 string
- keyword1 = fmt.Sprint(user.RealName, "--", user.CompanyName, "(", sellerItem.RealName, ")")
- if user.Mobile == "" {
- user.Mobile = user.Email
- }
- keyword2 = user.Mobile
- keyword3 = time.Now().Format(utils.FormatDateTime)
- keyword4 = fmt.Sprint("约访专家(", detailArticle.Title, ")")
- var redirectUrl string
- redirectUrl = utils.WX_MSG_PATH_ARTICLE_DETAIL + strconv.Itoa(articleId)
- sendInfo := new(SendWxTemplate)
- sendInfo.Keyword1 = keyword1
- sendInfo.Keyword2 = keyword2
- sendInfo.Keyword3 = keyword3
- sendInfo.Keyword4 = keyword4
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
- sendInfo.TemplateId = utils.WxMsgTemplateIdApplyXzs
- sendInfo.RedirectUrl = redirectUrl
- sendInfo.RedirectTarget = 3
- sendInfo.Resource = strconv.Itoa(articleId)
- sendInfo.OpenIdArr = openIdArr
- err = PublicSendTemplateMsg(sendInfo)
- return
- }
- // 获取用户数是否约访专家的请求
- func GetIsApplyAppointmentExpert(user *models.WxUserItem, articleId int) (isApplyAppointmentExpert bool) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("获取用户数是否约访专家的请求失败"+err.Error(), 2)
- }
- }()
- var condition string
- var pars []interface{}
- condition += ` AND article_id =? AND user_id = ? `
- pars = append(pars, articleId, user.UserId)
- total, e := models.GetCygxArticleApplyAppointmentExpertCount(condition, pars)
- if e != nil {
- err = errors.New("GetCygxArticleApplyAppointmentExpertCount, Err: " + e.Error())
- return
- }
- fmt.Println(total)
- if total > 0 {
- isApplyAppointmentExpert = true
- }
- return
- }
|