UserAuthUtils.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 ,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}'
  53. group by id
  54. '''
  55. user_ids = db.quchen_text.get_data_list(sql)
  56. return user_ids
  57. def super_auth():
  58. "获取超级数据权限的用户列表"
  59. rsp = requests.get('http://api.zanxiangnet.com/erp/api/user/search/3?powerLevelMin=99')
  60. user_list = []
  61. for _ in rsp.json()['data']:
  62. user_list.append(_['userId'])
  63. return user_list
  64. if __name__ == '__main__':
  65. # print(get_auth_channel(109))
  66. # print(get_role(78))
  67. # print(f"ssed{tuple([1, 3, 4])}")
  68. get_auth_game(85)