User.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace app\admin\model\dao;
  3. use app\common\model\UserModel;
  4. use think\facade\Db;
  5. class User extends BaseDao
  6. {
  7. protected $model;
  8. public static $table = "db_user";
  9. public function __construct()
  10. {
  11. $this->model = new UserModel();
  12. }
  13. public static function getUserById($uid)
  14. {
  15. return Db::table(self::$table)->where(['id' => $uid])->find();
  16. }
  17. public static function getUserByMobile($mobile)
  18. {
  19. return Db::table(self::$table)->where('mobile', $mobile)->find();
  20. }
  21. /**
  22. * 修改手机号码的时候同时修改用户名
  23. * @param $uid
  24. * @param $phone
  25. * @return int
  26. * @throws \think\db\exception\DbException
  27. */
  28. public static function ModifyMobile($uid, $phone)
  29. {
  30. return Db::table(self::$table)
  31. ->where(['id' => $uid])
  32. ->update([
  33. 'mobile' => $phone,
  34. 'user_name' => $phone,
  35. 'update_time' => date('Y-m-d H:i:s')
  36. ]);
  37. }
  38. public static function modifyUserPidAndPath($uid, $pid, $newPathPrefix)
  39. {
  40. return Db::table(self::$table)
  41. ->where(['id' => $uid])
  42. ->update([
  43. 'pid' => $pid,
  44. 'path' => $newPathPrefix,
  45. 'update_time' => date('Y-m-d H:i:s')
  46. ]);
  47. }
  48. public static function modifyUserPath($id, $newPath)
  49. {
  50. return Db::table(self::$table)
  51. ->where(['id' => $id])
  52. ->update([
  53. 'path' => $newPath,
  54. 'update_time' => date('Y-m-d H:i:s')
  55. ]);
  56. }
  57. public static function UpdateUserMoney($id, $money)
  58. {
  59. return Db::table(self::$table)
  60. ->where(['id' => $id])
  61. ->update([
  62. 'money' => $money,
  63. 'update_time' => date('Y-m-d H:i:s')
  64. ]);
  65. }
  66. public static function UpdateUserScore($id, $score)
  67. {
  68. return Db::table(self::$table)
  69. ->where(['id' => $id])
  70. ->update([
  71. 'score' => $score,
  72. 'update_time' => date('Y-m-d H:i:s')
  73. ]);
  74. }
  75. public static function updateState($id, int $status)
  76. {
  77. return Db::table(self::$table)
  78. ->where(['id' => $id])
  79. ->update([
  80. 'status' => $status,
  81. 'update_time' => date('Y-m-d H:i:s')
  82. ]);
  83. }
  84. public function getCount($where, $userMap)
  85. {
  86. return $this->model
  87. ->withJoin('userData', 'INNER')
  88. ->where($where)
  89. ->where($userMap)
  90. ->count();
  91. }
  92. public function getPageList($page, $limit, $where, $sort, $userMap)
  93. {
  94. return $this->model
  95. ->withJoin('userData', 'INNER')
  96. ->where($where)
  97. ->where($userMap)
  98. ->page($page, $limit)
  99. ->order($sort)
  100. ->select();
  101. }
  102. }