UserVote.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\models\vote;
  3. use app\models\user\User;
  4. use crmeb\basic\BaseModel;
  5. use crmeb\traits\ModelTrait;
  6. class UserVote extends BaseModel
  7. {
  8. /**
  9. * 数据表主键
  10. * @var string
  11. */
  12. protected $pk = 'id';
  13. /**
  14. * 模型名称
  15. * @var string
  16. */
  17. protected $name = 'user_vote';
  18. use ModelTrait;
  19. /**
  20. * @param $where
  21. * @return array
  22. */
  23. public static function getUserList($where)
  24. {
  25. $model = self::group('uid')->field('uid,sum(vote_num) as money');
  26. if (isset($where['id']) && $where['id']) $model = $model->where('sub_vote_id', $where['id']);
  27. $count = $model->count();
  28. $data = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
  29. $item['user'] = User::getUserInfo($item['uid']);
  30. });
  31. return compact('count', 'data');
  32. }
  33. /**
  34. * @param $where
  35. * @return array
  36. */
  37. public static function getOneUserList($where)
  38. {
  39. $model = self::where('uid', $where['uid'])->order('add_time', 'desc')->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
  40. $item['vote'] = VoteSub::get($item['sub_vote_id']);
  41. $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  42. });
  43. return $model;
  44. }
  45. }