isAjax()) { if (input('selectFields')) return $this->selectList(); list($page, $limit, $where) = $this->buildTableParams(); $count = self::$model::where($where)->count(); $list = self::$model::where($where)->page($page, $limit)->order($this->sort)->select()->toArray(); $data = [ 'code' => 0, 'msg' => '', 'count' => $count, 'data' => $list, ]; return json($data); } return $this->fetch(); } #[NodeAnnotation(title: '确认支付成功', auth: true)] public function recharge(Request $request, $id): string { $row = self::$model::find($id); empty($row) && $this->error('数据不存在'); if ($request->isPost()) { $post = $request->post(); try { $post['status'] = 2; $save = $row->save($post); }catch (\Exception $e) { $this->error('保存失败'); } $save ? $this->success('确认支付成功') : $this->error('保存失败'); } } #[NodeAnnotation(title: '编辑', auth: true)] public function edit(Request $request, $id = 0): string { $row = self::$model::find($id); empty($row) && $this->error('数据不存在'); if ($request->isPost()) { $post = $request->post(); $rule = []; $this->validate($post, $rule); try { Db::transaction(function() use ($post, $row, &$save) { $post['status'] = 1; $save = $row->save($post); }); }catch (\Exception $e) { $this->error('保存失败'); } $save ? $this->success('保存成功') : $this->error('保存失败'); } $this->assign('row', $row); return $this->fetch(); } #[NodeAnnotation(title: 'IP拉黑', auth: true)] public function blockip(Request $request, $id): string { $row = self::$model::find($id); empty($row) && $this->error('数据不存在'); if ($request->isPost()) { try { $save = (new \app\admin\model\BlackIp())->save([ 'ip' => $row->ip, ]); }catch (\Exception $e) { $this->error('保存失败'); } $save ? $this->success('IP拉黑成功') : $this->error('保存失败'); } } #[MiddlewareAnnotation(ignore: MiddlewareAnnotation::IGNORE_LOGIN)] public function no_check_login(Request $request): string { return '这里演示方法不需要经过登录验证'; } }