Răsfoiți Sursa

Merge branch 'feature/migrate_wechat_msg' into debug

xiexiaoyuan 2 ani în urmă
părinte
comite
158ad532aa

+ 1 - 0
models/admin.go

@@ -15,6 +15,7 @@ type Admin struct {
 	GroupId      int    `description:"分组id"`
 	Authority    int    `description:"管理权限,0:无,1:部门负责人,2:小组负责人"`
 	Position     string `description:"职位"`
+	OpenId       string `description:"弘则部门公众号的openid"`
 }
 
 func GetAdminByAdminId(adminId int) (item *Admin, err error) {

+ 12 - 0
models/company_product.go

@@ -232,6 +232,18 @@ func GetSellers() (items []*Sellers, err error) {
 	return
 }
 
+func GetSellersOpenId() (items []*Sellers, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT a.real_name,a.email,a.open_id,a.mobile,a.role_type_code,a.admin_id
+           FROM admin AS a
+			WHERE role_type_code IN('ficc_seller','ficc_group','ficc_team','rai_seller','rai_group')
+			and (
+				(a.email != "") or ( a.open_id<>'')
+			)`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
 func GetRemindCompany(sellerId int, endDate string) (items []*CompanyProduct, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT b.end_date,b.contract_end_date,a.company_name,b.status,b.seller_id,b.seller_name FROM

+ 1 - 1
services/company_product.go

@@ -257,7 +257,7 @@ func CompanyRemind(cont context.Context) (err error) {
 		}
 	}()
 	//获取销售
-	sellers, err := models.GetSellers()
+	sellers, err := models.GetSellersOpenId()
 	for k, v := range sellers {
 		fmt.Println(k, v.AdminId, v.Mobile)
 		CompanyRemind30Day(v)

+ 53 - 143
services/data_entry.go

@@ -67,60 +67,30 @@ func FrequencyByDay() (err error) {
 		if noticeSecondTotal >= nowBeforSecond && noticeSecondTotal <= nowAfterSecond {
 			//获取用户信息
 			var openId string
-			isAdmin := true
 			admin, err := models.GetAdminByAdminId(v.UserId)
 			if err != nil {
 				if err.Error() == utils.ErrNoRow() {
-					isAdmin = false
-				} else {
+					err = errors.New("账号不存在")
 					return err
 				}
+				return err
 			}
-			if admin == nil {
-				isAdmin = false
-			}
-			if isAdmin {
-				if admin.Mobile == "" {
+			openId = admin.OpenId
+			//发送消息
+			if openId != "" {
+				openIdList := make([]*models.OpenIdList, 0)
+				openIdItem := new(models.OpenIdList)
+				openIdItem.OpenId = openId
+				openIdList = append(openIdList, openIdItem)
 
-				} else {
-					wxUser, err := models.GetWxUserByMobile(admin.Mobile)
-					if err != nil {
-						return err
-					}
-					if wxUser == nil {
-						err = errors.New("用户信息不存在:mobile:" + admin.Mobile)
-						return err
-					}
-					openId = wxUser.OpenId
-				}
-			} else {
-				wxUser, err := models.GetWxUserByUserId(v.UserId)
+				first := "数据录入提醒"
+				keyword1 := v.SecName
+				keyword2 := "每日 " + v.NoticeTime
+				remark := v.SecName + "该更新了"
+				err = SendWxMsgWithFrequency(first, keyword1, keyword2, remark, openIdList)
 				if err != nil {
 					return err
 				}
-				if wxUser == nil {
-					err = errors.New("用户信息不存在:userId:" + strconv.Itoa(v.UserId))
-					return err
-				}
-				openId = wxUser.OpenId
-			}
-			//发送消息
-			if openId == "" {
-				err = errors.New("openId is empty")
-				return err
-			}
-			openIdList := make([]*models.OpenIdList, 0)
-			openIdItem := new(models.OpenIdList)
-			openIdItem.OpenId = openId
-			openIdList = append(openIdList, openIdItem)
-
-			first := "数据录入提醒"
-			keyword1 := v.SecName
-			keyword2 := "每日 " + v.NoticeTime
-			remark := v.SecName + "该更新了"
-			err = SendWxMsgWithFrequency(first, keyword1, keyword2, remark, openIdList)
-			if err != nil {
-				return err
 			}
 		}
 	}
@@ -224,72 +194,42 @@ func FrequencyByWeek() (err error) {
 		if noticeSecondTotal >= nowBeforSecond && noticeSecondTotal <= nowAfterSecond {
 			//获取用户信息
 			var openId string
-			isAdmin := true
 			admin, err := models.GetAdminByAdminId(v.UserId)
 			if err != nil {
 				if err.Error() == utils.ErrNoRow() {
-					isAdmin = false
-				} else {
-					return err
-				}
-			}
-			if admin == nil {
-				isAdmin = false
-			}
-			if isAdmin {
-				if admin.Mobile == "" {
-
-				} else {
-					wxUser, err := models.GetWxUserByMobile(admin.Mobile)
-					if err != nil {
-						return err
-					}
-					if wxUser == nil {
-						err = errors.New("用户信息不存在:mobile:" + admin.Mobile)
-						return err
-					}
-					openId = wxUser.OpenId
-				}
-			} else {
-				wxUser, err := models.GetWxUserByUserId(v.UserId)
-				if err != nil {
-					return err
-				}
-				if wxUser == nil {
-					err = errors.New("用户信息不存在:userId:" + strconv.Itoa(v.UserId))
+					err = errors.New("账号不存在")
 					return err
 				}
-				openId = wxUser.OpenId
-			}
-			//发送消息
-			if openId == "" {
-				err = errors.New("openId is empty")
 				return err
 			}
-			openIdList := make([]*models.OpenIdList, 0)
-			openIdItem := new(models.OpenIdList)
-			openIdItem.OpenId = openId
-			openIdList = append(openIdList, openIdItem)
+			openId = admin.OpenId
+			//发送消息
+			if openId != "" {
+				openIdList := make([]*models.OpenIdList, 0)
+				openIdItem := new(models.OpenIdList)
+				openIdItem.OpenId = openId
+				openIdList = append(openIdList, openIdItem)
 
-			first := "数据录入提醒"
-			keyword1 := v.SecName
-			keyword2 := "每周 " + v.NoticeTime
-			remark := v.SecName + "该更新了"
+				first := "数据录入提醒"
+				keyword1 := v.SecName
+				keyword2 := "每周 " + v.NoticeTime
+				remark := v.SecName + "该更新了"
 
-			err = SendWxMsgWithFrequency(first, keyword1, keyword2, remark, openIdList)
-			if err != nil {
-				return err
-			}
-			//发送成功,记录发送日志
-			{
-				sendRecord := new(models.EdbinfoSendMsgRecord)
-				sendRecord.UserId = v.UserId
-				sendRecord.TradeCode = v.TradeCode
-				sendRecord.CreateTime = time.Now()
-				err = models.AddEdbinfoSendMsgRecord(sendRecord)
+				err = SendWxMsgWithFrequency(first, keyword1, keyword2, remark, openIdList)
 				if err != nil {
 					return err
 				}
+				//发送成功,记录发送日志
+				{
+					sendRecord := new(models.EdbinfoSendMsgRecord)
+					sendRecord.UserId = v.UserId
+					sendRecord.TradeCode = v.TradeCode
+					sendRecord.CreateTime = time.Now()
+					err = models.AddEdbinfoSendMsgRecord(sendRecord)
+					if err != nil {
+						return err
+					}
+				}
 			}
 		} else {
 			utils.FileLog.Info("%s", v.TradeCode+":不在推送消息时间范围内")
@@ -382,61 +322,31 @@ func FrequencyByMonth() (err error) {
 		if noticeSecondTotal >= nowBeforSecond && noticeSecondTotal <= nowAfterSecond {
 			//获取用户信息
 			var openId string
-			isAdmin := true
 			admin, err := models.GetAdminByAdminId(v.UserId)
 			if err != nil {
 				if err.Error() == utils.ErrNoRow() {
-					isAdmin = false
-				} else {
+					err = errors.New("账号不存在")
 					return err
 				}
+				return err
 			}
-			if admin == nil {
-				isAdmin = false
-			}
-			if isAdmin {
-				if admin.Mobile == "" {
+			openId = admin.OpenId
+			//发送消息
+			if openId != "" {
+				openIdList := make([]*models.OpenIdList, 0)
+				openIdItem := new(models.OpenIdList)
+				openIdItem.OpenId = openId
+				openIdList = append(openIdList, openIdItem)
 
-				} else {
-					wxUser, err := models.GetWxUserByMobile(admin.Mobile)
-					if err != nil {
-						return err
-					}
-					if wxUser == nil {
-						err = errors.New("用户信息不存在:mobile:" + admin.Mobile)
-						return err
-					}
-					openId = wxUser.OpenId
-				}
-			} else {
-				wxUser, err := models.GetWxUserByUserId(v.UserId)
+				first := "数据录入提醒"
+				keyword1 := v.SecName
+				keyword2 := "每月 " + v.NoticeTime
+				remark := v.SecName + "该更新了"
+
+				err = SendWxMsgWithFrequency(first, keyword1, keyword2, remark, openIdList)
 				if err != nil {
 					return err
 				}
-				if wxUser == nil {
-					err = errors.New("用户信息不存在:userId:" + strconv.Itoa(v.UserId))
-					return err
-				}
-				openId = wxUser.OpenId
-			}
-			//发送消息
-			if openId == "" {
-				err = errors.New("openId is empty")
-				return err
-			}
-			openIdList := make([]*models.OpenIdList, 0)
-			openIdItem := new(models.OpenIdList)
-			openIdItem.OpenId = openId
-			openIdList = append(openIdList, openIdItem)
-
-			first := "数据录入提醒"
-			keyword1 := v.SecName
-			keyword2 := "每月 " + v.NoticeTime
-			remark := v.SecName + "该更新了"
-
-			err = SendWxMsgWithFrequency(first, keyword1, keyword2, remark, openIdList)
-			if err != nil {
-				return err
 			}
 		}
 	}

+ 41 - 4
services/wx_template_msg.go

@@ -24,7 +24,7 @@ func SendWxMsgWithFrequency(first, keyword1, keyword2, remark string, openIdList
 		fmt.Println("line 21", err, msg)
 	}()
 	utils.FileLog.Info("services SendMsg")
-	accessToken, err := models.GetWxAccessToken()
+	/*accessToken, err := models.GetWxAccessToken()
 	if err != nil {
 		msg = "GetWxAccessToken Err:" + err.Error()
 		return
@@ -50,7 +50,24 @@ func SendWxMsgWithFrequency(first, keyword1, keyword2, remark string, openIdList
 	sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
 	sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
 	sendMap["data"] = sendData
-	WxSendTemplateMsg(sendUrl, sendMap, openIdList)
+	WxSendTemplateMsg(sendUrl, sendMap, openIdList)*/
+	wxAppPath := ""
+	openIdArr := make([]string, len(openIdList))
+	for i, v := range openIdList {
+		openIdArr[i] = v.OpenId
+	}
+	sendInfo := new(SendWxTemplate)
+	sendInfo.WxAppId = utils.AdminWxAppId
+	sendInfo.First = first
+	sendInfo.Keyword1 = keyword1
+	sendInfo.Keyword2 = keyword2
+	sendInfo.RedirectUrl = wxAppPath
+	sendInfo.RedirectTarget = 0
+	sendInfo.TemplateId = utils.TemplateId
+	sendInfo.Resource = wxAppPath
+	sendInfo.OpenIdArr = openIdArr
+	sendInfo.Remark = remark
+	err = SendTemplateMsgV2(sendInfo)
 	return
 }
 
@@ -100,7 +117,7 @@ func SendWxMsgWithCompanyRemind(first, keyword1, keyword2, remark string, openId
 		}
 	}()
 	utils.FileLog.Info("%s", "services SendMsg")
-	accessToken, err := models.GetWxAccessToken()
+	/*accessToken, err := models.GetWxAccessToken()
 	if err != nil {
 		msg = "GetWxAccessToken Err:" + err.Error()
 		return
@@ -120,7 +137,24 @@ func SendWxMsgWithCompanyRemind(first, keyword1, keyword2, remark string, openId
 	sendData["date"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
 	sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
 	sendMap["data"] = sendData
-	WxSendTemplateMsg(sendUrl, sendMap, openIdList)
+	WxSendTemplateMsg(sendUrl, sendMap, openIdList)*/
+	wxAppPath := ""
+	openIdArr := make([]string, len(openIdList))
+	for i, v := range openIdList {
+		openIdArr[i] = v.OpenId
+	}
+	sendInfo := new(SendWxTemplate)
+	sendInfo.WxAppId = utils.AdminWxAppId
+	sendInfo.First = first
+	sendInfo.Productname = keyword1
+	sendInfo.Date = keyword2
+	sendInfo.RedirectUrl = wxAppPath
+	sendInfo.RedirectTarget = 0
+	sendInfo.TemplateId = utils.RemindTemplateId
+	sendInfo.Resource = wxAppPath
+	sendInfo.OpenIdArr = openIdArr
+	sendInfo.Remark = remark
+	err = SendTemplateMsgV2(sendInfo)
 	return
 }
 
@@ -165,11 +199,14 @@ func SendWxMsgWithActivityAppointmentRemind(first, keyword1, keyword2, keyword3,
 }
 
 type SendWxTemplate struct {
+	WxAppId        string   `description:"公众号appId"`
 	First          string   `description:"模板消息first字段"`
 	Keyword1       string   `description:"模板消息keyword1字段"`
 	Keyword2       string   `description:"模板消息keyword2字段"`
 	Keyword3       string   `description:"模板消息keyword3字段"`
 	Keyword4       string   `description:"模板消息keyword4字段"`
+	Productname    string   `description:"模板消息productname字段"`
+	Date           string   `description:"模板消息date字段"`
 	Remark         string   `description:"模板消息remark字段"`
 	TemplateId     string   `description:"模板id"`
 	RedirectUrl    string   `description:"跳转地址"`

+ 11 - 4
utils/config.go

@@ -31,6 +31,9 @@ var (
 
 	WxYbAppId string //微信研报小程序
 
+	//内部员工公众号(弘则部门)
+	AdminWxAppId                    string
+	AdminWxAppSecret                string
 )
 
 //oss配置
@@ -115,13 +118,17 @@ ZwIDAQAB
 
 	WxYbAppId = "wxb059c872d79b9967" //弘则研报小程序
 
+	//内部员工公众号(弘则部门)
+	AdminWxAppId = "wx1392111da5426e9e"
+	AdminWxAppSecret = "30eceb7cf29bf2f046031155ab55d7b4"
+
 	if RunMode == "release" {
 		CompanyId = 16
 		RealName = "超级管理员"
 		WxAppId = "wx4a844c734d8c8e56"
 		WxAppSecret = "26c586e7ccb3c575433f0f37797b3eeb"
-		TemplateId = "P0klzaZjEI2UYth-z-WnmtOQgyxcF8klPoA_MlsA8Eo"
-		RemindTemplateId = "PaHpQjVffrvmeW8wiOUcqlEhnD1LXyU9FnPVF-Jg9wM"
+		TemplateId = "DGvLwidav-OZc07klLv5mxwxO63qHdWS5Cj-rTDvTQo"
+		RemindTemplateId = "rCvkgRatnK_3N9pnQEErUyjFkyVpyAGuYtv3HwY82K4"
 		//同花顺正式地址
 		THS_SendUrl = `https://board.10jqka.com.cn/gateway/ps/syncNews`
 		THS_SyncWxGroupUrl = `https://board.10jqka.com.cn/gateway/ps/syncWechatGroupInfo`
@@ -140,8 +147,8 @@ ZwIDAQAB
 		AdminId = 11
 		WxAppId = "wx9b5d7291e581233a"
 		WxAppSecret = "f4d52e34021eee262dce9682b31f8861"
-		TemplateId = "pDk4o924gSZWj80ZdNnHodnLMIXjPSlKZU0ciQMOhec"
-		RemindTemplateId = "9JYV6sHMJlu2EHRBIj_8ift6wkrrTb9_UO-M_-YXKBw"
+		TemplateId = "DGvLwidav-OZc07klLv5mxwxO63qHdWS5Cj-rTDvTQo"
+		RemindTemplateId = "rCvkgRatnK_3N9pnQEErUyjFkyVpyAGuYtv3HwY82K4"
 		AppointmentRemindTemplateId = `Y59n_AHg-RLCKaz293geW76KDHpGL1qOnE7eF_lxelY` //活动预约通知模板id
 
 		//同花顺测试地址