Vplatform.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 Vplatform 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/Vplatform.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. public function dragsort()
  61. {
  62. if ($this->request->isPost()) {
  63. $ids = $this->request->post('ids');
  64. // 根据 $ids 更新排序逻辑(示例代码)
  65. foreach ($ids as $index => $id) {
  66. $this->model::where('id', $id)->update(['sort' => $index + 1]);
  67. }
  68. $this->success();
  69. }
  70. $this->error(__('参数错误'));
  71. }
  72. // // 添加
  73. // public function add()
  74. // {
  75. // if ($this->request->isPost()) {
  76. // $params = $this->request->post("row/a");
  77. // if ($params) {
  78. // $result = $this->model->save($params);
  79. // if ($result) $this->success();
  80. // $this->error(__('操作失败'));
  81. // }
  82. // $this->error(__('参数错误'));
  83. // }
  84. // return $this->view->fetch();
  85. // }
  86. //
  87. // // 编辑
  88. // public function edit($ids = null)
  89. // {
  90. // $row = $this->model->get($ids);
  91. // if (!$row) $this->error(__('记录不存在'));
  92. // if ($this->request->isPost()) {
  93. // $params = $this->request->post("row/a");
  94. // if ($params) {
  95. // $result = $row->save($params);
  96. // if ($result) $this->success();
  97. // $this->error(__('操作失败'));
  98. // }
  99. // $this->error(__('参数错误'));
  100. // }
  101. // $this->assign('row', $row);
  102. // return $this->view->fetch();
  103. // }
  104. }