|
@@ -3,6 +3,8 @@ package cygx
|
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "hongze/hz_crm_api/models"
|
|
|
+ "hongze/hz_crm_api/models/company"
|
|
|
"hongze/hz_crm_api/models/cygx"
|
|
|
"hongze/hz_crm_api/services/alarm_msg"
|
|
|
"hongze/hz_crm_api/utils"
|
|
@@ -70,3 +72,95 @@ func GetCygxUserYanxuanPermissionMapItem(userIds []int) (mapResp map[int]*cygx.C
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// 更新权益用户个人权限信息
|
|
|
+func UddateUserProductRai(userId int) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ go alarm_msg.SendAlarmMsg("更新权益用户个人权限信息失败 ,UddateUserProductRai,Err:"+err.Error()+fmt.Sprint("userId:", userId), 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ productId := utils.COMPANY_PRODUCT_RAI_ID
|
|
|
+ total, e := cygx.GetCygxUserYanxuanPermissionCountByUserIdStatus(userId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxUserYanxuanPermissionCountByUserIdStatus, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ totalUp, e := company.GetUserProductCountRaiByProductIdUserId(userId, productId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxUserYanxuanPermissionCountByUserIdStatus, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if total == 0 {
|
|
|
+ if totalUp == 0 {
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ yanxuanPermissionDetail, e := cygx.GetCygxUserYanxuanPermissionDetail(userId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxUserYanxuanPermissionCountByUserIdStatus, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if totalUp == 0 {
|
|
|
+ wxUser, e := models.GetWxUserItemByUserId(userId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item := new(company.UserProduct)
|
|
|
+ item.CompanyId = wxUser.CompanyId
|
|
|
+ item.ProductId = productId
|
|
|
+ item.ProductName = utils.COMPANY_PRODUCT_RAI_NAME
|
|
|
+ item.CompanyName = wxUser.CompanyName
|
|
|
+ item.Status = "试用"
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
+ item.StartDate = yanxuanPermissionDetail.StartDate
|
|
|
+ item.EndDate = yanxuanPermissionDetail.EndDate
|
|
|
+ item.RealName = wxUser.RealName
|
|
|
+ item.Mobile = wxUser.Mobile
|
|
|
+ item.Email = wxUser.Email
|
|
|
+ _, e = company.AddUserProduct(item)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("AddUserProduct, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ detailUp, e := company.GetUserProductDetailByProductIdUserId(userId, productId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetUserProductDetailByProductIdUserId, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var updateEndDate string
|
|
|
+ if detailUp.Status == "关闭" {
|
|
|
+ updateEndDate = yanxuanPermissionDetail.EndDate
|
|
|
+ } else {
|
|
|
+ startDateTimeYx, _ := time.ParseInLocation(utils.FormatDate, yanxuanPermissionDetail.EndDate, time.Local)
|
|
|
+ startDateTimeUp, _ := time.ParseInLocation(utils.FormatDate, detailUp.EndDate, time.Local)
|
|
|
+ if startDateTimeYx.After(startDateTimeUp) {
|
|
|
+ updateEndDate = yanxuanPermissionDetail.EndDate
|
|
|
+ } else {
|
|
|
+ updateEndDate = detailUp.EndDate
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if detailUp.Status == "正式" {
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ e = company.UpdateUserProductEndDate(updateEndDate, "试用", userId, productId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateUserProductEndDate, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|