Video.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. $url = 'http://jscp.agency.gitv.tv/epgDataSync/v1/' . $cspid . '/';
  140. $data = [
  141. 'cspId' => $cspid,
  142. 'cpAlbumId' => $id,
  143. 'albumName' => $params['title'],
  144. 'tvSets' => 1,
  145. 'updateToSet' => 1,
  146. 'isPurchase' => $params['is_pay'],
  147. 'isEffective' => $params['status'],
  148. 'isOnline' => $params['status'],
  149. 'albumTypes' => '健康',
  150. 'picBox' => config('upload.cdnurl') . $params['image'],
  151. 'albumUpdateTime' => date('YmdHis', time()),
  152. 'albumCreateTime' => date('YmdHis', time()),
  153. 'tvlist' => [
  154. [
  155. 'cpAlbumId' => $id,
  156. 'cpTvId' => $id,
  157. 'tvName' => $params['title'],
  158. 'tvIsEffective' => $params['status'],
  159. 'tvIsOnline' => $params['status'],
  160. 'isPurchase' => $params['is_pay'],
  161. 'playOrder' => 1,
  162. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/'.$params['title'].'.mp4'
  163. ]
  164. ]
  165. ];
  166. $data = json_encode($data, 320);
  167. $rs = httpRequest($url, 'POST', $data);
  168. if ($rs) {
  169. $rs = json_decode($rs, true);
  170. if ($rs['code'] == 'A000000') {
  171. Db::name('video')->where(['id' => $id])->setField('inject_status', 1);
  172. }
  173. }
  174. $this->success();
  175. } else {
  176. $this->error(__('No rows were inserted'));
  177. }
  178. }
  179. $this->error(__('Parameter %s can not be empty', ''));
  180. }
  181. return $this->view->fetch();
  182. }
  183. /**
  184. * 编辑
  185. */
  186. public function edit($ids = null)
  187. {
  188. $row = $this->model->get($ids);
  189. if (!$row) {
  190. $this->error(__('No Results were found'));
  191. }
  192. $adminIds = $this->getDataLimitAdminIds();
  193. if (is_array($adminIds)) {
  194. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  195. $this->error(__('You have no permission'));
  196. }
  197. }
  198. if ($this->request->isPost()) {
  199. $params = $this->request->post("row/a");
  200. if ($params) {
  201. $params = $this->preExcludeFields($params);
  202. $result = false;
  203. Db::startTrans();
  204. try {
  205. //是否采用模型验证
  206. if ($this->modelValidate) {
  207. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  208. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  209. $row->validateFailException(true)->validate($validate);
  210. }
  211. $result = $row->allowField(true)->save($params);
  212. Db::commit();
  213. } catch (ValidateException $e) {
  214. Db::rollback();
  215. $this->error($e->getMessage());
  216. } catch (PDOException $e) {
  217. Db::rollback();
  218. $this->error($e->getMessage());
  219. } catch (Exception $e) {
  220. Db::rollback();
  221. $this->error($e->getMessage());
  222. }
  223. if ($result !== false) {
  224. //内容同步
  225. $cspid = config('cspid');
  226. // $url = 'http://'.config('inject_ip').':'.config('inject_port').'/epgDataSync/v1/' . $cspid . '/';
  227. $url = 'http://jscp.agency.gitv.tv/epgDataSync/v1/' . $cspid . '/';
  228. $data = [
  229. 'cspId' => $cspid,
  230. 'cpAlbumId' => $ids,
  231. 'albumName' => $params['title'],
  232. 'tvSets' => 1,
  233. 'updateToSet' => 1,
  234. 'isPurchase' => $params['is_pay'],
  235. 'isEffective' => $params['status'],
  236. 'isOnline' => $params['status'],
  237. 'albumTypes' => '健康',
  238. 'picBox' => config('upload.cdnurl') . $params['image'],
  239. 'albumUpdateTime' => date('YmdHis', time()),
  240. // 'albumCreateTime' => date('YmdHis', time()),
  241. 'tvlist' => [
  242. [
  243. 'cpAlbumId' => $ids,
  244. 'cpTvId' => $ids,
  245. 'tvName' => $params['title'],
  246. 'tvIsEffective' => $params['status'],
  247. 'tvIsOnline' => $params['status'],
  248. 'isPurchase' => $params['is_pay'],
  249. 'playOrder' => 1,
  250. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/'.$params['title'].'.mp4'
  251. ]
  252. ]
  253. ];
  254. $data = json_encode($data, 320);
  255. $rs = httpRequest($url, 'POST', $data);
  256. if ($rs) {
  257. $rs = json_decode($rs, true);
  258. if ($rs['code'] == 'A000000') {
  259. Db::name('video')->where(['id' => $ids])->setField('inject_status', 1);
  260. }
  261. }
  262. $this->success();
  263. } else {
  264. $this->error(__('No rows were updated'));
  265. }
  266. }
  267. $this->error(__('Parameter %s can not be empty', ''));
  268. }
  269. $this->view->assign("row", $row);
  270. return $this->view->fetch();
  271. }
  272. /**
  273. * 删除
  274. */
  275. public function del($ids = "")
  276. {
  277. if (!$this->request->isPost()) {
  278. $this->error(__("Invalid parameters"));
  279. }
  280. $ids = $ids ? $ids : $this->request->post("ids");
  281. $params = Db::name('video')->find($ids);
  282. if (!$params) {
  283. $this->success();
  284. }
  285. Db::startTrans();
  286. $rt = Db::name('video')->delete($ids);
  287. if (!$rt) {
  288. Db::rollback();
  289. $this->error('删除失败');
  290. }
  291. //内容同步
  292. $cspid = config('cspid');
  293. // $url = 'http://'.config('inject_ip').':'.config('inject_port').'/epgDeleteSync/v1/' . $cspid;
  294. $url = 'http://jscp.agency.gitv.tv/epgDeleteSync/v1/' . $cspid . '/';
  295. $data = [
  296. 'cspId' => $cspid,
  297. 'cpAlbumId' => $ids,
  298. 'albumName' => $params['title'],
  299. 'tvSets' => 1,
  300. 'updateToSet' => 1,
  301. 'isPurchase' => $params['is_pay'],
  302. 'isEffective' => 0,
  303. 'isOnline' => 2,
  304. 'albumTypes' => '健康',
  305. 'picBox' => config('upload.cdnurl') . $params['image'],
  306. 'albumUpdateTime' => date('YmdHis', time()),
  307. // 'albumCreateTime' => date('YmdHis', time()),
  308. 'tvlist' => [
  309. [
  310. 'cpAlbumId' => $ids,
  311. 'cpTvId' => $ids,
  312. 'tvName' => $params['title'],
  313. 'tvIsEffective' => 0,
  314. 'tvIsOnline' => 2,
  315. 'isPurchase' => $params['is_pay'],
  316. 'playOrder' => 1,
  317. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/'.$params['title'].'.mp4'
  318. ]
  319. ]
  320. ];
  321. $data = json_encode($data, 320);
  322. $rs = httpRequest($url, 'POST', $data);
  323. if (!$rs) {
  324. Db::rollback();
  325. $this->error('删除失败');
  326. }
  327. $rs = json_decode($rs, true);
  328. if ($rs['code'] != 'A000000') {
  329. Db::rollback();
  330. $this->error('删除失败');
  331. }
  332. Db::commit();
  333. $this->success();
  334. }
  335. }