UserPlatform.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\model;
  3. use\think\Model;
  4. use think\Session;
  5. use think\cache\driver\Redis;
  6. use think\Loader;
  7. use think\Cache;
  8. class UserPlatform extends Model
  9. {
  10. /**
  11. * 平台用户
  12. */
  13. public function userList()
  14. {
  15. $code = -2;
  16. $limit = (input('pageSize') ?? 10);
  17. $currentPage = (input('currentPage') ?? 1);
  18. $platformId = input('id');
  19. $getData = [
  20. 'platform_id' => $platformId,
  21. 'pageSize' => $limit,
  22. 'currentPage' => $currentPage,
  23. ];
  24. // 验证传参.
  25. $validate = Loader::validate('UserPlatform');
  26. if (!$validate->scene('userList')->check($getData)) {
  27. return [
  28. 'code' => $code,
  29. 'msg' => $validate->getError(),
  30. 'data' => [],
  31. ];
  32. }
  33. // 查询平台用户.
  34. $offset = (($currentPage - 1) * $limit);
  35. $where = [
  36. 'platform_id' => $platformId,
  37. 'user_status' => 1,
  38. ];
  39. $file = ['platform_user', 'user_name', 'user_platform_rtime', 'user_platform_rip', 'user_platform_id', 'user_nickname', 'user_full_name', 'user_email', 'user_phone'];
  40. $userList = $this
  41. ->field($file)
  42. ->alias('a')
  43. ->join('user b', 'a.user_identity = b.user_identity')
  44. ->where($where)
  45. ->limit($offset, $limit)
  46. ->select();
  47. // 查询总数.
  48. $userCount = $this
  49. ->alias('a')
  50. ->join('user b', 'a.user_identity = b.user_identity')
  51. ->where($where)
  52. ->count();
  53. // 分页.
  54. $page = getPage($userCount, $limit, $currentPage);
  55. return [
  56. 'code' => 1,
  57. 'msg' => lang('MC01005'),
  58. 'data' => [
  59. 'userList' => $userList,
  60. 'userCount' => $userCount,
  61. 'currentPage' => $currentPage,
  62. 'page' => $page,
  63. ],
  64. ];
  65. }//end userList()
  66. /**
  67. * 删除用户平台关联
  68. */
  69. public function deleteUser()
  70. {
  71. $code = -2;
  72. $userPlatformId = input('id');
  73. $getData = ['user_platform_id' => $userPlatformId];
  74. // 验证传参.
  75. $validate = Loader::validate('UserPlatform');
  76. if (!$validate->scene('deleteUser')->check($getData)) {
  77. return [
  78. 'code' => $code,
  79. 'msg' => $validate->getError(),
  80. 'data' => [],
  81. ];
  82. }
  83. // 查询平台用户.
  84. $where = ['user_platform_id' => $userPlatformId];
  85. $this->where($where)->delete();
  86. return [
  87. 'code' => 1,
  88. 'msg' => lang('MC01005'),
  89. 'data' => [],
  90. ];
  91. }//end deleteUser()
  92. }