Income.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. public function index()
  21. {
  22. $this->request->filter(['strip_tags']);
  23. if ($this->request->isAjax()) {
  24. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  25. $total = $this->model
  26. ->with(['videolist', 'platform'])
  27. ->where($where)
  28. ->order($sort, $order)
  29. ->count();
  30. $list = $this->model
  31. ->with(['videolist', 'platform'])
  32. ->where($where)
  33. ->order($sort, $order)
  34. ->limit($offset, $limit)
  35. ->select();
  36. $result = ["total" => $total, "rows" => $list];
  37. return json($result);
  38. }
  39. return $this->view->fetch();
  40. }
  41. // 添加
  42. public function add()
  43. {
  44. if ($this->request->isPost()) {
  45. $params = $this->request->post("row/a");
  46. if ($params) {
  47. $result = $this->model->save($params);
  48. if ($result) $this->success();
  49. $this->error(__('操作失败'));
  50. }
  51. $this->error(__('参数错误'));
  52. }
  53. return $this->view->fetch();
  54. }
  55. // 编辑
  56. public function edit($ids = null)
  57. {
  58. $row = $this->model->get($ids);
  59. if (!$row) $this->error(__('记录不存在'));
  60. if ($this->request->isPost()) {
  61. $params = $this->request->post("row/a");
  62. if ($params) {
  63. $result = $row->save($params);
  64. if ($result) $this->success();
  65. $this->error(__('操作失败'));
  66. }
  67. $this->error(__('参数错误'));
  68. }
  69. $this->assign('row', $row);
  70. return $this->view->fetch();
  71. }
  72. }