xingzai 2 vuotta sitten
vanhempi
commit
6e37054697

+ 23 - 1
controllers/activity_special.go

@@ -245,6 +245,23 @@ func (this *ActivitySpecialController) SpecialTripAdd() {
 				br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
 				return
 			}
+			//流水记录表
+			itemBill := new(models.CygxActivitySpecialTripBill)
+			itemBill.UserId = user.UserId
+			itemBill.ActivityId = activityInfo.ActivityId
+			itemBill.CreateTime = time.Now()
+			itemBill.Mobile = user.Mobile
+			itemBill.Email = user.Email
+			itemBill.CompanyId = user.CompanyId
+			itemBill.CompanyName = user.CompanyName
+			itemBill.RealName = user.RealName
+			itemBill.Source = 1
+			itemBill.DoType = 1
+			itemBill.BillDetailed = -1 // 流水减一
+			itemBill.RegisterPlatform = 1
+			itemBill.ChartPermissionId = activityInfo.ChartPermissionId
+
+			go services.ActivitySpecialUserRmind(user, activityId, 2)
 			//判断是删除还是添加
 			if total == 0 {
 				//获取销售信息
@@ -255,7 +272,6 @@ func (this *ActivitySpecialController) SpecialTripAdd() {
 					return
 				}
 				item := new(models.CygxActivitySpecialTrip)
-				item.RegisterPlatform = utils.REGISTER_PLATFORM
 				item.UserId = uid
 				item.RealName = user.RealName
 				item.ActivityId = activityId
@@ -287,7 +303,13 @@ func (this *ActivitySpecialController) SpecialTripAdd() {
 					br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
 					return
 				}
+				resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
+				//48小时之内的取消也扣除一次参会记录
+				if time.Now().Add(+time.Hour * 48).After(resultTime) {
+					itemBill.BillDetailed = 0 //48小时之内,取消报名之后二次报名,不扣除流水记录
+				}
 			}
+			go models.AddCygxActivitySpecialTripBill(itemBill)
 		}
 	} else {
 		hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)

+ 9 - 9
models/activity_special.go

@@ -6,14 +6,14 @@ import (
 	"github.com/rdlucklib/rdluck_tools/paging"
 )
 
-//专项调研活动列表
+// 专项调研活动列表
 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"`
+	ChartPermissionId     int    `description:"行业Id"`
 	ResearchTheme         string `description:"调研主题"`
 	ActivityTimeText      string `description:"活动预期时间带文字"`
 	TripImgLink           string `description:"行程图片链接"`
@@ -41,7 +41,7 @@ type CygxActivitySpecialDetail struct {
 	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  `
 	if condition != "" {
@@ -52,7 +52,7 @@ func GetActivitySpecialCount(condition string, pars []interface{}) (count int, e
 	return
 }
 
-//主题列表
+// 主题列表
 func GetActivitySpecialListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivitySpecialDetail, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT	*
@@ -65,7 +65,7 @@ func GetActivitySpecialListAll(condition string, pars []interface{}, startSize,
 	return
 }
 
-//修改发布状态
+// 修改发布状态
 func UpdateActivitySpecialPublishStatus(publishStatus, activityId int) (err error) {
 	sql := ` UPDATE cygx_activity_special SET  publish_status= ?  WHERE activity_id = ?`
 	o := orm.NewOrm()
@@ -73,7 +73,7 @@ func UpdateActivitySpecialPublishStatus(publishStatus, activityId int) (err erro
 	return
 }
 
-//主题列表
+// 主题列表
 func GetActivityLabelSpecialListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityLabelList, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT	label,activity_id,is_show_subject_name
@@ -86,7 +86,7 @@ func GetActivityLabelSpecialListAll(condition string, pars []interface{}, startS
 	return
 }
 
-//获取专项调研活动列表
+// 获取专项调研活动列表
 func GetCygxActivitySpecialDetailList(condition string, pars []interface{}, uid, startSize, pageSize int) (items []*CygxActivitySpecialDetail, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT
@@ -130,7 +130,7 @@ type CygxActivitySpecialResp struct {
 	Detail        *CygxActivitySpecialDetail
 }
 
-//通过活动ID获取活动详情
+// 通过活动ID获取活动详情
 func GetCygxActivitySpecialDetailById(uid, ActivityId int) (item *CygxActivitySpecialDetail, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT *,( SELECT COUNT( 1 ) FROM cygx_activity_special_signup AS s WHERE s.activity_id = a.activity_id AND s.user_id = ? ) AS is_signup 
@@ -148,7 +148,7 @@ type ActivityIdRep struct {
 	PlaySeconds int `description:"播放时长"`
 }
 
-//通过活动ID获取活动详情
+// 通过活动ID获取活动详情
 func GetCygxActivitySpecialDetail(ActivityId int) (item *CygxActivitySpecialDetail, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM cygx_activity_special  WHERE activity_id=? AND publish_status = 1 `

+ 44 - 0
models/activity_special_trip_bill.go

@@ -0,0 +1,44 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxActivitySpecialTripBill struct {
+	Id                int       `orm:"column(id);pk"`
+	UserId            int       `description:"用户id,多个用,隔开"`
+	ActivityId        int       `description:"活动ID"`
+	CreateTime        time.Time `description:"创建时间"`
+	Mobile            string    `description:"手机号"`
+	Email             string    `description:"邮箱号"`
+	CompanyId         int       `description:"公司ID"`
+	CompanyName       string    `description:"公司名称"`
+	RealName          string    `description:"用户实际名称"`
+	AdminId           int       `description:"销售/管理员ID"`
+	Source            int       `description:"来源,1小程序,2后台添加, 3开发人员手动添加"`
+	BillDetailed      int       `description:"流水明细,判断是进账还是出账"`
+	DoType            int       `description:"操作方式,1报名,2取消报名"`
+	RegisterPlatform  int       `description:"来源 1小程序,2:网页"`
+	ChartPermissionId int       `description:"行业id"`
+}
+
+// 添加
+func AddCygxActivitySpecialTripBill(item *CygxActivitySpecialTripBill) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	if err != nil {
+		return
+	}
+	return
+}
+
+func GetCygxActivitySpecialTripBill(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBill, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_activity_special_trip_bill  
+			WHERE 1 = 1 ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}

+ 1 - 0
models/db.go

@@ -55,6 +55,7 @@ func init() {
 		new(UserTemplateRecord),
 		new(CygxAdvice),
 		new(CygxPageHistoryRecord),
+		new(CygxActivitySpecialTripBill),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 12 - 5
models/wx_user.go

@@ -126,7 +126,7 @@ func GetWxUserItemByUserUnionId(unionId string) (item *WxUserItem, err error) {
 	return
 }
 
-//根据用户UnionId取相关信息
+// 根据用户UnionId取相关信息
 func GetWxUserAouthByUnionId(UnionId string) (item *WxUserItem, err error) {
 	sql := `SELECT
 			a.*,
@@ -146,7 +146,7 @@ func GetWxUserAouthByUnionId(UnionId string) (item *WxUserItem, err error) {
 	return
 }
 
-//根据用户手机号获取相关信息
+// 根据用户手机号获取相关信息
 func GetWxUserItemByUserMobile(mobile string) (item *WxUserItem, err error) {
 	sql := `SELECT
 			a.user_id,
@@ -171,7 +171,7 @@ func GetWxUserItemByUserMobile(mobile string) (item *WxUserItem, err error) {
 	return
 }
 
-//GetUserCountByMobile 获取数量
+// GetUserCountByMobile 获取数量
 func GetUserCountByMobile(mobile string) (count int, err error) {
 	o := orm.NewOrm()
 	sqlCount := ` SELECT COUNT(1) AS count  FROM wx_user WHERE mobile = ? `
@@ -179,17 +179,24 @@ func GetUserCountByMobile(mobile string) (count int, err error) {
 	return
 }
 
-//添加用户信息
+// 添加用户信息
 func AddWxUser(item *WxUser) (lastId int64, err error) {
 	o := orm.NewOrm()
 	lastId, err = o.Insert(item)
 	return
 }
 
-//变更联系人是否已注册状态
+// 变更联系人是否已注册状态
 func ModifyWxUserRegisterStatus(userId int) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE wx_user SET is_register=?,source=3,register_time=NOW() WHERE user_id = ? `
 	_, err = o.Raw(sql, 1, userId).Exec()
 	return
 }
+
+// 判断这个用户是否被设置消息提醒
+func GetUserRemind(uid int) (count int, err error) {
+	sql := `SELECT  COUNT(1) AS count FROM cygx_user_remind WHERE user_id = ? `
+	err = orm.NewOrm().Raw(sql, uid).QueryRow(&count)
+	return
+}

+ 104 - 17
services/activity_special_trip.go

@@ -2,8 +2,10 @@ package services
 
 import (
 	"errors"
+	"fmt"
 	"hongze/hongze_clpt/models"
 	"hongze/hongze_clpt/utils"
+	"strconv"
 	"time"
 )
 
@@ -49,14 +51,17 @@ func SpecialTripPopupMsg(activityInfo *models.CygxActivitySpecialDetail, user *m
 	return
 }
 
-//获取用户剩余报名次数
+// 获取用户剩余报名次数
+
+// 获取用户剩余报名次数
 func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (errMsg string, tripRemaining int, err error) {
 
 	//获取 专项调研客户类型   //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户;6、冻结客户;7、流失客户 8:行业升级套餐客户
 	msgTemplate := "您的专项调研次数已用完,如仍想参加,请与您的对口销售商议"
-	var tripTota int
+	//var tripTota int
 	var airborneTota int
-	userType, _, e := GetActivitySpecialUserType(user.CompanyId)
+	//userType, _, e := GetActivitySpecialUserType(user.CompanyId)
+	userType, _, e := GetUserType(user.CompanyId)
 	if e != nil {
 		err = errors.New("获取客户身份信息失败 GetActivitySpecialUserType, Err: " + e.Error())
 		return
@@ -79,20 +84,25 @@ func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *model
 			err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
 			return
 		}
-
-		condition += ` AND is_valid = 1 `
-
-		tripTota, e = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
+		//condition += ` AND is_valid = 1 `
+		//查询当年的数据
+		condition += ` AND create_time > ?  `
+		pars = append(pars, time.Now().Format(utils.FormatDate))
+		listTripBill, e := models.GetCygxActivitySpecialTripBill(condition, pars)
 		if e != nil {
 			err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
 			return
 		}
-		tripTota += airborneTota
-		if tripTota >= 12 {
+		var TripBillNum int
+		for _, v := range listTripBill {
+			TripBillNum += v.BillDetailed
+		}
+		tripRemaining = 10 - airborneTota + TripBillNum
+		if tripRemaining <= 0 {
 			errMsg = msgTemplate
 			return
 		}
-		tripRemaining = 12 - tripTota
+		//tripRemaining = 12 - tripTota
 	} else {
 		var condition string
 		var pars []interface{}
@@ -108,20 +118,97 @@ func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *model
 			err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
 			return
 		}
-
-		condition += ` AND is_valid = 1 `
-
-		tripTota, e = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
+		//查询当年的数据
+		condition += ` AND create_time > ?  `
+		pars = append(pars, time.Now().Format(utils.FormatDate))
+		listTripBill, e := models.GetCygxActivitySpecialTripBill(condition, pars)
 		if e != nil {
 			err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
 			return
 		}
-		tripTota += airborneTota
-		if tripTota >= 6 {
+		var TripBillNum int
+		for _, v := range listTripBill {
+			TripBillNum += v.BillDetailed
+		}
+		tripRemaining = 5 - airborneTota + TripBillNum
+		if tripRemaining <= 0 {
 			errMsg = msgTemplate
 			return
 		}
-		tripRemaining = 6 - tripTota
+	}
+	return
+}
+
+// 用户搜专项调研操作操作行为,模板消息推送
+func ActivitySpecialUserRmind(user *models.WxUserItem, activityId, TripStatus int) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("用户搜专项调研操作操作行为,模板消息推送失败"+err.Error(), 2)
+		}
+	}()
+	countUser, err := models.GetUserRemind(user.UserId)
+	if err != nil {
+		return err
+	}
+	if countUser == 0 {
+		return err
+	}
+	var first string
+	var keyword1 string
+	var keyword2 string
+	var keyword3 string
+	var keyword4 string
+	var remark string
+	//获取销售手机号
+	sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return err
+	}
+	if sellerItemQy != nil {
+		openIdList, e := models.GetWxOpenIdByMobileList(sellerItemQy.Mobile)
+		if e != nil {
+			err = errors.New("GetSellerByAdminId, Err: " + e.Error())
+			return
+		}
+		activityInfo, e := models.GetCygxActivitySpecialDetailById(user.UserId, activityId)
+		if e != nil {
+			err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
+			return
+		}
+		if activityInfo == nil {
+			return
+		}
+		//TripStatus            int    `description:"行程进行状态 1:预报名,2:确定行程"`
+		if TripStatus == 1 {
+			first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:专项调研预报名")
+		} else {
+			first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:活动报名")
+		}
+		keyword1 = activityInfo.ResearchTheme
+		keyword2 = "__"
+		remark = "点击查看活动详情"
+		openIdArr := make([]string, 0)
+		for _, v := range openIdList {
+			openIdArr = append(openIdArr, v.OpenId)
+		}
+		redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(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.WxMsgTemplateIdArticleUserRemind
+		sendInfo.RedirectUrl = redirectUrl
+		sendInfo.RedirectTarget = 3
+		sendInfo.Resource = strconv.Itoa(activityId)
+		sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
+		sendInfo.OpenIdArr = openIdArr
+		err = PublicSendTemplateMsg(sendInfo)
+		if err != nil {
+			return
+		}
 	}
 	return
 }

+ 12 - 9
utils/config.go

@@ -26,15 +26,16 @@ var (
 	WxPublicAppId     string //查研观向小助手公众号
 	WxPublicAppSecret string //查研观向小助手公众号
 
-	WxOpenAppId                   string //公众平台AppId
-	WxOpenAppSecret               string //公众平台AppSecret
-	HeadimgurlDefault             string //默认头像
-	WxMsgTemplateIdApplyXzs       string //申请待处理(小助手)
-	WxMsgTemplateIdApplyCancelXzs string //预约取消提醒(小助手)
-	WxMsgTemplateIdApply          string //申请待处理
-	WxMsgTemplateIdAskMsgMobile   string //手机号用户【XXX】发送模板消息
-	WxMsgTemplateIdAskMsgXzs      string //手机号用户【XXX】发送模板消息模板ID(小助手)
-	IndexName                     string
+	WxOpenAppId                      string //公众平台AppId
+	WxOpenAppSecret                  string //公众平台AppSecret
+	HeadimgurlDefault                string //默认头像
+	WxMsgTemplateIdApplyXzs          string //申请待处理(小助手)
+	WxMsgTemplateIdApplyCancelXzs    string //预约取消提醒(小助手)
+	WxMsgTemplateIdApply             string //申请待处理
+	WxMsgTemplateIdAskMsgMobile      string //手机号用户【XXX】发送模板消息
+	WxMsgTemplateIdAskMsgXzs         string //手机号用户【XXX】发送模板消息模板ID(小助手)
+	WxMsgTemplateIdArticleUserRemind string //用户阅读报告通知-模板ID
+	IndexName                        string
 
 	ActSendMsgMobile string //活动带问发送模板消息接收者的手机号
 
@@ -95,6 +96,7 @@ func init() {
 		WxMsgTemplateIdApply = "PaoDanHGlt1kFw5q-4_ipJSwO3FyZpxSSNg4rwB7YCk"
 		WxMsgTemplateIdAskMsgMobile = "15557270714,17634786714,18767183922,17516315016"
 		WxMsgTemplateIdAskMsgXzs = "IpS-yuNNQc8osCoy20jPHNkvBUyKRL1NGn7c0G9xmQA" //手机号用户【XXX】发送模板消息模板ID(小助手)
+		WxMsgTemplateIdArticleUserRemind = "7qe3i4MrGxAIPhJeMgoqqw6j0A_foUB65DLSmxKe05s"
 
 		WxOpenAppId = "wx26ccbe242908ed73"                   //公众平台AppId
 		WxOpenAppSecret = "0851cc85027c6eb74a400016648ecda8" //公众平台AppSecret
@@ -109,6 +111,7 @@ func init() {
 		WxMsgTemplateIdApply = "qfNuops-sKrfIkbA7U97A7gSrX03mUpoEpJksRUdloo"
 		WxMsgTemplateIdAskMsgMobile = "15557270714,17634786714,18767183922,17516315016"
 		WxMsgTemplateIdAskMsgXzs = "qfNuops-sKrfIkbA7U97A7gSrX03mUpoEpJksRUdloo" //手机号用户【XXX】发送模板消息模板ID(小助手)
+		WxMsgTemplateIdArticleUserRemind = "CB7bOl7f3viMG4s1uhRo7WM0Jbx3WvodKuIZ8A_z8fM"
 
 		WxOpenAppId = "wx294d2825f451f851"                   //公众平台AppId
 		WxOpenAppSecret = "7bf62d2d037280f8b635c6eca2f31db9" //公众平台AppSecret