getModel()::where($this->getPk(),$id); if($type == 1) $query->inc('share_num',$inc)->update(); if($type == 2) $query->inc('view_num',$inc)->update(); }catch (Exception $exception){ } } public function userCount() { $count = $this->getModel()::getDB()->count("*"); $res = $this->getModel()::getDB()->order('create_time DESC')->with(['user' => function($query){ $query->field('uid,avatar avatar_img'); }])->limit(10)->group('uid')->select()->toArray(); $list = []; foreach ($res as $item){ if($item['user']['avatar_img']){ $list[] = $item['user']; } } return compact('count','list'); } /** * TODO 更新状态 * @param int $id * @author Qinii * @day 2020-11-25 */ public function changStatus(int $id) { $this->getModel()::getDB()->where($this->getPk(),$id)->update(['status' => 20]); } }