Browse Source

模板消息

xingzai 2 years ago
parent
commit
dec5c2d44e
6 changed files with 317 additions and 44 deletions
  1. 1 1
      controllers/activity.go
  2. 0 43
      models/activity.go
  3. 56 0
      models/activity_special.go
  4. 24 0
      models/wx_template_msg.go
  5. 230 0
      services/activity_special.go
  6. 6 0
      services/task.go

+ 1 - 1
controllers/activity.go

@@ -3743,7 +3743,7 @@ func (this *ActivityCoAntroller) SpecialSignupAdd() {
 				}
 			}
 			//感兴趣人数到达10人时,模板消息发送给活动负责人
-			if len(actList) == 2 {
+			if len(actList) == 10 {
 				go services.SendWxMsgActivitySpecial10(activityInfo)
 			}
 

+ 0 - 43
models/activity.go

@@ -796,41 +796,6 @@ func GetActivityLabelSpecialListAll(condition string, pars []interface{}, startS
 	return
 }
 
-//专项调研活动列表
-type CygxActivitySpecialDetail struct {
-	ActivityId            int    `description:"活动ID "`
-	ActivityTypeName      string `description:"活动名称"`
-	SpecialType           int    `description:"调研形式、 1 线上 , 2 线下"`
-	City                  string `description:"调研城市"`
-	ChartPermissionName   string `description:"行业名称"`
-	ChartPermissionId     string `description:"行业Id"`
-	ResearchTheme         string `description:"调研主题"`
-	ActivityTimeText      string `description:"活动预期时间带文字"`
-	TripImgLink           string `description:"行程图片链接"`
-	IsSignup              int    `description:"是否感兴趣 1是 ,0 否"`
-	Label                 string `description:"主题标签"`
-	ImgUrl                string `description:"图片链接"`
-	ImgUrlText            string `description:"图片链接文字"`
-	IndustrialName        string `description:"产业名称"`
-	IndustrialSubjectName string `description:"标的名称(相关公司)"`
-	Scale                 string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
-	CustomerTypeIds       string `description:"活动可见的客户类型,多个ID用 , 隔开"`
-	IsTrip                int    `description:"是否报名 1是 ,0 否"`
-	TripNum               int    `description:"已报名人数"`
-	Days                  int    `description:"调研天数"`
-	Host                  string `description:"主持人"`
-	PersonInCharge        string `description:"纪要负责人"`
-	LimitPeopleNum        int    `description:"限制人数数量"`
-	TripImgLinkFix        string `description:"确定行程之后的图片链接"`
-	ActivityTimeTextByDay string `description:"活动预期时间带周日"`
-	ActivityTime          string `description:"活动预期时间"`
-	ActivityTimeEnd       string `description:"活动预期结束时间"`
-	ActiveState           int    `description:"活动进行状态 未开始:1、进行中2、已结束3"`
-	TripStatus            int    `description:"行程进行状态 1:预报名,2:确定行程"`
-	Explain               string `description:"说明"`
-	AdminId               int    `description:"管理员ID"`
-}
-
 type GetCygxActivitySpecialDetailListResp struct {
 	IsFollow        bool               `description:"是否关注新调研通知"`
 	IsBindingMobile bool               `description:"是否绑定了手机号"`
@@ -899,14 +864,6 @@ func GetCygxActivitySpecialDetail(ActivityId int) (item *CygxActivitySpecialDeta
 	return
 }
 
-//列表
-func GetActivityList() (items []*CygxActivityList, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT  *  FROM cygx_activity`
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
 func UpdateCygxActivityName(activityId int, Name string) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE cygx_activity SET activity_name_task = ? WHERE activity_id=?  `

+ 56 - 0
models/activity_special.go

@@ -5,6 +5,41 @@ import (
 	"github.com/beego/beego/v2/client/orm"
 )
 
+//专项调研活动列表
+type CygxActivitySpecialDetail struct {
+	ActivityId            int    `description:"活动ID "`
+	ActivityTypeName      string `description:"活动名称"`
+	SpecialType           int    `description:"调研形式、 1 线上 , 2 线下"`
+	City                  string `description:"调研城市"`
+	ChartPermissionName   string `description:"行业名称"`
+	ChartPermissionId     string `description:"行业Id"`
+	ResearchTheme         string `description:"调研主题"`
+	ActivityTimeText      string `description:"活动预期时间带文字"`
+	TripImgLink           string `description:"行程图片链接"`
+	IsSignup              int    `description:"是否感兴趣 1是 ,0 否"`
+	Label                 string `description:"主题标签"`
+	ImgUrl                string `description:"图片链接"`
+	ImgUrlText            string `description:"图片链接文字"`
+	IndustrialName        string `description:"产业名称"`
+	IndustrialSubjectName string `description:"标的名称(相关公司)"`
+	Scale                 string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
+	CustomerTypeIds       string `description:"活动可见的客户类型,多个ID用 , 隔开"`
+	IsTrip                int    `description:"是否报名 1是 ,0 否"`
+	TripNum               int    `description:"已报名人数"`
+	Days                  int    `description:"调研天数"`
+	Host                  string `description:"主持人"`
+	PersonInCharge        string `description:"纪要负责人"`
+	LimitPeopleNum        int    `description:"限制人数数量"`
+	TripImgLinkFix        string `description:"确定行程之后的图片链接"`
+	ActivityTimeTextByDay string `description:"活动预期时间带周日"`
+	ActivityTime          string `description:"活动预期时间"`
+	ActivityTimeEnd       string `description:"活动预期结束时间"`
+	ActiveState           int    `description:"活动进行状态 未开始:1、进行中2、已结束3"`
+	TripStatus            int    `description:"行程进行状态 1:预报名,2:确定行程"`
+	Explain               string `description:"说明"`
+	AdminId               int    `description:"管理员ID"`
+}
+
 //获取数量
 func GetActivitySpecialCount(condition string, pars []interface{}) (count int, err error) {
 	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_activity_special as art WHERE 1= 1  `
@@ -15,3 +50,24 @@ func GetActivitySpecialCount(condition string, pars []interface{}) (count int, e
 	err = o.Raw(sqlCount, pars).QueryRow(&count)
 	return
 }
+
+//主题列表
+func GetActivitySpecialListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivitySpecialDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT	*
+		FROM cygx_activity_special as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY art.last_updated_time DESC  LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+//修改发布状态
+func UpdateActivitySpecialPublishStatus(publishStatus, activityId int) (err error) {
+	sql := ` UPDATE cygx_activity_special SET  publish_status= ?  WHERE activity_id = ?`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, publishStatus, activityId).Exec()
+	return
+}

+ 24 - 0
models/wx_template_msg.go

@@ -44,3 +44,27 @@ func GetWxOpenIdByMobileList(mobile string) (items []*OpenIdList, err error) {
 	_, err = orm.NewOrm().Raw(sql).QueryRows(&items)
 	return
 }
+
+type AdminOpenIdList struct {
+	OpenId    string `description:"OpenId"`
+	UserId    int    `description:"UserId"`
+	Mobile    string `description:"手机号"`
+	CompanyId int    `description:"手机号"`
+}
+
+// GetAdminOpendidByCompany 通过用户公司ID获取对应销售的openid
+func GetAdminOpendidByCompany(condition string, pars []interface{}) (list []*AdminOpenIdList, err error) {
+	sql := `SELECT
+			cr.open_id,a.mobile,p.company_id,cr.union_id
+		FROM
+			company_product AS p
+			INNER JOIN admin AS a ON a.admin_id = p.seller_id 
+			INNER JOIN user_record  as c ON c.bind_account = a.mobile
+			INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
+		WHERE
+			1 = 1 
+			AND p.product_id = 2
+			AND create_platform = 4 ` + condition
+	_, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
+	return
+}

+ 230 - 0
services/activity_special.go

@@ -710,3 +710,233 @@ func SendWxMsgActivitySpecial10(activityInfo *models.CygxActivitySpecialDetail)
 	}
 	return
 }
+
+//SendWxMsgActivitySpecialTwoDays  活动开始前两天08:00,提醒报名客户 \提醒报名客户的对口销售
+func SendWxMsgActivitySpecialTwoDays(cont context.Context) (err error) {
+	var msg string
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
+			go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
+			utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
+		}
+	}()
+	twoDayTime := time.Now().AddDate(0, 0, 2)
+	startTime := twoDayTime.Format(utils.FormatDate) + " 00:00:00"
+	endTime := twoDayTime.Format(utils.FormatDate) + " 23:59:59"
+	var condition string
+	var pars []interface{}
+	condition = ` AND  days >0  AND activity_time BETWEEN ? AND  ? `
+	pars = append(pars, startTime, endTime)
+	listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
+	if e != nil {
+		err = errors.New("GetSellerByAdminId, Err: " + e.Error())
+		return
+	}
+	if len(listActivitySpecial) == 0 {
+		return
+	}
+
+	var activityIds []int
+
+	for _, v := range listActivitySpecial {
+		activityIds = append(activityIds, v.ActivityId)
+		condition = `  AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
+		pars = make([]interface{}, 0)
+		listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
+			return
+		}
+		if len(listSpecialTrip) == 0 {
+			return
+		}
+		var mobile string
+		var companyIds []int
+		for _, vT := range listSpecialTrip {
+			mobile += "'" + vT.Mobile + "',"
+			companyIds = append(companyIds, vT.CompanyId)
+		}
+		mobile = strings.TrimRight(mobile, ",")
+		openIdList, e := models.GetWxOpenIdByMobileList(mobile)
+		if e != nil {
+			err = errors.New("GetSellerByAdminId, Err: " + e.Error())
+			return
+		}
+		first := "【" + v.ResearchTheme + "】专项调研将在两天后进行,如不能参加,请及时取消报名"
+		keyword1 := v.ResearchTheme
+		keyword2 := "已报名"
+		keyword3 := v.ActivityTimeTextByDay
+		keyword4 := "线上"
+		if v.SpecialType == 2 {
+			keyword4 = v.City
+		}
+		remark := "点击查看活动详情"
+		SendWxMsgWithFrequency(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
+
+		//活动开始前两天08:00,提醒报名客户的对口销售
+		companyIdsLen := len(companyIds)
+		if companyIdsLen == 0 {
+			continue
+		} else {
+			pars = make([]interface{}, 0)
+			condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `)  GROUP BY  p.company_id  `
+			pars = append(pars, companyIds)
+
+			listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
+			if e != nil && e.Error() != utils.ErrNoRow() {
+				err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
+				return
+			}
+			if len(listSeller) == 0 {
+				continue
+			}
+			type SllerData struct {
+				Openid  string `description:"Openid"`
+				Keyword string `description:"Keyword "`
+			}
+			mapSller := make(map[string]string)
+			mapSllerOpenid := make(map[string]string)
+			for _, vS := range listSeller {
+				for _, vT := range listSpecialTrip {
+					if vT.CompanyId == vS.CompanyId {
+						mapSller[vS.Mobile] += "【" + vT.RealName + "--" + vT.CompanyName + "】"
+						mapSllerOpenid[vS.Mobile] = vS.OpenId
+					}
+				}
+			}
+			for k, vM := range mapSller {
+				first = "【" + v.ResearchTheme + "】专项调研将在两天后进行,请及时提醒您的报名客户"
+				keyword2 = vM
+				openIdList = make([]*models.OpenIdList, 0)
+				openIdList = append(openIdList, &models.OpenIdList{OpenId: mapSllerOpenid[k]})
+				SendWxMsgWithFrequency(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
+			}
+		}
+	}
+	return
+}
+
+//SendWxMsgActivitySpecialCancel  线下活动前4天08:00报名人数不足7人,线上活动前3天08:00报名人数不足10人,活动自动取消发布,并推送模板消息至报名客户及对口销售
+func SendWxMsgActivitySpecialCancel(cont context.Context) (err error) {
+	var msg string
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
+			go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
+			utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
+		}
+	}()
+	dayTime3 := time.Now().AddDate(0, 0, 3)
+	startTime := dayTime3.Format(utils.FormatDate) + " 00:00:00"
+	endTime := dayTime3.Format(utils.FormatDate) + " 23:59:59"
+
+	dayTime4 := time.Now().AddDate(0, 0, 4)
+	startTime4 := dayTime4.Format(utils.FormatDate) + " 00:00:00"
+	endTime4 := dayTime4.Format(utils.FormatDate) + " 23:59:59"
+	var condition string
+	var pars []interface{}
+	condition = ` AND days >0  AND activity_time BETWEEN ? AND  ? AND special_type= 1 `
+	pars = append(pars, startTime, endTime)
+
+	condition += ` OR ( days >0  AND activity_time BETWEEN ? AND  ? AND special_type= 2 ) `
+	pars = append(pars, startTime4, endTime4)
+
+	listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
+	if e != nil {
+		err = errors.New("GetSellerByAdminId, Err: " + e.Error())
+		return
+	}
+	if len(listActivitySpecial) == 0 {
+		return
+	}
+
+	var activityIds []int
+
+	for _, v := range listActivitySpecial {
+		activityIds = append(activityIds, v.ActivityId)
+		condition = ` AND is_cancel = 0  AND activity_id = ` + strconv.Itoa(v.ActivityId)
+		pars = make([]interface{}, 0)
+		listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
+			return
+		}
+		if v.SpecialType == 1 {
+			if len(listSpecialTrip) >= 10 {
+				continue
+			}
+		}
+		if v.SpecialType == 2 {
+			if len(listSpecialTrip) >= 7 {
+				continue
+			}
+		}
+		e = models.UpdateActivitySpecialPublishStatus(0, v.ActivityId)
+		if e != nil {
+			err = errors.New("UpdateActivitySpecialPublishStatus,自动取消专项调研日程失败 Err: " + e.Error() + strconv.Itoa(v.ActivityId))
+			return
+		}
+		if len(listSpecialTrip) < 0 {
+			return
+		}
+		var mobile string
+		var companyIds []int
+		for _, vT := range listSpecialTrip {
+			mobile += "'" + vT.Mobile + "',"
+			companyIds = append(companyIds, vT.CompanyId)
+		}
+		mobile = strings.TrimRight(mobile, ",")
+		openIdList, e := models.GetWxOpenIdByMobileList(mobile)
+		if e != nil {
+			err = errors.New("GetSellerByAdminId, Err: " + e.Error())
+			return
+		}
+		first := "【" + v.ResearchTheme + "】专项调研因专家安排变动,本次调研活动延期举办,具体时间另行通知"
+		keyword1 := v.ResearchTheme
+		keyword2 := "已取消"
+		keyword3 := ""
+		keyword4 := ""
+		remark := ""
+
+		openIdArr := make([]string, 0)
+		for _, vOpenid := range openIdList {
+			openIdArr = append(openIdArr, vOpenid.OpenId)
+		}
+		companyIdsLen := len(companyIds)
+		if len(companyIds) > 0 {
+			pars = make([]interface{}, 0)
+			condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `)  GROUP BY  p.company_id  `
+			pars = append(pars, companyIds)
+			listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
+			if e != nil && e.Error() != utils.ErrNoRow() {
+				err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
+				return
+			}
+			if len(listSeller) > 0 {
+				for _, vOpenid := range listSeller {
+					openIdArr = append(openIdArr, vOpenid.OpenId)
+				}
+			}
+		}
+		redirectUrl := ""
+		sendInfo := new(SendWxTemplate)
+		sendInfo.First = first
+		sendInfo.Keyword1 = keyword1
+		sendInfo.Keyword2 = keyword2
+		sendInfo.Keyword3 = keyword3
+		sendInfo.Keyword4 = keyword4
+		sendInfo.Remark = remark
+		sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
+		sendInfo.RedirectUrl = redirectUrl
+		sendInfo.RedirectTarget = 3
+		sendInfo.Resource = strconv.Itoa(v.ActivityId)
+		sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
+		sendInfo.OpenIdArr = openIdArr
+		fmt.Println(sendInfo)
+		err = PublicSendTemplateMsg(sendInfo)
+	}
+	return
+}

+ 6 - 0
services/task.go

@@ -95,6 +95,12 @@ func Task() {
 
 		addctivitySignupDetail := task.NewTask("addctivitySignupDetail", "0 0 23 * * *", AddctivitySignupDetail) // 获取当天已结束的活动的报名信息。添加到到会详情
 		task.AddTask("addctivitySignupDetail", addctivitySignupDetail)
+
+		sendWxMsgActivitySpecialTwoDays := task.NewTask("sendWxMsgActivitySpecialTwoDays", "0 0 8 * * *", SendWxMsgActivitySpecialTwoDays)
+		task.AddTask("sendWxMsgActivitySpecialTwoDays", sendWxMsgActivitySpecialTwoDays) //活动开始前两天08:00,提醒报名客户 \提醒报名客户的对口销售
+
+		sendWxMsgActivitySpecialCancel := task.NewTask("sendWxMsgActivitySpecialCancel", "0 0 8 * * *", SendWxMsgActivitySpecialCancel)
+		task.AddTask("sendWxMsgActivitySpecialCancel", sendWxMsgActivitySpecialCancel) // 线下活动前4天08:00报名人数不足7人,线上活动前3天08:00报名人数不足10人,活动自动取消发布,并推送模板消息至报名客户及对口销售
 	}
 	if utils.RunMode != "release" {
 		getArticleListByApi := task.NewTask("getArticleListByApi", "0 */60 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章