|
@@ -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
|
|
|
+}
|