Vplatform.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. $vid = $this->model->where('id', $ids)->value('vid');
  68. $platform_id = $this->model->where('id', $ids)->value('platform_id');
  69. $this->view->assign("vid", $vid);
  70. $this->view->assign("platform_id", $platform_id);
  71. return parent::edit($ids);
  72. }
  73. public function add($vid=0,$platform_id=0)
  74. {
  75. if ($this->request->isPost()) {
  76. $params = $this->request->post("row/a");
  77. if ($params) {
  78. $params['vname'] = model('videolist')->where('id', $params['vid'])->value('name');
  79. $params['pname'] = model('platform')->where('id', $params['platform_id'])->value('name');
  80. $result = $this->model->save($params);
  81. if ($result === false) {
  82. $this->error($this->model->getError());
  83. }
  84. $this->success();
  85. }else{
  86. $this->error();
  87. }
  88. }
  89. return $this->view->fetch();
  90. }
  91. }