Videolist.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace app\admin\controller\video;
  3. use app\common\controller\Backend;
  4. use fast\Tree;
  5. use think\Db;
  6. /**
  7. * 会员管理
  8. *
  9. * @icon fa fa-user
  10. */
  11. class Videolist extends Backend
  12. {
  13. protected $relationSearch = true;
  14. /**
  15. * @var \app\admin\model\User
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = model('Videolist');
  22. }
  23. /**
  24. * 查看
  25. */
  26. public function index()
  27. {
  28. //设置过滤方法
  29. $this->request->filter(['strip_tags']);
  30. if ($this->request->isAjax()) {
  31. //如果发送的来源是Selectpage,则转发到Selectpage
  32. if ($this->request->request('keyField')) {
  33. return $this->selectpage();
  34. }
  35. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  36. $map['bid']=$this->auth->id;
  37. $total = $this->model
  38. ->with('user')
  39. ->where($where)
  40. ->where($map)
  41. ->order($sort, $order)
  42. ->count();
  43. $list = $this->model
  44. ->with('user')
  45. ->where($where)
  46. ->where($map)
  47. ->order($sort, $order)
  48. ->limit($offset, $limit)
  49. ->select();
  50. foreach ($list as $k => &$v) {
  51. $groups = json_decode($v['type'],true);
  52. $arr=[];
  53. foreach ($groups as $k1=>$v1){
  54. $Category=model('Category')->where(['id'=>$v1])->find();
  55. $arr[$v1]=isset($Category['name'])?$Category['name']:'';
  56. }
  57. $list[$k]['type'] = implode(',', array_keys($arr));
  58. $list[$k]['type_text'] = implode(',', array_values($arr));
  59. }
  60. $result = array("total" => $total, "rows" => $list);
  61. return json($result);
  62. }
  63. //$dds=['1'=>'视频','2'=>'音频','3'=>'小说','4'=>'图片','5'=>'图文'];
  64. $dds=['1'=>'视频','4'=>'图片'];
  65. $this->view->assign("mimetypeList", $dds);
  66. return $this->view->fetch();
  67. }
  68. /**
  69. * 编辑
  70. */
  71. public function edit($ids = NULL)
  72. {
  73. $row = $this->model->get($ids);
  74. if (!$row)
  75. $this->error(__('No Results were found'));
  76. if ($this->request->isPost()) {
  77. $params = $this->request->post("row/a");
  78. if ($params) {
  79. if($params['lx']==1){
  80. $params['type']=json_encode($params['type']);
  81. $params['adddd']=json_encode($params['adddd']);
  82. }
  83. if($params['lx']==2){
  84. $params['type']=json_encode($params['type2']);
  85. }
  86. if($params['lx']==3){
  87. $params['type']=json_encode($params['type3']);
  88. }
  89. if($params['lx']==4){
  90. $params['type']=json_encode($params['type4']);
  91. }
  92. if($params['lx']==5){
  93. $params['type']=json_encode($params['type5']);
  94. }
  95. unset($params['type3']);
  96. unset($params['type2']);
  97. unset($params['type4']);
  98. unset($params['type5']);
  99. $result = $row->save($params);
  100. if ($result === false) {
  101. $this->error($this->model->getError());
  102. }
  103. $this->success();
  104. }else{
  105. $this->error();
  106. }
  107. }
  108. $this->view->assign('groupids', json_decode($row['type'],true));
  109. $this->view->assign('addddid', json_decode($row['adddd'],true));
  110. //$this->view->assign('yearqid', json_decode($row['yearq'],true));
  111. $this->view->assign('row', $row);
  112. $this->view->assign('groupdata', $this->fenlei('type'));
  113. $this->view->assign('adddddata', $this->fenlei('adddd'));
  114. $this->view->assign('yearqdata', $this->fenlei('year'));
  115. $this->view->assign('type2data', $this->fenlei('type2'));
  116. $this->view->assign('type3data', $this->fenlei('type3'));
  117. $this->view->assign('type4data', $this->fenlei('type4'));
  118. $this->view->assign('type5data', $this->fenlei('type5'));
  119. return $this->view->fetch();
  120. }
  121. public function add()
  122. {
  123. if ($this->request->isPost()) {
  124. $params = $this->request->post("row/a");
  125. if ($params) {
  126. if($params['lx']==1){
  127. $params['type']=json_encode($params['type']);
  128. $params['adddd']=json_encode($params['adddd']);
  129. }
  130. if($params['lx']==2){
  131. $params['type']=json_encode($params['type2']);
  132. }
  133. if($params['lx']==3){
  134. $params['type']=json_encode($params['type3']);
  135. }
  136. if($params['lx']==4){
  137. $params['type']=json_encode($params['type4']);
  138. }
  139. if($params['lx']==5){
  140. $params['type']=json_encode($params['type5']);
  141. }
  142. unset($params['type3']);
  143. unset($params['type2']);
  144. unset($params['type4']);
  145. unset($params['type5']);
  146. $result = $this->model->save($params);
  147. if ($result === false) {
  148. $this->error($this->model->getError());
  149. }
  150. $this->success();
  151. }else{
  152. $this->error();
  153. }
  154. }
  155. $this->view->assign('groupdata', $this->fenlei('type'));
  156. $this->view->assign('adddddata', $this->fenlei('adddd'));
  157. $this->view->assign('yearqdata', $this->fenlei('year'));
  158. $this->view->assign('type2data', $this->fenlei('type2'));
  159. $this->view->assign('type3data', $this->fenlei('type3'));
  160. $this->view->assign('type4data', $this->fenlei('type4'));
  161. $this->view->assign('type5data', $this->fenlei('type5'));
  162. $this->view->assign("id", $this->auth->id);
  163. return $this->view->fetch();
  164. }
  165. public function fenlei($tpie='type')
  166. {
  167. $tree = Tree::instance();
  168. $this->model = model('app\common\model\Category');
  169. $tree->init(collection($this->model->where(['type'=>$tpie])->order('weigh desc,id desc')->field('id,pid,name,nickname,image,type,flag')->select())->toArray(), 'pid');
  170. $fenlei = $tree->getTreeList($tree->getTreeArray(0), 'name');
  171. $groupdata=[];
  172. foreach ($fenlei as $k => $v) {
  173. $groupdata[$v['id']] = $v['name'];
  174. }
  175. return $groupdata;
  176. }
  177. }