Income.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 Income extends Backend
  7. {
  8. protected $model = null;
  9. public function _initialize()
  10. {
  11. parent::_initialize();
  12. $this->model = new \app\common\model\Income;
  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/Income.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')
  32. ->where($where)
  33. ->order($sort, $order)
  34. ->count();
  35. $list = $this->model
  36. ->with('videolist')
  37. ->where($where)
  38. ->order($sort, $order)
  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. public function add()
  48. {
  49. if ($this->request->isPost()) {
  50. $params = $this->request->post("row/a");
  51. if ($params) {
  52. $result = $this->model->save($params);
  53. if ($result) $this->success();
  54. $this->error(__('操作失败'));
  55. }
  56. $this->error(__('参数错误'));
  57. }
  58. return $this->view->fetch();
  59. }
  60. // 编辑
  61. public function edit($ids = null)
  62. {
  63. $row = $this->model->get($ids);
  64. if (!$row) $this->error(__('记录不存在'));
  65. if ($this->request->isPost()) {
  66. $params = $this->request->post("row/a");
  67. if ($params) {
  68. $result = $row->save($params);
  69. if ($result) $this->success();
  70. $this->error(__('操作失败'));
  71. }
  72. $this->error(__('参数错误'));
  73. }
  74. $this->assign('row', $row);
  75. return $this->view->fetch();
  76. }
  77. }