123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_mfyx/models"
- "hongze/hongze_mfyx/models/order"
- "hongze/hongze_mfyx/utils"
- "time"
- )
- // 判断用户是否开通了个人研选权限
- func GetMfyxUserPermissionTotal(userId int) (toatal int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("判断用户是否开通了个人研选权限失败 GetMfyxUserPermissionTotal userId", userId, ",err:", err.Error()), 2)
- }
- }()
- //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
- toatal, e := models.GetCygxUserYanxuanPermissionCountByUserId(userId)
- if e != nil {
- err = errors.New("GetCygxUserYanxuanPermissionCountByUserId, Err: " + e.Error())
- return
- }
- return
- }
- // 查询研选的权限状态
- func GetUserRaiPermissionYanXuanInfo(user *models.WxUserItem) (hasPermission int, err error) {
- uid := user.UserId
- applyCount, e := models.GetApplyRecordCount(uid)
- if e != nil {
- err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
- return
- }
- if user.CompanyId <= 1 {
- if applyCount == 0 {
- hasPermission = 4
- } else {
- hasPermission = 5
- }
- } else {
- hasPermission = 3
- }
- //判断用户是否开通了个人研选权限
- mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(user.UserId)
- if mfyxUserPermissionTotal == 1 {
- hasPermission = 1
- return
- }
- var condition string
- var pars []interface{}
- condition = " AND company_id = ? AND status IN ('正式','试用') AND chart_permission_id = ? ORDER BY company_report_permission_id DESC LIMIT 1 "
- pars = append(pars, user.CompanyId, utils.CHART_PERMISSION_ID_YANXUAN)
- companyReportPermissionDetail, e := models.GetCompanyReportPermissionDetailByCondition(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCompanyReportPermissionDetailByCondition, Err: " + e.Error())
- return
- }
- //如果用户没有研选权限,那么就获取他对应的状态码
- if companyReportPermissionDetail == nil {
- hasPermission, _, _, _, e = GetUserHasPermissionArticle(user)
- if e != nil {
- err = errors.New("GetUserHasPermissionArticle, Err: " + e.Error())
- return
- }
- } else {
- hasPermission = 1
- }
- return
- }
- // 判断用户是否持有阅读卡
- func GetCygxOrderUserCardTotal(mobile string) (total int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("判断用户是否持有阅读卡失败 GetCygxOrderUserCardTotal mobile", mobile, ",err:", err.Error()), 2)
- }
- }()
- var condition string
- var pars []interface{}
- condition += ` AND mobile = ? AND is_suspend = 0 AND start_date < ? AND end_date > ? `
- pars = append(pars, mobile, time.Now(), time.Now())
- total, e := order.GetCygxOrderUserCardCount(condition, pars)
- if e != nil {
- err = errors.New("GetCygxUserYanxuanPermissionCountByUserId, Err: " + e.Error())
- return
- }
- return
- }
- // 判断用户是购买了单场付费活动
- func GetCygxOrderVirtualAssetdCountTotal(mobile string, activityId int) (total int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("判断用户是购买了单场付费活动失败 GetCygxOrderUserCardTotal mobile", mobile, "activityId:", activityId, ",err:", err.Error()), 2)
- }
- }()
- var condition string
- var pars []interface{}
- condition += ` AND mobile = ? AND source = 'activity' AND source_id = ? `
- pars = append(pars, mobile, activityId)
- total, e := order.GetCygxOrderVirtualAssetdCount(condition, pars)
- if e != nil {
- err = errors.New("GetCygxOrderVirtualAssetdCount, Err: " + e.Error())
- return
- }
- return
- }
|