Video.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 视频专区
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Video extends Backend
  11. {
  12. /**
  13. * Video模型对象
  14. * @var \app\admin\model\Video
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Video;
  21. $this->view->assign("isPayList", $this->model->getIsPayList());
  22. $this->view->assign("statusList", $this->model->getStatusList());
  23. }
  24. /**
  25. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  26. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  27. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  28. */
  29. /**
  30. * 查看
  31. */
  32. public function index()
  33. {
  34. //当前是否为关联查询
  35. $this->relationSearch = true;
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags', 'trim']);
  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. $list = $this->model
  45. ->with(['type'])
  46. ->where($where)
  47. ->order($sort, $order)
  48. ->paginate($limit);
  49. foreach ($list as $row) {
  50. $row->getRelation('type')->visible(['type','name']);
  51. }
  52. $result = array("total" => $list->total(), "rows" => $list->items());
  53. return json($result);
  54. }
  55. return $this->view->fetch();
  56. }
  57. /**
  58. * 添加
  59. */
  60. public function add()
  61. {
  62. if ($this->request->isPost()) {
  63. $params = $this->request->post("row/a");
  64. if ($params) {
  65. $params = $this->preExcludeFields($params);
  66. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  67. $params[$this->dataLimitField] = $this->auth->id;
  68. }
  69. $result = false;
  70. Db::startTrans();
  71. try {
  72. //是否采用模型验证
  73. if ($this->modelValidate) {
  74. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  75. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  76. $this->model->validateFailException(true)->validate($validate);
  77. }
  78. $result = $this->model->allowField(true)->save($params);
  79. $id = $this->model->id;
  80. Db::commit();
  81. } catch (ValidateException $e) {
  82. Db::rollback();
  83. $this->error($e->getMessage());
  84. } catch (PDOException $e) {
  85. Db::rollback();
  86. $this->error($e->getMessage());
  87. } catch (Exception $e) {
  88. Db::rollback();
  89. $this->error($e->getMessage());
  90. }
  91. if ($result !== false) {
  92. /*//生成ftp文件
  93. $content = [
  94. 'cpPrvdName' => '健康e家',
  95. 'cpPrvCode' => '41000144',
  96. 'cpPrvType' => '1006',
  97. 'ChnName' => '健康',
  98. 'ChnCode' => '1000020',
  99. 'contentId' => (string)$id,
  100. 'extraContentID' => '',
  101. 'content' => $params['title'],
  102. 'actors' => '',
  103. 'directors' => '',
  104. 'contentYear' => '',
  105. 'tags' => '',
  106. 'intent' => [
  107. 'action' => '',
  108. 'package' => '',
  109. 'component' => [
  110. 'pkg' => '',
  111. 'cls' => ''
  112. ],
  113. 'extras' => [
  114. 'cmd' => '',
  115. 'from' => '',
  116. 'media_id' => ''
  117. ]
  118. ],
  119. 'isEffective' => $params['status'],
  120. 'pic' => one_domain_image($params['image']),
  121. 'contentTime' => date('Y-m-d H:i:s'),
  122. 'isPaid' => $params['is_pay'],
  123. 'formatType' => ''
  124. ];
  125. $content = json_encode($content, 320);
  126. $filename = 'shipin_'.date('Ymd').'_'.date('His').'_increment'.'.json';
  127. error_log(print_r($content, 1) . PHP_EOL, 3, './jiankang/' . $filename);
  128. //调用增量注入接口
  129. $url = 'http:// test.meta.unso.gitv.tv/sendMeta';
  130. $method = 'POST';
  131. $postfields = [
  132. 'priKey' => '123456',
  133. 'data' => [$content]
  134. ];
  135. httpRequest($url, $method, $postfields);*/
  136. //内容同步
  137. $cspid = config('cspid');
  138. $url = 'http://'.config('inject_ip').':'.config('inject_port').'/epgDataSync/v1/' . $cspid;
  139. $data = [
  140. 'cspId' => $cspid,
  141. 'cpAlbumId' => $id,
  142. 'albumName' => $params['title'],
  143. 'tvSets' => 1,
  144. 'updateToSet' => 1,
  145. 'isPurchase' => $params['is_pay'],
  146. 'isEffective' => $params['status'],
  147. 'isOnline' => $params['status'],
  148. 'albumTypes' => '健康',
  149. 'picBox' => config('upload.cdnurl') . $params['image'],
  150. 'albumUpdateTime' => date('YmdHis', time()),
  151. 'albumCreateTime' => date('YmdHis', time()),
  152. 'tvlist' => [
  153. [
  154. 'cpAlbumId' => $id,
  155. 'cpTvId' => $id,
  156. 'tvName' => $params['title'],
  157. 'tvIsEffective' => $params['status'],
  158. 'tvIsOnline' => $params['status'],
  159. 'isPurchase' => $params['is_pay'],
  160. 'playOrder' => 1,
  161. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/'.$params['title'].'.mp4'
  162. ]
  163. ]
  164. ];
  165. $rs = httpRequest($url, 'POST', $data);
  166. if ($rs) {
  167. $rs = json_decode($rs, true);
  168. if ($rs['code'] == 'A000000') {
  169. Db::name('video')->where(['id' => $id])->setField('inject_status', 1);
  170. }
  171. }
  172. $this->success();
  173. } else {
  174. $this->error(__('No rows were inserted'));
  175. }
  176. }
  177. $this->error(__('Parameter %s can not be empty', ''));
  178. }
  179. return $this->view->fetch();
  180. }
  181. /**
  182. * 编辑
  183. */
  184. public function edit($ids = null)
  185. {
  186. $row = $this->model->get($ids);
  187. if (!$row) {
  188. $this->error(__('No Results were found'));
  189. }
  190. $adminIds = $this->getDataLimitAdminIds();
  191. if (is_array($adminIds)) {
  192. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  193. $this->error(__('You have no permission'));
  194. }
  195. }
  196. if ($this->request->isPost()) {
  197. $params = $this->request->post("row/a");
  198. if ($params) {
  199. $params = $this->preExcludeFields($params);
  200. $result = false;
  201. Db::startTrans();
  202. try {
  203. //是否采用模型验证
  204. if ($this->modelValidate) {
  205. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  206. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  207. $row->validateFailException(true)->validate($validate);
  208. }
  209. $result = $row->allowField(true)->save($params);
  210. Db::commit();
  211. } catch (ValidateException $e) {
  212. Db::rollback();
  213. $this->error($e->getMessage());
  214. } catch (PDOException $e) {
  215. Db::rollback();
  216. $this->error($e->getMessage());
  217. } catch (Exception $e) {
  218. Db::rollback();
  219. $this->error($e->getMessage());
  220. }
  221. if ($result !== false) {
  222. //内容同步
  223. $cspid = config('cspid');
  224. $url = 'http://'.config('inject_ip').':'.config('inject_port').'/epgDataSync/v1/' . $cspid;
  225. $data = [
  226. 'cspId' => $cspid,
  227. 'cpAlbumId' => $ids,
  228. 'albumName' => $params['title'],
  229. 'tvSets' => 1,
  230. 'updateToSet' => 1,
  231. 'isPurchase' => $params['is_pay'],
  232. 'isEffective' => $params['status'],
  233. 'isOnline' => $params['status'],
  234. 'albumTypes' => '健康',
  235. 'picBox' => config('upload.cdnurl') . $params['image'],
  236. 'albumUpdateTime' => date('YmdHis', time()),
  237. // 'albumCreateTime' => date('YmdHis', time()),
  238. 'tvlist' => [
  239. [
  240. 'cpAlbumId' => $ids,
  241. 'cpTvId' => $ids,
  242. 'tvName' => $params['title'],
  243. 'tvIsEffective' => $params['status'],
  244. 'tvIsOnline' => $params['status'],
  245. 'isPurchase' => $params['is_pay'],
  246. 'playOrder' => 1,
  247. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/'.$params['title'].'.mp4'
  248. ]
  249. ]
  250. ];
  251. $rs = httpRequest($url, 'POST', $data);
  252. if ($rs) {
  253. $rs = json_decode($rs, true);
  254. if ($rs['code'] == 'A000000') {
  255. Db::name('video')->where(['id' => $ids])->setField('inject_status', 1);
  256. }
  257. }
  258. $this->success();
  259. } else {
  260. $this->error(__('No rows were updated'));
  261. }
  262. }
  263. $this->error(__('Parameter %s can not be empty', ''));
  264. }
  265. $this->view->assign("row", $row);
  266. return $this->view->fetch();
  267. }
  268. /**
  269. * 删除
  270. */
  271. public function del($ids = "")
  272. {
  273. if (!$this->request->isPost()) {
  274. $this->error(__("Invalid parameters"));
  275. }
  276. $ids = $ids ? $ids : $this->request->post("ids");
  277. $params = Db::name('video')->find($ids);
  278. if (!$params) {
  279. $this->success();
  280. }
  281. Db::startTrans();
  282. $rt = Db::name('video')->delete($ids);
  283. if (!$rt) {
  284. Db::rollback();
  285. $this->error('删除失败');
  286. }
  287. //内容同步
  288. $cspid = config('cspid');
  289. $url = 'http://'.config('inject_ip').':'.config('inject_port').'/epgDeleteSync/v1/' . $cspid;
  290. $data = [
  291. 'cspId' => $cspid,
  292. 'cpAlbumId' => $ids,
  293. 'albumName' => $params['title'],
  294. 'tvSets' => 1,
  295. 'updateToSet' => 1,
  296. 'isPurchase' => $params['is_pay'],
  297. 'isEffective' => 0,
  298. 'isOnline' => 2,
  299. 'albumTypes' => '健康',
  300. 'picBox' => config('upload.cdnurl') . $params['image'],
  301. 'albumUpdateTime' => date('YmdHis', time()),
  302. // 'albumCreateTime' => date('YmdHis', time()),
  303. 'tvlist' => [
  304. [
  305. 'cpAlbumId' => $ids,
  306. 'cpTvId' => $ids,
  307. 'tvName' => $params['title'],
  308. 'tvIsEffective' => 0,
  309. 'tvIsOnline' => 2,
  310. 'isPurchase' => $params['is_pay'],
  311. 'playOrder' => 1,
  312. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/'.$params['title'].'.mp4'
  313. ]
  314. ]
  315. ];
  316. $rs = httpRequest($url, 'POST', $data);
  317. if (!$rs) {
  318. Db::rollback();
  319. $this->error('删除失败');
  320. }
  321. $rs = json_decode($rs, true);
  322. if ($rs['code'] != 'A000000') {
  323. Db::rollback();
  324. $this->error('删除失败');
  325. }
  326. Db::commit();
  327. $this->success();
  328. }
  329. }