UserAuthUtils.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. from model.DataBaseUtils import MysqlUtils
  2. import requests
  3. def get_auth_user(user_id):
  4. """获取用户拥有所有用户(包括自己)的权限"""
  5. rsp = requests.get(url=f'http://api.zanxiangnet.com/erp/api/user/subUser/3/{user_id}')
  6. nick_name_list = []
  7. for _ in rsp.json()['data']:
  8. nick_name_list.append(_['nickName'])
  9. return nick_name_list
  10. def get_auth_channel(user_id):
  11. """获取用户拥有的所有公众号权限"""
  12. db = MysqlUtils()
  13. # 普通权限------java,获取本人对应拥有的公众号
  14. rsp = requests.get(f'http://api.zanxiangnet.com/system/api/mp/mpAccount/subAccountWithUser/3/{user_id}')
  15. channel_list = rsp.json()['data']
  16. data1 = []
  17. if channel_list:
  18. for _ in channel_list:
  19. data1.append(_['nickName'])
  20. sql2 = f"""select GROUP_CONCAT(channel_ids) from user_channel_group_auth a
  21. left join channel_group b on a.channel_group_id=b.id
  22. where user_id={user_id}"""
  23. data2 = db.quchen_text.getOne(sql2)
  24. data3 = []
  25. if data2:
  26. rsp = requests.get('http://api.zanxiangnet.com/system/api/mp/mpAccount/search/3')
  27. channel_list = []
  28. channel_dict = {}
  29. for _ in rsp.json()['data']:
  30. channel_list.append((_['id'], _['nickName']))
  31. channel_dict[_['id']] = _['nickName']
  32. data2_2 = tuple(data2.split(','))
  33. for _ in data2_2:
  34. data3.append(channel_dict[int(_)])
  35. return tuple(data1 + data3)
  36. def get_auth_game_info(user_id):
  37. """获取用户拥有的所有用户拥有的游戏"""
  38. db = MysqlUtils()
  39. # 1.获取用户名字
  40. rsp = requests.get('http://api.zanxiangnet.com/erp/api/user/search/3?powerLevelMin=0')
  41. user_name = None
  42. for _ in rsp.json()['data']:
  43. if str(_['userId']) == str(user_id):
  44. user_name = _['nickName']
  45. # 2.获取所有游戏id
  46. sql = f'''
  47. SELECT d.id ,d.name,min(DATE_FORMAT(a.start_date,"%Y-%m-%d"))
  48. FROM quchen_text.advertiser_vx a
  49. left join db_mp.mp_mp_conf b on a.name =b.wx_name
  50. left join db_mp.mp_conf_agent c on c.advertiser_conf_id = b.id
  51. left join db_mp.h_game d on c.app_id = d.id
  52. where pitcher ='{user_name}' and d.id is not null
  53. group by id
  54. '''
  55. user_ids = db.quchen_text.get_data_list(sql)
  56. return user_ids
  57. def get_auth_game_name(user_id):
  58. """获取用户拥有的所有用户拥有的游戏"""
  59. db = MysqlUtils()
  60. # 1.获取用户名字
  61. rsp = requests.get('http://api.zanxiangnet.com/erp/api/user/search/3?powerLevelMin=0')
  62. user_name = None
  63. for _ in rsp.json()['data']:
  64. if str(_['userId']) == str(user_id):
  65. user_name = _['nickName']
  66. # 2.获取所有游戏id
  67. sql = f'''
  68. SELECT d.name
  69. FROM quchen_text.advertiser_vx a
  70. left join db_mp.mp_mp_conf b on a.name =b.wx_name
  71. left join db_mp.mp_conf_agent c on c.advertiser_conf_id = b.id
  72. left join db_mp.h_game d on c.app_id = d.id
  73. where pitcher ='{user_name}' and d.name is not null
  74. group by name
  75. '''
  76. user_ids = db.quchen_text.get_data_list(sql)
  77. return user_ids
  78. def super_auth():
  79. "获取超级数据权限的用户列表"
  80. rsp = requests.get('http://api.zanxiangnet.com/erp/api/user/search/3?powerLevelMin=99')
  81. user_list = []
  82. for _ in rsp.json()['data']:
  83. user_list.append(_['userId'])
  84. return user_list
  85. if __name__ == '__main__':
  86. # print(get_auth_channel(109))
  87. # print(get_role(78))
  88. # print(f"ssed{tuple([1, 3, 4])}")
  89. get_auth_game_name(196)