model = new \app\common\model\VideoPlatform; // 获取短剧和平台数据(用于下拉框) // $videolist = Videolist::column('id,name'); // $platforms = Platform::column('id,name'); // $this->assign('videolist', $videolist); // $this->assign('platforms', $platforms); } // 列表页 // application/admin/controller/platform/Vplatform.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,platform') ->where($where) ->order($sort) ->count(); $list = $this->model ->with('videolist,platform') ->where($where) ->order($sort) ->limit($offset, $limit) ->select(); $result = ["total" => $total, "rows" => $list]; return json($result); } return $this->view->fetch(); } /** * 编辑 */ public function edit($ids = NULL) { $row = $this->model->get($ids); if (!$row) $this->error(__('No Results were found')); return parent::edit($ids); } public function add() { return parent::add(); } public function dragsort() { if ($this->request->isPost()) { $ids = $this->request->post('ids'); // 根据 $ids 更新排序逻辑(示例代码) foreach ($ids as $index => $id) { $this->model::where('id', $id)->update(['sort' => $index + 1]); } $this->success(); } $this->error(__('参数错误')); } // // 添加 // 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(); // } }