Users.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class Users extends Model
  5. {
  6. protected $connection = 'mysql';
  7. protected $pk = 'id';
  8. protected $name = 'user';
  9. function roles()
  10. {
  11. return $this->hasOne(UsersRoles::class, 'id', 'role_id');
  12. }
  13. public static function getusername($uuid)
  14. {
  15. $user = self::where('uuid', $uuid)->find();
  16. return $user->username;
  17. }
  18. public static function getuserbyuuid($uuid)
  19. {
  20. $user = self::where('uuid', $uuid)->find();
  21. if (!empty($user)) {
  22. $user = $user->toArray();
  23. }
  24. return $user;
  25. }
  26. public static function getDepart($did)
  27. {
  28. $uidlist = self::field('id,username')->where(['did' => $did])
  29. ->order('id asc')
  30. ->select()
  31. ->toArray();
  32. foreach ($uidlist as $vo) {
  33. if (empty($uidliststr)) {
  34. $uidliststr = $vo['id'];
  35. } else {
  36. $uidliststr .= ',' . $vo['id'];
  37. }
  38. }
  39. if (!empty($uidliststr)) {
  40. return explode(',', $uidliststr);
  41. }
  42. }
  43. public static function getuserbyuid($uid)
  44. {
  45. $userarray = self::where(['uid' => $uid, 'weid' => weid()])->find();
  46. if ($userarray) {
  47. $userarray = $userarray->toArray();
  48. }
  49. return $userarray;
  50. }
  51. public static function getadminbyopenid()
  52. {
  53. if (!empty(getFans()['openid'])) {
  54. $uuid = UuidRelation::getuuid(UID(), 'admin');
  55. if (!empty($uuid)) {
  56. $userarray = self::where(['uuid' => $uuid, 'weid' => weid()])->find();
  57. if ($userarray) {
  58. $userarray = $userarray->toArray();
  59. $UsersRoles = UsersRoles::getinfo($userarray);
  60. $userarray['UsersRoles'] = $UsersRoles;
  61. }
  62. }
  63. }
  64. return $userarray;
  65. }
  66. public static function getallarray()
  67. {
  68. $list = self::field('id,username')
  69. ->order('id asc')
  70. ->select()
  71. ->toArray();
  72. $array = [];
  73. foreach ($list as $k => $v) {
  74. $array[$k]['val'] = $v['id'];
  75. $array[$k]['key'] = $v['username'];
  76. }
  77. return $array;
  78. }
  79. }