| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\admin\controller\platform;
- use app\common\controller\Backend;
- use app\common\model\Videolist;
- use app\common\model\Platform;
- class Income extends Backend
- {
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->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', 'platform'])
- ->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->with(['videolist', 'platform'])
- ->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();
- }
- }
|