zhangchuanxing преди 1 месец
родител
ревизия
71c14b5bd8
променени са 5 файла, в които са добавени 111 реда и са изтрити 0 реда
  1. 2 0
      controllers/report.go
  2. 9 0
      models/db.go
  3. 2 0
      models/report.go
  4. 34 0
      models/wx_user/wx_user_end_date.go
  5. 64 0
      services/wx_user.go

+ 2 - 0
controllers/report.go

@@ -1470,6 +1470,8 @@ func (this *ReportController) IsShow() {
 	} else {
 		resp.IsShowMobileAndEmailButton = true //是否展示手机号跟邮箱按钮
 	}
+
+	resp.IsShowMobileAndEmailButton, resp.EndData = services.GetWxUserEndDate(user)
 	//mobile := user.Mobile
 	//if mobile == "" {
 	//	br.Ret = 200

+ 9 - 0
models/db.go

@@ -7,6 +7,7 @@ import (
 	"hongze/hongze_cygx/models/order"
 	"hongze/hongze_cygx/models/rai_serve"
 	"hongze/hongze_cygx/models/time_line"
+	"hongze/hongze_cygx/models/wx_user"
 	"hongze/hongze_cygx/models/yidong"
 	"hongze/hongze_cygx/utils"
 	"time"
@@ -197,6 +198,7 @@ func init() {
 		new(WxUserRaiLabel),
 		new(WxUserRaiLabelLog),
 		new(WxUserRaiArticleLabel),
+		//new(WxUserEndDateLog),
 	)
 
 	initOrder()      // 订单模块
@@ -246,3 +248,10 @@ func initYidong() {
 		new(yidong.CygxYidongActivityMeetData), //易董活动到会信息原始数据
 	)
 }
+
+// initYidong
+func initWxUseer() {
+	orm.RegisterModel(
+		new(wx_user.WxUserEndDateLog), //易董活动原始数据
+	)
+}

+ 2 - 0
models/report.go

@@ -399,6 +399,8 @@ type IsShow struct {
 	IsShowQuestionnaire        bool      `description:"是否展示研选问卷调查"`
 	IsShowAboutVideo           bool      `description:"是否展示关于我们的视频"`
 	IsShowMobileAndEmailButton bool      `description:"是否展示手机号跟邮箱按钮"`
+	IsShowTerminateButton      bool      `description:"是否弹到期提醒的弹窗"`
+	EndData                    string    `description:"结束时间"`
 }
 
 type SearchTxt struct {

+ 34 - 0
models/wx_user/wx_user_end_date.go

@@ -0,0 +1,34 @@
+package wx_user
+
+//权益正式客户到期前30天弹窗消息提醒
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type WxUserEndDateLog struct {
+	EndDateId   int `orm:"column(end_date_id);pk"`
+	UserId      int
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	ModifyTime  time.Time `description:"修改时间"`
+	CreateTime  time.Time `description:"创建时间"`
+	RealName    string    `description:"用户实际名称"`
+	EndDate     string    `description:"结束时间"`
+}
+
+// 添加历史信息
+func AddWxUserEndDateLog(item *WxUserEndDateLog) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+func GeWxUserEndDateLogCount(userId int, endDate string) (count int, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT COUNT(1) AS count FROM  wx_user_end_date_log WHERE user_id = ? AND end_date = ? `
+	err = o.Raw(sql, userId, endDate).QueryRow(&count)
+	return
+}

+ 64 - 0
services/wx_user.go

@@ -5,6 +5,8 @@ import (
 	"errors"
 	"fmt"
 	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/models/company"
+	"hongze/hongze_cygx/models/wx_user"
 	"hongze/hongze_cygx/utils"
 	"strconv"
 	"strings"
@@ -1496,3 +1498,65 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 	//fmt.Println(mapComapnyInteractionNum)
 	return
 }
+
+func GetWxUserEndDate(user *models.WxUserItem) (isShowTerminateButton bool, endDataButton string) {
+	companyId := user.CompanyId
+	userId := user.UserId
+	//添加一个key拦截
+	key := "CYGX_WX_USER_END_DATE_KEY" + fmt.Sprint("C_", companyId, "U_", userId)
+	if utils.Rc.IsExist(key) {
+		return
+		utils.Rc.Put(key, 1, 1*time.Second)
+	}
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("权益正式客户到期前30天弹窗消息提醒 失败GetWxUserEndDate, err:", err.Error()), 2)
+		}
+	}()
+
+	productDetail, e := company.GetCompanyProductDetailByCompanyId(companyId, 2)
+	if e != nil {
+		err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
+		return
+	}
+	if productDetail.Status != utils.COMPANY_STATUS_FORMAL { // 不是正式状态不做处理
+		return
+	}
+	endDate := utils.StrDateToTime(productDetail.EndDate)
+	diff := endDate.Sub(time.Now())
+	// 将差值转换为天数
+	diffDay := int(diff.Hours() / 24)
+	if endDate.After(time.Now()) {
+		diffDay += 1 //不足一天的按照一天计算
+	}
+	if diffDay <= 30 {
+		total, e := wx_user.GeWxUserEndDateLogCount(userId, productDetail.EndDate)
+		if e != nil {
+			err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
+			return
+		}
+		if total == 0 {
+			isShowTerminateButton = true
+			endDataButton = productDetail.EndDate
+			item := wx_user.WxUserEndDateLog{
+				UserId:      user.UserId,
+				Mobile:      user.Mobile,
+				Email:       user.Email,
+				CompanyId:   user.CompanyId,
+				CompanyName: user.CompanyName,
+				RealName:    user.RealName,
+				CreateTime:  time.Now(),
+				ModifyTime:  time.Now(),
+			}
+			_, e = wx_user.AddWxUserEndDateLog(&item)
+			if e != nil {
+				err = errors.New("AddWxUserEndDateLog, Err: " + e.Error())
+				return
+			}
+			return
+		}
+	}
+	return
+}