| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace app\extra\dao\user;
- use app\extra\basic\Dao;
- use app\model\user\User;
- class UserDao extends Dao
- {
- /**
- * 设置模型
- * @return string
- */
- protected function setModel(): string
- {
- return User::class;
- }
- public function getList(array $where,string $field = '*',int $page = 0, int $limit = 0,string $order='id desc')
- {
- return $this->getModel()->where($where)->field($field)->when($page&&$limit,function($query)use($page,$limit){
- $query->page($page,$limit);
- })->with(['level'=>function ($query) {
- $query->field('id,name');
- }])->select();
- }
- /**
- * 排行榜列表
- * @param array $where
- * @param string $field
- * @param int $type
- * @return \think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getRank(array $where,string $field = '*',int $type=1)
- {
- return $this->getModel()->where($where)->field($field)->page(1,15)
- ->when($type==1,function($query){
- $query->withCount(['cutterOrder'=>function($query){
- $query->where('status',3);
- }])->having('cutter_order_count > 0')->order('cutter_order_count desc');
- })
- ->when($type==2,function($query){
- $query->withSum(['brokerage'=>function($query){
- $query->where('pm',1)->where('type','not in',['extract_fail']);
- }],'number')->having('brokerage_sum > 0')->order('brokerage_sum desc');
- })->select();
- }
- /**
- * 查询一条排行榜数据
- * @param array $where
- * @param string $field
- * @param int $type
- * @return \think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getSelfRank(array $where,string $field = '*',int $type=1)
- {
- return $this->getModel()->where($where)->field($field)->page(1,15)
- ->when($type==1,function($query){
- $query->withCount(['cutterOrder'=>function($query){
- $query->where('status',3);
- }]);
- })
- ->when($type==2,function($query){
- $query->withSum(['brokerage'=>function($query){
- $query->where('pm',1)->where('type','not in',['extract_fail']);
- }],'number');
- })->findOrEmpty();
- }
- }
|