Video.php 14 KB

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