dao = $dao; } /** * @param $merId * @param array $where * @param $page * @param $limit * @return array * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author zfy * @day 2020-04-16 */ public function lst($merId, array $where, $page, $limit) { $query = $this->dao->search($where, $merId); $count = $query->count($this->dao->getPk()); $list = $query->setOption('field', [])->field(['create_time', 'log_id', 'admin_name', 'route', 'method', 'url', 'ip', 'admin_id']) ->page($page, $limit)->order('create_time DESC')->select(); return compact('count', 'list'); } /** * @param Request $request * @param int $merId * @return BaseDao|Model * @author zfy * @day 2020-04-15 */ public function addLog(Request $request, int $merId = 0) { return $this->create($merId, self::parse($request)); } /** * @param int $merId * @param array $data * @return BaseDao|Model * @author zfy * @day 2020-04-16 */ public function create(int $merId, array $data) { $data['mer_id'] = $merId; return $this->dao->create($data); } /** * @param Request $request * @return array * @author zfy * @day 2020-04-16 */ public static function parse(Request $request) { return [ 'admin_id' => $request->adminId(), 'admin_name' => $request->adminInfo()->real_name ?: '未定义', 'route' => $request->rule()->getName(), 'ip' => $request->ip(), 'url' => $request->url(true), 'method' => $request->method() ]; } }