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 }