Vplatform.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\admin\controller\platform;
  3. use app\common\controller\Backend;
  4. /**
  5. * 第三方平台列表
  6. *
  7. */
  8. class Vplatform extends Backend
  9. {
  10. protected $relationSearch = true;
  11. protected $model = null;
  12. public function _initialize()
  13. {
  14. parent::_initialize();
  15. // $this->model = new \app\admin\model\third\Platform;
  16. $this->model = new \app\common\model\VideoPlatform;
  17. // $this->model = model('platform');
  18. $videolist=[];
  19. $platformlist=[];
  20. $video=model('videolist')->field('id,name')->select();
  21. foreach ($video as $k => $v){
  22. $videolist[$v['id']]=$v['name'];
  23. }
  24. $platform=model('platform')->field('id,name')->select();
  25. foreach ($platform as $k => $v){
  26. $platformlist[$v['id']]=$v['name'];
  27. }
  28. $this->view->assign('videolist', $videolist);
  29. $this->view->assign('platformlist', $platformlist);
  30. }
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags']);
  38. if ($this->request->isAjax()) {
  39. //如果发送的来源是Selectpage,则转发到Selectpage
  40. if ($this->request->request('keyField')) {
  41. return $this->selectpage();
  42. }
  43. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  44. $total = $this->model
  45. ->where($where)
  46. ->order($sort, $order)
  47. ->count();
  48. $list = $this->model
  49. ->where($where)
  50. ->with('platform,videolist')
  51. ->order($sort, $order)
  52. ->limit($offset, $limit)
  53. ->select();
  54. $result = array("total" => $total, "rows" => $list);
  55. return json($result);
  56. }
  57. return $this->view->fetch();
  58. }
  59. /**
  60. * 编辑
  61. */
  62. public function edit($ids = NULL)
  63. {
  64. $row = $this->model->get($ids);
  65. if (!$row){
  66. $this->error(__('No Results were found'));
  67. }
  68. if ($this->request->isPost()) {
  69. $params = $this->request->post("row/a");
  70. // if($params['max']<$params['min']){
  71. // $this->error('最大值不能小于最小值');
  72. // }
  73. if ($params['dividend']<0){
  74. $this->error('分红金额不能小于0');
  75. }
  76. }
  77. $vid = $this->model->where('id', $ids)->value('vid');
  78. $platform_id = $this->model->where('id', $ids)->value('platform_id');
  79. $this->view->assign("vid", $vid);
  80. $this->view->assign("platform_id", $platform_id);
  81. return parent::edit($ids);
  82. }
  83. public function add($vid=0,$platform_id=0)
  84. {
  85. if ($this->request->isPost()) {
  86. $params = $this->request->post("row/a");
  87. $vid = $this->request->post("vid");
  88. $platform_id = $this->request->post("platform_id");
  89. if ($params) {
  90. $params['vid'] = $vid;
  91. $params['platform_id'] = $platform_id;
  92. if ($this->model->where('vid', $vid)->where('platform_id', $platform_id)->find()){
  93. $this->error('该平台收益已设置');
  94. }
  95. // if($params['max']<$params['min']){
  96. // $this->error('最大值不能小于最小值');
  97. // }
  98. if ($params['dividend']<0){
  99. $this->error('分红金额不能小于0');
  100. }
  101. $params['vname'] = model('videolist')->where('id', $params['vid'])->value('name');
  102. $params['pname'] = model('platform')->where('id', $params['platform_id'])->value('name');
  103. $result = $this->model->save($params);
  104. if ($result === false) {
  105. $this->error($this->model->getError());
  106. }
  107. $this->success();
  108. }else{
  109. $this->error();
  110. }
  111. }
  112. return $this->view->fetch();
  113. }
  114. }