model = new \app\common\model\Income; // 获取短剧和平台数据(用于下拉框) // $videolist = Videolist::column('id,name'); // $platforms = Platform::column('id,name'); // $this->assign('videolist', $videolist); // $this->assign('platforms', $platforms); } // 列表页 // application/admin/controller/platform/Income.php public function index() { $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { list($where, $sort, $order, $offset, $limit) = $this->buildparams(); // 强制指定排序字段别名 // if ($sort === 'id') { // $sort = 'video_platform.id'; // } $total = $this->model ->with('videolist') ->where($where) ->order($sort, $order) ->count(); $list = $this->model ->with('videolist') ->where($where) ->order($sort, $order) ->limit($offset, $limit) ->select(); $result = ["total" => $total, "rows" => $list]; return json($result); } return $this->view->fetch(); } // 添加 public function add() { if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { $result = $this->model->save($params); if ($result) $this->success(); $this->error(__('操作失败')); } $this->error(__('参数错误')); } return $this->view->fetch(); } // 编辑 public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) $this->error(__('记录不存在')); if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { $result = $row->save($params); if ($result) $this->success(); $this->error(__('操作失败')); } $this->error(__('参数错误')); } $this->assign('row', $row); return $this->view->fetch(); } }