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(); } }