Эх сурвалжийг харах

Merge branch 'cygx_9.10' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 2 жил өмнө
parent
commit
9307190470

+ 4 - 1
controllers/activity.go

@@ -873,7 +873,10 @@ func (this *ActivityCoAntroller) SignupAdd() {
 		resp.SellerMobile = sellerMobile
 
 	}
-
+	//公司线下调研活动客户报名后给建会人,所属销售推送模板信息
+	if signupStatus == "Success" {
+		go services.SendResearchActivitiesTemplateMsg(user, activityInfo)
+	}
 	if signupType == 1 && user.IsMsgOutboundMobile == 0 {
 		resp.GoOutboundMobile = true
 		if user.Mobile != "" || user.OutboundMobile != "" {

+ 45 - 0
models/admin.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"time"
 )
 
 type AdminMobileResp struct {
@@ -15,3 +16,47 @@ func GetAdminByRole() (items []*AdminMobileResp, err error) {
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+type Admin struct {
+	AdminId                   int    `orm:"column(admin_id);pk" description:"系统用户id"`
+	AdminName                 string `description:"系统用户名称"`
+	AdminAvatar               string `description:"用户头像"`
+	RealName                  string `description:"系统用户姓名"`
+	Password                  string `json:"-"`
+	LastUpdatedPasswordTime   string `json:"-"`
+	Enabled                   int
+	Email                     string `description:"系统用户邮箱"`
+	LastLoginTime             string
+	CreatedTime               time.Time
+	LastUpdatedTime           string
+	Role                      string    `description:"系统用户角色"`
+	Mobile                    string    `description:"手机号"`
+	RoleType                  int       `description:"角色类型:1需要录入指标,0:不需要"`
+	RoleId                    int       `description:"角色ID"`
+	RoleName                  string    `description:"角色名称"`
+	RoleTypeCode              string    `description:"角色类型编码"`
+	DepartmentId              int       `description:"部门id"`
+	DepartmentName            string    `description:"部门名称"`
+	GroupId                   int       `description:"分组id"`
+	GroupName                 string    `description:"分组名称"`
+	Authority                 int       `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"`
+	Position                  string    `description:"职位"`
+	DisableTime               time.Time `description:"禁用时间"`
+	ChartPermission           int8      `description:"图表权限id"`
+	OpenId                    string    `description:"弘则部门公众号的openid"`
+	UnionId                   string    `description:"微信公众平台唯一标识"`
+	EdbPermission             int8      `description:"指标库操作权限,0:只能操作 自己的,1:所有指标可操作"`
+	MysteelChemicalPermission int8      `description:"钢联化工指标操作权限,0:只能操作 自己的,1:所有指标可操作"`
+	PredictEdbPermission      int8      `description:"预测指标库操作权限,0:只能操作 自己的,1:所有预测指标可操作"`
+	Province                  string    `description:"省"`
+	ProvinceCode              string    `description:"省编码"`
+	City                      string    `description:"市"`
+	CityCode                  string    `description:"市编码"`
+}
+
+func GetSysAdminById(adminId int) (item *Admin, err error) {
+	sql := `SELECT * FROM admin WHERE admin_id=? `
+	o := orm.NewOrm()
+	err = o.Raw(sql, adminId).QueryRow(&item)
+	return
+}

+ 14 - 9
models/wx_template_msg.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_cygx/utils"
 )
 
 type SendTemplateResponse struct {
@@ -27,15 +28,6 @@ func GetOpenIdList() (items []*OpenIdList, err error) {
 	return
 }
 
-func GetWxOpenIdList() (items []*OpenIdList, err error) {
-	sql := `SELECT open_id FROM wx_user AS wu 
-          INNER JOIN company AS c ON c.company_id = wu.company_id 
-          WHERE open_id=? `
-	openId := "oW3Gts7V3hj-sTAE1VDi0MhGlee8"
-	_, err = orm.NewOrm().Raw(sql, openId).QueryRows(&items)
-	return
-}
-
 func GetWxOpenIdByMobileList(mobile string) (items []*OpenIdList, err error) {
 	//sql := `SELECT * FROM user_record WHERE bind_account IN (` + utils.WxMsgTemplateIdAskMsgMobile + `) AND create_platform = 1`
 	sql := `SELECT cr.*,user_id FROM user_record  as c
@@ -68,3 +60,16 @@ func GetAdminOpendidByCompany(condition string, pars []interface{}) (list []*Adm
 	_, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
 	return
 }
+
+func GetWxOpenIdByMobileSliceList(mobiles []string) (items []*OpenIdList, err error) {
+	itemsLen := len(mobiles)
+	if itemsLen == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := `SELECT cr.*,user_id FROM user_record  as c
+			INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
+			WHERE bind_account IN (` + utils.GetOrmInReplace(itemsLen) + `) AND create_platform = 4`
+	_, err = o.Raw(sql, mobiles).QueryRows(&items)
+	return
+}

+ 85 - 0
services/activity_wx_template_msg.go

@@ -0,0 +1,85 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"strconv"
+	"time"
+)
+
+// SendResearchActivitiesTemplateMsg 线下调研活动报名给所属销售跟建会人员推送
+func SendResearchActivitiesTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
+	//如果不是公司线下调研就返回
+	if activityDetail.ActivityTypeId != 4 {
+		return
+	}
+	defer func() {
+		if err != nil {
+			go utils.SendEmail("线下调研活动报名给所属销售跟建会人员推送失败Err"+time.Now().Format("2006-01-02 15:04:05"), ";Err:"+err.Error(), utils.EmailSendToUsers)
+			go utils.SendAlarmMsg(fmt.Sprint("线下调研活动报名给所属销售跟建会人员推送失败Err:", err.Error(), "活动ID:", activityDetail.ActivityId, "手机号:", user.Mobile), 2)
+		}
+	}()
+	var mobiles []string
+	//获取销售信息
+	sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+	if sellerItem != nil {
+		mobiles = append(mobiles, sellerItem.Mobile)
+	}
+	//获取建会人员信息
+	admin, err := models.GetSysAdminById(activityDetail.AdminId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+	if admin != nil {
+		mobiles = append(mobiles, admin.Mobile)
+	}
+
+	var first string
+	var keyword1 string
+	var keyword2 string
+	var keyword3 string
+	var keyword4 string
+	var remark string
+	var redirectUrl string
+
+	first = "【" + activityDetail.ActivityName + "】有客户报名"
+	keyword1 = user.RealName + "——" + user.CompanyName + "(所属销售:" + sellerItem.RealName + ")"
+	keyword2 = user.Mobile
+	keyword3 = time.Now().Format(utils.FormatDateTime)
+	keyword4 = activityDetail.ActivityName
+	remark = "点击查看报告详情"
+
+	openIdList, e := models.GetWxOpenIdByMobileSliceList(mobiles)
+	if e != nil {
+		err = errors.New("GetWxOpenIdByMobileList, Err: " + e.Error())
+		return
+	}
+	openIdArr := make([]string, 0)
+	for _, v := range openIdList {
+		openIdArr = append(openIdArr, v.OpenId)
+	}
+	redirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId)
+	sendInfo := new(SendWxTemplate)
+	sendInfo.First = first
+	sendInfo.Keyword1 = keyword1
+	sendInfo.Keyword2 = keyword2
+	sendInfo.Keyword3 = keyword3
+	sendInfo.Keyword4 = keyword4
+	sendInfo.Remark = remark
+	sendInfo.TemplateId = utils.WxMsgTemplateIdApplyXzs
+	sendInfo.RedirectUrl = redirectUrl
+	sendInfo.RedirectTarget = 3
+	sendInfo.Resource = strconv.Itoa(activityDetail.ArticleId)
+	sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_COMMENT
+	sendInfo.OpenIdArr = openIdArr
+	err = PublicSendTemplateMsg(sendInfo)
+	if err != nil {
+		return
+	}
+	return
+}

+ 12 - 25
services/wechat_send_msg.go

@@ -13,7 +13,7 @@ import (
 	"time"
 )
 
-//访谈申请
+// 访谈申请
 func SendInterviewApplyTemplateMsg(realName, companyName, mobile, articleTitle string, itemOpenid *models.OpenIdList) (err error) {
 	var msg string
 	defer func() {
@@ -60,7 +60,7 @@ func SendInterviewApplyTemplateMsg(realName, companyName, mobile, articleTitle s
 	return
 }
 
-//访谈申请取消
+// 访谈申请取消
 func SendInterviewApplyCancelTemplateMsg(realName, companyName, mobile, articleTitle string, itemOpenid *models.OpenIdList) (err error) {
 	var msg string
 	defer func() {
@@ -102,7 +102,7 @@ func SendInterviewApplyCancelTemplateMsg(realName, companyName, mobile, articleT
 	return
 }
 
-//权限申请
+// 权限申请
 func SendPermissionApplyTemplateMsg(realName, companyName, mobile, applyMethod string, itemOpenid *models.OpenIdList) (err error) {
 	var msg string
 	defer func() {
@@ -116,28 +116,15 @@ func SendPermissionApplyTemplateMsg(realName, companyName, mobile, applyMethod s
 	}()
 
 	var accessToken string
-	if utils.RunMode == "release" {
-		accessToken, err = models.GetWxAccessTokenByXzs()
-		if err != nil {
-			msg = "GetWxAccessToken Err:" + err.Error()
-			return
-		}
-		if accessToken == "" {
-			msg = "accessToken is empty"
-			return
-		}
-	} else {
-		accessToken, err = models.GetWxAccessToken()
-		if err != nil {
-			msg = "GetWxAccessToken Err:" + err.Error()
-			return
-		}
-		if accessToken == "" {
-			msg = "accessToken is empty"
-			return
-		}
+	accessToken, err = models.GetWxAccessTokenByXzs()
+	if err != nil {
+		msg = "GetWxAccessToken Err:" + err.Error()
+		return
+	}
+	if accessToken == "" {
+		msg = "accessToken is empty"
+		return
 	}
-
 	sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
 
 	sendMap := make(map[string]interface{})
@@ -244,7 +231,7 @@ type SendWxTemplate struct {
 	OpenIdArr      []string `description:"消息接收者openid"`
 }
 
-//推送模板消息
+// 推送模板消息
 func PublicSendTemplateMsg(sendInfo *SendWxTemplate) (err error) {
 	postData, err := json.Marshal(sendInfo)
 	if err != nil {