package services import ( "errors" "fmt" "hongze/hongze_mfyx/models" "hongze/hongze_mfyx/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 }