User.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 static function modifyUserPidAndPathByPid($uid, int $pid, string $path)
  83. {
  84. return Db::table(self::$table)
  85. ->where(['pid' => $uid])
  86. ->update([
  87. 'pid' => $pid,
  88. 'path' => $path,
  89. 'update_time' => sr_getcurtime(time())
  90. ]);
  91. }
  92. public function getUserDetail($id)
  93. {
  94. return $this->model
  95. ->withJoin('userData', 'INNER')
  96. ->where('id', $id)
  97. ->find()
  98. ->toArray();
  99. }
  100. public function getCount($where, $userMap)
  101. {
  102. return $this->model
  103. ->withJoin('userData', 'INNER')
  104. ->where($where)
  105. ->where($userMap)
  106. ->count();
  107. }
  108. public function getPageList($page, $limit, $where, $sort, $userMap)
  109. {
  110. return $this->model
  111. ->withJoin('userData', 'INNER')
  112. ->where($where)
  113. ->where($userMap)
  114. ->page($page, $limit)
  115. ->order($sort)
  116. ->select();
  117. }
  118. }