participate.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package util
  2. import (
  3. "app.yhyue.com/moapp/jybase/redis"
  4. "fmt"
  5. IC "jyBXCore/rpc/init"
  6. "sync"
  7. )
  8. var (
  9. PLock *ParticipateLock
  10. )
  11. type ParticipateLock struct {
  12. sync.Mutex
  13. UserLock map[string]*sync.Mutex
  14. }
  15. func NewParticipateLock() *ParticipateLock {
  16. return &ParticipateLock{
  17. UserLock: make(map[string]*sync.Mutex),
  18. }
  19. }
  20. func GetParticipateLock(str string) *sync.Mutex {
  21. PLock.Lock()
  22. if PLock.UserLock[str] == nil {
  23. PLock.UserLock[str] = &sync.Mutex{}
  24. }
  25. PLock.Unlock()
  26. return PLock.UserLock[str]
  27. }
  28. // 参标权限判断
  29. func IsAllowedParticipate(appId, userId string, newUserId, accountId, entAccountId, entId, entUserId, positionId, positionType int64) (b bool, role int64) {
  30. powerCheck := IC.Middleground.PowerCheckCenter.Check(appId, userId, newUserId, accountId, entId, positionType, positionId)
  31. //不是超级订阅 也不是大会员
  32. if powerCheck.Vip.Status <= 0 && powerCheck.Member.Status <= 0 {
  33. return
  34. }
  35. role = powerCheck.Ent.EntRoleId
  36. resource := IC.Middleground.ResourceCenter.Haspowers(accountId, entAccountId, entId, entUserId)
  37. if len(resource.Powers) != 0 {
  38. for _, r := range resource.Powers {
  39. //资源中台 cb_zy_code
  40. if r == IC.C.ResourceCode {
  41. b = true
  42. break
  43. }
  44. }
  45. }
  46. return
  47. }
  48. // 3秒内防止重复提交
  49. func IsAllowedAccess(key string) string {
  50. redisKey := fmt.Sprintf("participate_isAllowed_%s", key)
  51. if b, err := redis.Exists("other", redisKey); err != nil && b {
  52. return "访问频次过快,请稍后再试"
  53. }
  54. redis.Put("other", redisKey, key, 3)
  55. return ""
  56. }