User.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. public static function modifyUserPidAndPath($uid, $pid, $newPathPrefix)
  22. {
  23. return Db::table(self::$table)
  24. ->where(['id' => $uid])
  25. ->update([
  26. 'pid' => $pid,
  27. 'path' => $newPathPrefix,
  28. 'update_time' => sr_getcurtime(time())
  29. ]);
  30. }
  31. public static function modifyUserPath($id, $newPath)
  32. {
  33. return Db::table(self::$table)
  34. ->where(['id' => $id])
  35. ->update([
  36. 'path' => $newPath,
  37. 'update_time' => sr_getcurtime(time())
  38. ]);
  39. }
  40. public static function UpdateUserMoney($id, $money)
  41. {
  42. return Db::table(self::$table)
  43. ->where(['id' => $id])
  44. ->update([
  45. 'money' => $money,
  46. 'update_time' => sr_getcurtime(time())
  47. ]);
  48. }
  49. public static function UpdateUserScore($id, $score)
  50. {
  51. return Db::table(self::$table)
  52. ->where(['id' => $id])
  53. ->update([
  54. 'score' => $score,
  55. 'update_time' => sr_getcurtime(time())
  56. ]);
  57. }
  58. public static function updateStatus($id, int $status)
  59. {
  60. return Db::table(self::$table)
  61. ->where(['id' => $id])
  62. ->update([
  63. 'status' => $status,
  64. 'update_time' => sr_getcurtime(time())
  65. ]);
  66. }
  67. public static function getUserOrEmptyById($id)
  68. {
  69. return (new UserModel())->findOrEmpty($id);
  70. }
  71. public static function update($id, $userData)
  72. {
  73. $userData['update_time'] = sr_getcurtime(time());
  74. return Db::table(self::$table)
  75. ->where(['id' => $id])
  76. ->update($userData);
  77. }
  78. public static function updateTotalTeamWithdraw($path, $apply_money)
  79. {
  80. Db::table(self::$table)->whereIn('id', $path)->inc('total_team_withdraw', $apply_money)->update();
  81. }
  82. public function getUserDetail($id)
  83. {
  84. return $this->model
  85. ->withJoin('userData', 'INNER')
  86. ->where('id', $id)
  87. ->find()
  88. ->toArray();
  89. }
  90. public function getCount($where, $userMap)
  91. {
  92. return $this->model
  93. ->withJoin('userData', 'INNER')
  94. ->where($where)
  95. ->where($userMap)
  96. ->count();
  97. }
  98. public function getPageList($page, $limit, $where, $sort, $userMap)
  99. {
  100. return $this->model
  101. ->withJoin('userData', 'INNER')
  102. ->where($where)
  103. ->where($userMap)
  104. ->page($page, $limit)
  105. ->order($sort)
  106. ->select();
  107. }
  108. }