浏览代码

no message

xingzai 1 年之前
父节点
当前提交
a0bfe1c82b
共有 11 个文件被更改,包括 255 次插入308 次删除
  1. 31 295
      controllers/article.go
  2. 8 0
      models/apply_record.go
  3. 12 10
      models/article.go
  4. 8 1
      models/company_product.go
  5. 23 0
      models/order/goods.go
  6. 32 0
      services/article.go
  7. 29 0
      services/order.go
  8. 0 1
      services/user.go
  9. 83 0
      services/user_permission.go
  10. 10 0
      utils/common.go
  11. 19 1
      utils/constants.go

+ 31 - 295
controllers/article.go

@@ -66,16 +66,9 @@ func (this *ArticleController) Detail() {
 		return
 	}
 	detail := new(models.ArticleDetail)
-	//detailInit := new(models.ArticleDetail) // 初始化的文章信息,用来处理body 内容回显
 	hasPermission := 0
 	var haveResearch bool
-	//判断是否已经申请过
-	applyCount, err := models.GetApplyRecordCount(uid)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		br.Msg = "获取信息失败"
-		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
-		return
-	}
+
 	resp := new(models.ArticleDetailResp)
 	detail, err = models.GetArticleDetailById(articleId)
 	if err != nil {
@@ -97,42 +90,13 @@ func (this *ArticleController) Detail() {
 			detail.DepartmentImgUrl = departmentDetail.ImgUrl
 		}
 	}
-	lyjhTypeMap, _ := services.GetLyjhTypeMap()
-	if _, ok := lyjhTypeMap[detail.CategoryId]; ok {
-		detail.IsRoadShow = true
-	}
-	// 判断是否属于研选类型的报告
-	if strings.Contains(detail.CategoryName, utils.CHART_PERMISSION_NAME_YANXUAN) {
-		detail.IsResearch = true
-	}
 
-	// 高毅资产的联系人,有权限的行业也不能查看报告详情页。提示无权限页面
-	if detail.ArticleTypeId == 0 && user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID {
-		_, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
-		if err != nil {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
-			return
-		}
-		resp.PopupMsg = popupMsg
-		resp.HasPermission = 3
-		resp.SellerName = sellerName
-		resp.SellerMobile = sellerMobile
-		detail.Body = ""
-		detail.Abstract = ""
-		detail.BodyText = ""
-		detail.SellerName = sellerName
-		detail.SellerMobile = sellerMobile
-		resp.Detail = detail
-		br.Ret = 200
-		br.Success = true
-		br.Msg = "获取成功"
-		br.Data = resp
-		return
-	}
+	// 判断是否属于研选类型的报告
+	detail.IsResearch = true
 	articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
 	detail.IsCollect = articleCollectMap[detail.ArticleId]
-	//detailInit = detail
+
+	//是否是通过模板消息进来的
 	if isSendWx == 1 {
 		var condition string
 		var pars []interface{}
@@ -168,208 +132,24 @@ func (this *ArticleController) Detail() {
 			}
 		}
 	}
-	//是否属于专项调研报告
-	if detail.SubCategoryName == "专项调研" {
-		detail.IsSpecialArticle = true
-		havePower, err := services.GetSpecialArticleDetailUserPower(user, detail)
-		if err != nil {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
-			return
-		}
-		resp.IsSpecialArticle = true
-		if !havePower {
-			hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
-			if err != nil {
-				br.Msg = "获取信息失败"
-				br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
-				return
-			}
-			resp.PopupMsg = popupMsg
-			resp.HasPermission = hasPermission
-			resp.SellerName = sellerName
-			resp.SellerMobile = sellerMobile
-			detail.Body = ""
-			detail.Abstract = ""
-			detail.BodyText = ""
-			detail.SellerName = sellerName
-			detail.SellerMobile = sellerMobile
-			resp.Detail = detail
-			br.Ret = 200
-			br.Success = true
-			br.Msg = "获取成功"
-			br.Data = resp
-			return
-		}
-	}
-	//`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
-	if user.CompanyId > 1 {
-		companyPermission, err := models.GetCompanyPermission(user.CompanyId)
-		if err != nil {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
-			return
-		}
-
-		//判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
-		mfyxUserPermissionTotal := services.GetMfyxUserPermissionTotal(uid)
-		if mfyxUserPermissionTotal == 1 {
-			companyPermission += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
-			companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME
-		}
-		//如果有研选订阅的权限,那么就拼接一个 买方研选的权限做校验
-		if strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
-			companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME
-		}
-
-		if companyPermission == "" {
-			if applyCount > 0 {
-				hasPermission = 5
-			} else {
-				hasPermission = 2
-			}
-			goto Loop
-		} else {
-			var articlePermissionName string
-			if detail.CategoryId > 0 {
-				articlePermission, err := models.GetArticlePermission(detail.CategoryId)
-				if err != nil {
-					br.Msg = "获取信息失败"
-					br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
-					return
-				}
-				if articlePermission == nil {
-					br.Msg = "获取信息失败"
-					br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
-					return
-				}
-				articlePermissionName = articlePermission.PermissionName
-			} else {
-				articlePermissionName = detail.CategoryName
-			}
 
-			var hasPersion bool
-			slice := strings.Split(articlePermissionName, ",")
-			for _, v := range slice {
-				if strings.Contains(companyPermission, v) {
-					hasPersion = true
-				}
-			}
-			if strings.Contains(detail.CategoryName, "研选") {
-				detail.IsResearch = true
-			}
-			userType, _, err := services.GetUserType(user.CompanyId)
-			if err != nil {
-				br.Msg = "获取信息失败"
-				br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
-				return
-			}
-			//永续客户,无法查看研选权限,但是下面的联系人,单独开通研选后,也可以查看研选内容
-			if userType == 1 && strings.Contains(detail.CategoryName, "研选") && mfyxUserPermissionTotal == 0 {
-				hasPersion = false
-			}
-			//if detail.IsReport == 1 {
-			//detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
-			//if err != nil && err.Error() != utils.ErrNoRow() {
-			//	br.Msg = "获取信息失败"
-			//	br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
-			//	return
-			//}
-			//permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
-			//if err != nil {
-			//	br.Msg = "获取信息失败"
-			//	br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
-			//	return
-			//}
-			//if detailCategory != nil {
-			//	if detailCategory.PermissionType == 1 {
-			//		if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
-			//			hasPersion = false
-			//		}
-			//	} else if detailCategory.PermissionType == 2 {
-			//		if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
-			//			hasPersion = false
-			//		}
-			//	}
-			//}
-			//}
-
-			//大行业通过权限校验,再校验主客观权限。只有医药、消费、科技、智造,才会校验主客观权限
-			if hasPersion && utils.InArrayByStr([]string{utils.YI_YAO_NAME, utils.XIAO_FEI_NAME, utils.KE_JI_NAME, utils.ZHI_ZAO_NAME}, articlePermissionName) {
-				hasPersion = services.CheckArticlePermissionType(articleId, user)
-			}
-			if hasPersion {
-				hasPermission = 1
-				go services.ArticleHistory(articleId, user)
-				//30分钟之内阅读同一篇文章不错二次推送
-				key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
-				if !utils.Rc.IsExist(key) {
-					go services.ArticleUserRemind(user, detail, 1)
-					utils.Rc.Put(key, 1, 30*time.Second)
-				}
-			} else { //无该行业权限
-				companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
-				if err == nil && companyDetail.ProductId == 1 {
-					hasPermission = 2
-				} else {
-					hasPermission = 3
-				}
-			}
-		}
+	havePower, err := services.GetArticleDetailUserPower(user, detail)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "校验用户权限失败,Err:" + err.Error()
+		return
+	}
 
-		interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
-			return
-		}
-		if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
-			detail.IsInterviewApply = true
-			detail.InterviewApplyStatus = interviewApplyItem.Status
-		}
-		//获取销售手机号
-		sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
-			return
-		}
-		if sellerItem != nil {
-			detail.SellerMobile = sellerItem.Mobile
-			detail.SellerName = sellerItem.RealName
-		}
-		sellerList, err := models.GetSellerList(articleId)
-		if err != nil {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
-			return
-		}
-		if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
-			strnum := strings.Index(detail.SellerAndMobile, "-")
-			detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
-			if strnum > 0 {
-				nickName := detail.SellerAndMobile[0:strnum]
-				sellerAndMobile := &models.SellerRep{
-					SellerMobile: "",
-					SellerName:   nickName,
-				}
-				sellerList = append(sellerList, sellerAndMobile)
-			}
+	if havePower {
+		hasPermission = 1
+		go services.ArticleHistory(articleId, user)
+		//30分钟之内阅读同一篇文章不错二次推送
+		key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
+		if !utils.Rc.IsExist(key) {
+			go services.ArticleUserRemind(user, detail, 1)
+			utils.Rc.Put(key, 1, 30*time.Second)
 		}
-		detail.SellerList = sellerList
 
-	} else { //潜在客户
-		if applyCount > 0 {
-			hasPermission = 5
-		} else {
-			hasPermission = 4
-		}
-	}
-Loop:
-	if hasPermission != 1 && user.UserId > 0 {
-		detail.Body = ""
-		detail.BodyText = ""
-	} else {
 		articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
 		if err != nil {
 			br.Msg = "获取信息失败"
@@ -387,16 +167,15 @@ Loop:
 		if detail.IsReport == 1 {
 			detail.IsBelongReport = true
 		}
-		haveResearch = true
-	}
-	if hasPermission == 5 {
-		companyPermissionNoStatus, err := models.GetCompanyPermissionByUserNoStatus(user.CompanyId)
-		if err != nil {
+	} else {
+		hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "获取信息失败"
-			br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			br.ErrMsg = "获取信息失败,GetUserDetailPermissionCode Err:" + err.Error()
 			return
 		}
-		if companyPermissionNoStatus != "" {
+		//权益客户对权益销售信息进行展示
+		if hasPermission == 2 || hasPermission == 3 {
 			sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
 			if err != nil && err.Error() != utils.ErrNoRow() {
 				br.Msg = "获取信息失败"
@@ -409,63 +188,20 @@ Loop:
 				detail.SellerName = sellerItemQy.RealName
 			}
 		}
-	}
-
-	if hasPermission == 2 || hasPermission == 4 {
-		//获取销售手机号
-		sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
-			return
-		}
-		if sellerItemQy != nil {
-			hasPermission = 3
-			detail.SellerMobile = sellerItemQy.Mobile
-			detail.SellerName = sellerItemQy.RealName
-		}
-	}
-
-	if detail.ArticleId < utils.SummaryArticleId {
-		if user.Mobile != "" {
+		detail.Body = ""
+		detail.BodyText = ""
+		resp.IsShowWxPay = utils.IS_SHOW_WX_PAY          //是否展示微信支付按钮
+		resp.GoodsList = services.GetUserGoodsCardList() //日卡月卡商品信息
 
-			detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token="
-		} else {
-			detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId)
-		}
-		detail.IsNeedJump = true
+		//resp.IsCompanyApply =
 	}
 
-	// 处理研选下面的路演精华 的报告链接是否跳转
-	if hasPermission == 1 && detail.ArticleId > utils.SummaryArticleId && detail.ArticleTypeId > 0 {
-		//detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
-		if detail.ReportLink != "" {
-
-			detail.ReportLink += "?token="
-		}
-	}
-	if articleId < utils.SummaryArticleId {
-		detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
-	}
 	if detail.ArticleTypeId == 14 {
 		detail.IsApplyAppointmentExpert = true //判断文章类型是否属于专家访谈  查研观向11.0
 	}
 	resp.HasPermission = hasPermission
 	resp.HaveResearch = haveResearch
-	if user.UserId == 0 {
-		resp.HasPermission = 1
-		if detail.UpdateFrequency == "daily" {
-			detail.Frequency = "日度"
-		} else if detail.UpdateFrequency == "weekly" {
-			detail.Frequency = "周度"
-		} else if detail.UpdateFrequency == "monthly" {
-			detail.Frequency = "月度"
-		} else if detail.UpdateFrequency == "quarterly" {
-			detail.Frequency = "季度"
-		} else if detail.UpdateFrequency == "yearly" {
-			detail.Frequency = "年度"
-		}
-	}
+
 	resp.Detail = detail
 	if user.Mobile != "" {
 		resp.Mobile = user.Mobile

+ 8 - 0
models/apply_record.go

@@ -78,6 +78,14 @@ func GetApplyRecordCount(userId int) (count int, err error) {
 	return
 }
 
+// 获取客户的试用申请次数
+func GetApplyRecordCountByCompanyIdPay(companyIdPay int) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count FROM cygx_apply_record WHERE user_id=?  AND company_id_pay = ?  `
+	err = o.Raw(sql, companyIdPay).QueryRow(&count)
+	return
+}
+
 // 通过手机号获取详情
 func GetCygxApplyRecordByMobile(mobile string) (item *CygxApplyRecord, err error) {
 	o := orm.NewOrm()

+ 12 - 10
models/article.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_mfyx/models/order"
 	"time"
 )
 
@@ -244,16 +245,17 @@ func GetArticlePermission(companyId int) (item *ChartPermission, err error) {
 }
 
 type ArticleDetailResp struct {
-	Detail           *ArticleDetail
-	HasPermission    int    `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
-	HasFree          int    `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
-	HaveResearch     bool   `description:"是否有研选权限"`
-	Mobile           string `description:"用户手机号"`
-	PopupMsg         string `description:"权限弹窗信息"`
-	SellerMobile     string `description:"销售电话"`
-	SellerName       string `description:"销售姓名"`
-	IsSpecialArticle bool   `description:"是否属于专项调研报告"`
-	IsResearch       bool   `description:"是否属于研选"`
+	Detail         *ArticleDetail
+	HasPermission  int                    `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
+	HasFree        int                    `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
+	HaveResearch   bool                   `description:"是否有研选权限"`
+	Mobile         string                 `description:"用户手机号"`
+	PopupMsg       string                 `description:"权限弹窗信息"`
+	SellerMobile   string                 `description:"销售电话"`
+	SellerName     string                 `description:"销售姓名"`
+	IsShowWxPay    bool                   `description:"是否展示微信支付"`
+	IsCompanyApply bool                   `description:"机构是否申请过试用"`
+	GoodsList      []*order.CygxGoodsResp `description:"商品信息"`
 }
 
 type ArticleDetailHtgjResp struct {

+ 8 - 1
models/company_product.go

@@ -5,7 +5,7 @@ import (
 )
 
 // 获取是否属于权益客户
-func GetCountCompanyProductCompanyId(companyId, productId int) (count int, err error) {
+func GetCompanyProductCount(companyId, productId int) (count int, err error) {
 	o := orm.NewOrmUsingDB("weekly_report")
 	sql := `SELECT  COUNT(1) AS count FROM company_product WHERE company_id = ?  AND product_id = ?  `
 	err = o.Raw(sql, companyId, productId).QueryRow(&count)
@@ -22,3 +22,10 @@ func GetCompanyProductList(condition string, pars []interface{}) (items []*Compa
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }
+
+func GetCompanyProductDetailByCompanyId(companyId, productId int) (item *CompanyProduct, err error) {
+	sql := ` SELECT * FROM company_product WHERE company_id = ? AND product_id = ?; `
+	o := orm.NewOrmUsingDB("weekly_report")
+	err = o.Raw(sql, companyId, productId).QueryRow(&item)
+	return
+}

+ 23 - 0
models/order/goods.go

@@ -0,0 +1,23 @@
+package order
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	//"time"
+)
+
+type CygxGoodsResp struct {
+	GoodsId      int    `description:"商品ID"`
+	GoodsName    string `description:"商品名称"`
+	Price        string `description:"商品原价格"`
+	CurrentPrice string `description:"商品现价(当时出售的价格)"`
+}
+
+func GetCygxGoodsList(condition string, pars []interface{}) (item []*CygxGoodsResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_goods
+			WHERE 1 = 1 ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}

+ 32 - 0
services/article.go

@@ -574,3 +574,35 @@ func GetYanxuanArticleIds() (articleIds []int) {
 	}
 	return
 }
+
+// GetArticleDetailUserPower 处理用户查看报告详情的权限
+func GetArticleDetailUserPower(user *models.WxUserItem, articleInfo *models.ArticleDetail) (havePower bool, err error) {
+	userId := user.UserId
+	companyId := user.CompanyId
+	//判断用户是否开通了个人研选权限
+	mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(userId)
+	if mfyxUserPermissionTotal == 1 {
+		havePower = true
+		return
+	}
+
+	productDetail, e := models.GetCompanyProductDetailByCompanyId(companyId, 2)
+	if e != nil {
+		err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
+		return
+	}
+	// 永续客户无法查看研选权限
+	if productDetail.Status == utils.COMPANY_STATUS_FOREVER {
+		return
+	}
+	permissionStr, e := models.GetCompanyPermission(companyId)
+	if e != nil {
+		err = errors.New("GetCompanyPermission, Err: " + e.Error())
+		return
+	}
+	if strings.Contains(permissionStr, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
+		havePower = true
+		return
+	}
+	return
+}

+ 29 - 0
services/order.go

@@ -0,0 +1,29 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_mfyx/models/order"
+	"hongze/hongze_mfyx/utils"
+)
+
+// 获取日卡、月卡商品配置信息
+func GetUserGoodsCardList() (goodsListResp []*order.CygxGoodsResp) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("判断用户是否开通了个人研选权限失败 GetCygxGoodsList, err:", err.Error()), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	condition = ` AND  goods_id IN  (1,2) `
+	goodsList, e := order.GetCygxGoodsList(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxGoodsList, Err: " + e.Error())
+		return
+	}
+	goodsListResp = goodsList
+	return
+}

+ 0 - 1
services/user.go

@@ -46,7 +46,6 @@ func GetWxUserItemByOpenId(openid string) (item *models.WxUserItem, err error) {
 		formatWxUserAndUserRecord(item, userRecord)
 		return
 	}
-	fmt.Println("userRecord.UserId ", userRecord.UserId)
 
 	//获取用户信息
 	item, wxUserErr := models.GetWxUserItemByUserId(userRecord.UserId)

+ 83 - 0
services/user_permission.go

@@ -2,6 +2,7 @@ package services
 
 import (
 	"errors"
+	"fmt"
 	"hongze/hongze_mfyx/models"
 	"hongze/hongze_mfyx/utils"
 	"strings"
@@ -85,3 +86,85 @@ func GetUserRaiPermissionInfo(userId, companyId int) (authInfo models.UserPermis
 	permissionArr = strings.Split(permissions, ",")
 	return
 }
+
+func GetUserApplyRecordCount(userId int) (applyCount int, err error) {
+	// 用户申请记录
+	applyCount, e := models.GetApplyRecordCount(userId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("获取用户申请信息失败, Err: " + e.Error())
+		return
+	}
+	return
+}
+
+// 获取客户是否有过历史申请记录
+func GetUserApplyRecordCountByCompanyIdPay(companyIdPay int) (isApplyCount bool) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("判断用户是否开通了个人研选权限失败 GetCygxGoodsList, err:", err.Error()), 2)
+		}
+	}()
+	if companyIdPay >= 1 {
+		return
+	}
+	// 客户申请
+	applyCount, e := models.GetApplyRecordCountByCompanyIdPay(companyIdPay)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("获取用户申请信息失败, Err: " + e.Error())
+		return
+	}
+	if applyCount > 0 {
+		isApplyCount = true
+	}
+	return
+}
+
+// 用户详情页获取用户权限状态  https://hzstatic.hzinsights.com/static/images/202402/20240205/LpE6dspJCLzfQoCoE8SFMDiLuxXk.png(状态码说明)
+func GetUserDetailPermissionCode(userId, companyId int) (permission int, err error) {
+	// 用户申请记录
+	applyCount, e := GetUserApplyRecordCount(userId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("获取用户申请信息失败, Err: " + e.Error())
+		return
+	}
+	if companyId == 1 {
+		// 潜在用户
+		if applyCount > 0 {
+			permission = 6
+		} else {
+			permission = 7
+		}
+	} else {
+		//权益客户
+		raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
+		if e != nil {
+			err = errors.New("获取用户申请信息失败, Err: " + e.Error())
+			return
+		}
+
+		if raiCount == 1 {
+			if applyCount > 0 {
+				permission = 2
+			} else {
+				permission = 3
+			}
+		} else {
+			//ficc 客户
+			ficcCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_FICC_ID)
+			if e != nil {
+				err = errors.New("获取用户申请信息失败, Err: " + e.Error())
+				return
+			}
+			if ficcCount == 1 {
+				if applyCount > 0 {
+					permission = 4
+				} else {
+					permission = 5
+				}
+			}
+		}
+	}
+	return
+}

+ 10 - 0
utils/common.go

@@ -960,3 +960,13 @@ func StrDateToDate(strTime string) time.Time {
 	resultTime, _ := time.ParseInLocation(timeLayout, strTime, loc)
 	return resultTime
 }
+
+func GetOrdernum() string {
+	now := time.Now().UnixNano()
+	// 生成4位随机数
+	rand.Seed(now)
+	randomPart := rand.Intn(10000)
+	// 拼接订单号
+	orderSn := "OD" + time.Now().Format(FormatDateTimeUnSpace) + fmt.Sprintf("%04d", randomPart)
+	return orderSn
+}

+ 19 - 1
utils/constants.go

@@ -21,12 +21,30 @@ const (
 	PageSize30             = 30
 )
 
+// 客户状态
+const (
+	COMPANY_STATUS_TRY_OUT         = "试用"
+	COMPANY_STATUS_X_CLASS_TRY_OUT = "X类试用" //最早定义为永续
+	COMPANY_STATUS_FOREVER         = "永续"
+	COMPANY_STATUS_FREEZE          = "冻结"
+	COMPANY_STATUS_LOSE            = "流失"
+	COMPANY_STATUS_LOSE_FLAG       = "loss"
+	COMPANY_STATUS_FORMAL          = "正式"
+	COMPANY_STATUS_POTENTIAL       = "潜在"
+	COMPANY_STATUS_CLOSE           = "关闭"
+	COMPANY_STATUS_CLOSE_FLAG      = "close"
+	COMPANY_STATUS_TRY_OUT_COUNT   = 60
+
+	COMPANY_APPROVE_STATUS = "待审批"
+)
+
 const (
 	APPNAME           = "弘则-买方研选"
 	EmailSendToUsers  = "cxzhang@hzinsights.com"
 	EmailSendToExpert = "cxzhang@hzinsights.com"
 	DefaultHeadimgurl = "https://hzstatic.hzinsights.com/static/images/202401/20240103/u6Ykx23BMTnwtvYhZnJktgD54MLp.png"
-	REGISTER_PLATFORM = 5 // 来源 1小程序,2:网页 5:买方研选
+	REGISTER_PLATFORM = 5    // 来源 1小程序,2:网页 5:买方研选
+	IS_SHOW_WX_PAY    = true // 是否展示微信支付
 )
 
 // 手机号,电子邮箱正则