UserDao.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\extra\dao\user;
  3. use app\extra\basic\Dao;
  4. use app\model\user\User;
  5. class UserDao extends Dao
  6. {
  7. /**
  8. * 设置模型
  9. * @return string
  10. */
  11. protected function setModel(): string
  12. {
  13. return User::class;
  14. }
  15. public function getList(array $where,string $field = '*',int $page = 0, int $limit = 0,string $order='id desc')
  16. {
  17. return $this->getModel()->where($where)->field($field)->when($page&&$limit,function($query)use($page,$limit){
  18. $query->page($page,$limit);
  19. })->with(['level'=>function ($query) {
  20. $query->field('id,name');
  21. }])->select();
  22. }
  23. /**
  24. * 排行榜列表
  25. * @param array $where
  26. * @param string $field
  27. * @param int $type
  28. * @return \think\Collection
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function getRank(array $where,string $field = '*',int $type=1)
  34. {
  35. return $this->getModel()->where($where)->field($field)->page(1,15)
  36. ->when($type==1,function($query){
  37. $query->withCount(['cutterOrder'=>function($query){
  38. $query->where('status',3);
  39. }])->having('cutter_order_count > 0')->order('cutter_order_count desc');
  40. })
  41. ->when($type==2,function($query){
  42. $query->withSum(['brokerage'=>function($query){
  43. $query->where('pm',1)->where('type','not in',['extract_fail']);
  44. }],'number')->having('brokerage_sum > 0')->order('brokerage_sum desc');
  45. })->select();
  46. }
  47. /**
  48. * 查询一条排行榜数据
  49. * @param array $where
  50. * @param string $field
  51. * @param int $type
  52. * @return \think\Collection
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public function getSelfRank(array $where,string $field = '*',int $type=1)
  58. {
  59. return $this->getModel()->where($where)->field($field)->page(1,15)
  60. ->when($type==1,function($query){
  61. $query->withCount(['cutterOrder'=>function($query){
  62. $query->where('status',3);
  63. }]);
  64. })
  65. ->when($type==2,function($query){
  66. $query->withSum(['brokerage'=>function($query){
  67. $query->where('pm',1)->where('type','not in',['extract_fail']);
  68. }],'number');
  69. })->findOrEmpty();
  70. }
  71. }