123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_mfyx/models"
- "hongze/hongze_mfyx/models/order"
- "hongze/hongze_mfyx/utils"
- "strings"
- )
- var (
- UserPermissionOperationModeApply = "Apply"
- UserPermissionOperationModeCall = "Call"
- UserPermissionPopupMsgApplyActivity = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
- UserPermissionPopupMsgCallActivity = "您暂无权限参加此活动,若想参加可以联系对口销售"
- UserPermissionPopupMsgApplyMicroVideo = "您暂无权限查看此视频,若想查看可以申请开通对应的试用权限"
- UserPermissionPopupMsgCallMicroVideo = "您暂无权限查看此视频若想查看可以联系对口销售"
- )
- // GetUserRaiPermissionInfo 获取权限类型及信息
- // HasPermission 是否有权限:1-有权限; 2-无权限; 3-潜在客户未提交申请; 4-潜在客户已提交申请 5-仅有FICC权限
- func GetUserRaiPermissionInfo(userId, companyId int) (authInfo models.UserPermissionAuthInfo, permissionArr []string, err error) {
- // 用户申请记录
- applyCount, e := models.GetApplyRecordCount(userId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("获取用户申请信息失败, Err: " + e.Error())
- return
- }
- // 潜在用户
- if companyId <= 1 {
- authInfo.HasPermission = 3
- if applyCount > 0 {
- authInfo.HasPermission = 4
- }
- authInfo.OperationMode = UserPermissionOperationModeApply
- authInfo.PopupMsg = UserPermissionPopupMsgApplyActivity
- return
- }
- // 销售信息
- ficcSeller, e := models.GetSellerByCompanyIdCheckFicc(companyId, utils.COMPANY_PRODUCT_FICC_ID)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("获取FICC销售信息失败, Err: " + e.Error())
- return
- }
- raiSeller, e := models.GetSellerByCompanyIdCheckFicc(companyId, utils.COMPANY_PRODUCT_RAI_ID)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("获取权益销售信息失败, Err: " + e.Error())
- return
- }
- if raiSeller != nil {
- authInfo.SellerMobile = raiSeller.Mobile
- authInfo.SellerName = raiSeller.RealName
- }
- // 仅有FICC权限
- if ficcSeller != nil && raiSeller == nil {
- authInfo.HasPermission = 5
- authInfo.OperationMode = UserPermissionOperationModeApply
- authInfo.PopupMsg = UserPermissionPopupMsgApplyActivity
- return
- }
- // permissions示例: 医药,消费,科技,智造,策略,专家,买方研选
- permissions, e := models.GetCompanyPermissionName(companyId)
- if e != nil {
- err = errors.New("获取客户权限失败, Err: " + e.Error())
- return
- }
- if permissions == "" {
- // 无权益权限
- if raiSeller != nil {
- // 有销售信息
- authInfo.HasPermission = 2
- authInfo.OperationMode = UserPermissionOperationModeCall
- authInfo.PopupMsg = UserPermissionPopupMsgCallActivity
- return
- }
- // 无销售信息, 无申请, 视作潜在用户
- authInfo.HasPermission = 3
- authInfo.OperationMode = UserPermissionOperationModeApply
- return
- }
- // 有基本的权益权限
- authInfo.HasPermission = 1
- 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 GetCygxUserBusinessCardCount(userId, companyId int) (isNeedBusinessCard bool) {
- if companyId > 1 {
- return
- }
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("判断用户是否需要上传名片失败 GetCygxUserBusinessCardCount, err:", err.Error()), 2)
- }
- }()
- businessCardCount, e := order.GetCygxUserBusinessCardCount(userId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxUserBusinessCardCount, Err: " + e.Error())
- return
- }
- if businessCardCount > 0 {
- return
- }
- isNeedBusinessCard = true
- return
- }
- // 获取客户是否有过历史申请记录
- func GetUserApplyRecordCountByCompanyIdPay(companyIdPay int) (isCompanyApply bool) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("获取客户是否有过历史申请记录 GetUserApplyRecordCountByCompanyIdPay, err:", err.Error()), 2)
- }
- }()
- //if companyIdPay >= 1 {
- // return
- //}
- //// 客户申请
- //applyCount, e := models.GetApplyRecordCountByCompanyIdPay(companyIdPay)
- //if e != nil {
- // err = errors.New("GetApplyRecordCountByCompanyIdPay, Err: " + e.Error())
- // return
- //}
- //有研选订阅的权限的也不开放申请按钮
- permissionCount, e := models.GetCompanyPermissionCheck(companyIdPay, utils.CHART_PERMISSION_ID_YANXUAN)
- if e != nil {
- err = errors.New("GetCompanyPermissionCheck, Err: " + e.Error())
- return
- }
- //if applyCount > 0 || permissionCount > 0 {
- if permissionCount > 0 {
- isCompanyApply = true
- }
- return
- }
- // 获取用户权限状态 https://hzstatic.hzinsights.com/static/images/202402/20240205/LpE6dspJCLzfQoCoE8SFMDiLuxXk.png(状态码说明)
- func GetUserPermissionCode(userId, companyId int) (permission int, err error) {
- // 用户申请记录
- applyCount, e := models.GetApplyRecordCount(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
- }
- // 用户详情页获取用户权限状态 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
- }
- // 获取权益销售姓名
- func GetSellerName(user *models.WxUserItem) (sellerName string, sellerId int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("获取权益销售姓名失败 GetSellerName, err:", err.Error()), 2)
- }
- }()
- companyId := user.CompanyId
- //潜在客户没有销售
- if user.CompanyId <= 1 {
- return
- }
- //权益客户
- raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
- if e != nil {
- err = errors.New("GetCompanyProductCount, Err: " + e.Error())
- return
- }
- //仅开通FICC的客户不展示销售姓名
- if raiCount == 0 {
- return
- }
- sealldetail, e := models.GetRaiSellerByCompanyId(companyId)
- if e != nil {
- err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
- return
- }
- sellerName = sealldetail.RealName
- sellerId = sealldetail.AdminId
- return
- }
|