User.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. /**
  59. * 更新用户绿色积分 by wes
  60. * @param $id
  61. * @param $score
  62. * @return int
  63. * @throws \think\db\exception\DbException
  64. */
  65. public static function UpdateUserGreenScore($id, $score)
  66. {
  67. return Db::table(self::$table)
  68. ->where(['id' => $id])
  69. ->update([
  70. 'green_score' => $score,
  71. 'update_time' => sr_getcurtime(time())
  72. ]);
  73. }
  74. public static function updateStatus($id, int $status)
  75. {
  76. return Db::table(self::$table)
  77. ->where(['id' => $id])
  78. ->update([
  79. 'status' => $status,
  80. 'update_time' => sr_getcurtime(time())
  81. ]);
  82. }
  83. public static function getUserOrEmptyById($id)
  84. {
  85. return (new UserModel())->findOrEmpty($id);
  86. }
  87. public static function update($id, $userData)
  88. {
  89. $userData['update_time'] = sr_getcurtime(time());
  90. return Db::table(self::$table)
  91. ->where(['id' => $id])
  92. ->update($userData);
  93. }
  94. public static function updateTotalTeamWithdraw($path, $apply_money)
  95. {
  96. Db::table(self::$table)->whereIn('id', $path)->inc('total_team_withdraw', $apply_money)->update();
  97. }
  98. public static function modifyUserPidAndPathByPid($uid, int $pid, string $path)
  99. {
  100. return Db::table(self::$table)
  101. ->where(['pid' => $uid])
  102. ->update([
  103. 'pid' => $pid,
  104. 'path' => $path,
  105. 'update_time' => sr_getcurtime(time())
  106. ]);
  107. }
  108. public function getUserDetail($id)
  109. {
  110. return $this->model
  111. ->withJoin('userData', 'INNER')
  112. ->where('id', $id)
  113. ->find()
  114. ->toArray();
  115. }
  116. public function getCount($where, $userMap)
  117. {
  118. return $this->model
  119. ->withJoin('userData', 'INNER')
  120. ->where($where)
  121. ->where($userMap)
  122. ->count();
  123. }
  124. public function getPageList($page, $limit, $where, $sort, $userMap)
  125. {
  126. return $this->model
  127. ->withJoin('userData', 'INNER')
  128. ->where($where)
  129. ->where($userMap)
  130. ->page($page, $limit)
  131. ->order($sort)
  132. ->select();
  133. }
  134. }