Videoplatform.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\admin\controller\platform;
  3. use app\common\controller\Backend;
  4. use app\common\model\Videolist;
  5. use app\common\model\Platform;
  6. class Videoplatform extends Backend
  7. {
  8. protected $model = null;
  9. public function _initialize()
  10. {
  11. parent::_initialize();
  12. $this->model = new \app\common\model\VideoPlatform;
  13. // 获取短剧和平台数据(用于下拉框)
  14. // $videolist = Videolist::column('id,name');
  15. // $platforms = Platform::column('id,name');
  16. // $this->assign('videolist', $videolist);
  17. // $this->assign('platforms', $platforms);
  18. }
  19. // 列表页
  20. // application/admin/controller/platform/Videoplatform.php
  21. public function index()
  22. {
  23. $this->request->filter(['strip_tags']);
  24. if ($this->request->isAjax()) {
  25. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  26. // 强制指定排序字段别名
  27. if ($sort === 'id') {
  28. $sort = 'video_platform.id';
  29. }
  30. $total = $this->model
  31. ->with('videolist,platform')
  32. ->where($where)
  33. ->order($sort)
  34. ->count();
  35. $list = $this->model
  36. ->with('videolist,platform')
  37. ->where($where)
  38. ->order($sort)
  39. ->limit($offset, $limit)
  40. ->select();
  41. $result = ["total" => $total, "rows" => $list];
  42. return json($result);
  43. }
  44. return $this->view->fetch();
  45. }
  46. /**
  47. * 编辑
  48. */
  49. public function edit($ids = NULL)
  50. {
  51. $row = $this->model->get($ids);
  52. if (!$row)
  53. $this->error(__('No Results were found'));
  54. return parent::edit($ids);
  55. }
  56. public function add()
  57. {
  58. return parent::add();
  59. }
  60. // // 添加
  61. // public function add()
  62. // {
  63. // if ($this->request->isPost()) {
  64. // $params = $this->request->post("row/a");
  65. // if ($params) {
  66. // $result = $this->model->save($params);
  67. // if ($result) $this->success();
  68. // $this->error(__('操作失败'));
  69. // }
  70. // $this->error(__('参数错误'));
  71. // }
  72. // return $this->view->fetch();
  73. // }
  74. //
  75. // // 编辑
  76. // public function edit($ids = null)
  77. // {
  78. // $row = $this->model->get($ids);
  79. // if (!$row) $this->error(__('记录不存在'));
  80. // if ($this->request->isPost()) {
  81. // $params = $this->request->post("row/a");
  82. // if ($params) {
  83. // $result = $row->save($params);
  84. // if ($result) $this->success();
  85. // $this->error(__('操作失败'));
  86. // }
  87. // $this->error(__('参数错误'));
  88. // }
  89. // $this->assign('row', $row);
  90. // return $this->view->fetch();
  91. // }
  92. }