Video.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. //内容同步
  93. $cspid = config('cspid');
  94. // $url = 'http://'.config('inject_ip').':'.config('inject_port').'/epgDataSync/v1/' . $cspid;
  95. $url = 'http://jscp.agency.gitv.tv/epgDataSync/v1/' . $cspid . '/';
  96. $videofile = $params['videofile'];
  97. $videofile = explode('/', $videofile);
  98. $video_url = $videofile[3];
  99. $data = [
  100. // 'cspId' => $cspid,
  101. 'cpAlbumId' => $id,
  102. 'albumName' => $params['title'],
  103. 'tvSets' => 1,
  104. 'updateToSet' => 1,
  105. 'isPurchase' => $params['is_pay'],
  106. 'isEffective' => $params['status'],
  107. 'isOnline' => $params['status'],
  108. 'albumTypes' => '健康',
  109. 'picBox' => config('upload.cdnurl') . $params['image'],
  110. 'albumUpdateTime' => date('YmdHis', time()),
  111. 'albumCreateTime' => date('YmdHis', time()),
  112. 'tvlist' => [
  113. [
  114. 'cpAlbumId' => $id,
  115. 'cpTvId' => $id,
  116. 'tvName' => $params['title'],
  117. 'tvIsEffective' => $params['status'],
  118. 'tvIsOnline' => $params['status'],
  119. 'isPurchase' => $params['is_pay'],
  120. 'playOrder' => 1,
  121. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/inject/'.$video_url
  122. ]
  123. ]
  124. ];
  125. $data = json_encode($data, 320);
  126. $header = [
  127. 'Content-Type: application/json'
  128. ];
  129. $rs = httpRequest($url, 'POST', $data, $header);
  130. if ($rs) {
  131. $rs = json_decode($rs, true);
  132. if ($rs['code'] == 'A000000') {
  133. //注入中兴
  134. $url2 = 'http://jscp.agency.gitv.tv/epgDataSync/v1/' . config('cspid_zx') . '/';
  135. $rs2 = httpRequest($url2, 'POST', $data, $header);
  136. if ($rs2) {
  137. $rs2 = json_decode($rs2, true);
  138. if ($rs2['code'] == 'A000000') {
  139. Db::name('video')->where(['id' => $id])->setField('inject_status', 1);
  140. }
  141. }
  142. }
  143. }
  144. $this->success();
  145. } else {
  146. $this->error(__('No rows were inserted'));
  147. }
  148. }
  149. $this->error(__('Parameter %s can not be empty', ''));
  150. }
  151. return $this->view->fetch();
  152. }
  153. /**
  154. * 编辑
  155. */
  156. public function edit($ids = null)
  157. {
  158. $row = $this->model->get($ids);
  159. if (!$row) {
  160. $this->error(__('No Results were found'));
  161. }
  162. $adminIds = $this->getDataLimitAdminIds();
  163. if (is_array($adminIds)) {
  164. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  165. $this->error(__('You have no permission'));
  166. }
  167. }
  168. if ($this->request->isPost()) {
  169. $params = $this->request->post("row/a");
  170. if ($params) {
  171. $params = $this->preExcludeFields($params);
  172. $result = false;
  173. $params['search_status'] = 0;
  174. Db::startTrans();
  175. try {
  176. //是否采用模型验证
  177. if ($this->modelValidate) {
  178. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  179. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  180. $row->validateFailException(true)->validate($validate);
  181. }
  182. $result = $row->allowField(true)->save($params);
  183. Db::commit();
  184. } catch (ValidateException $e) {
  185. Db::rollback();
  186. $this->error($e->getMessage());
  187. } catch (PDOException $e) {
  188. Db::rollback();
  189. $this->error($e->getMessage());
  190. } catch (Exception $e) {
  191. Db::rollback();
  192. $this->error($e->getMessage());
  193. }
  194. if ($result !== false) {
  195. //内容同步
  196. /*$cspid = config('cspid');
  197. // $url = 'http://'.config('inject_ip').':'.config('inject_port').'/epgDataSync/v1/' . $cspid . '/';
  198. $url = 'http://jscp.agency.gitv.tv/epgDataSync/v1/' . $cspid . '/';
  199. $videofile = $row['videofile'];
  200. $videofile = explode('/', $videofile);
  201. $video_url = $videofile[3];
  202. $data = [
  203. // 'cspId' => $cspid,
  204. 'cpAlbumId' => $ids,
  205. 'albumName' => $params['title'],
  206. 'tvSets' => 1,
  207. 'updateToSet' => 1,
  208. 'isPurchase' => $params['is_pay'],
  209. 'isEffective' => $params['status'],
  210. 'isOnline' => $params['status'],
  211. 'albumTypes' => '健康',
  212. 'picBox' => config('upload.cdnurl') . $params['image'],
  213. 'albumUpdateTime' => date('YmdHis', time()),
  214. // 'albumCreateTime' => date('YmdHis', time()),
  215. 'tvlist' => [
  216. [
  217. 'cpAlbumId' => $ids,
  218. 'cpTvId' => $ids,
  219. 'tvName' => $params['title'],
  220. 'tvIsEffective' => $params['status'],
  221. 'tvIsOnline' => $params['status'],
  222. 'isPurchase' => $params['is_pay'],
  223. 'playOrder' => 1,
  224. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/inject/'.$video_url
  225. ]
  226. ]
  227. ];
  228. $data = json_encode($data, 320);
  229. $header = [
  230. 'Content-Type: application/json'
  231. ];
  232. $rs = httpRequest($url, 'POST', $data, $header);
  233. if ($rs) {
  234. $rs = json_decode($rs, true);
  235. if ($rs['code'] == 'A000000') {
  236. Db::name('video')->where(['id' => $ids])->setField('inject_status', 1);
  237. }
  238. }*/
  239. $this->success();
  240. } else {
  241. $this->error(__('No rows were updated'));
  242. }
  243. }
  244. $this->error(__('Parameter %s can not be empty', ''));
  245. }
  246. $this->view->assign("row", $row);
  247. return $this->view->fetch();
  248. }
  249. /**
  250. * 删除
  251. */
  252. public function del($ids = "")
  253. {
  254. if (!$this->request->isPost()) {
  255. $this->error(__("Invalid parameters"));
  256. }
  257. $ids = $ids ? $ids : $this->request->post("ids");
  258. $params = Db::name('video')->find($ids);
  259. if (!$params) {
  260. $this->success();
  261. }
  262. if ($params['status'] != 0) {
  263. $this->error('请先将视频状态修改为不显示');
  264. }
  265. Db::startTrans();
  266. $rt = Db::name('video')->delete($ids);
  267. if (!$rt) {
  268. Db::rollback();
  269. $this->error('删除失败');
  270. }
  271. //内容同步
  272. $cspid = config('cspid');
  273. // $url = 'http://'.config('inject_ip').':'.config('inject_port').'/epgDeleteSync/v1/' . $cspid;
  274. $url = 'http://jscp.agency.gitv.tv/epgDeleteSync/v1/' . $cspid . '/';
  275. $videofile = $params['videofile'];
  276. $videofile = explode('/', $videofile);
  277. $video_url = $videofile[3];
  278. $data = [
  279. // 'cspId' => $cspid,
  280. 'cpAlbumId' => $ids,
  281. 'albumName' => $params['title'],
  282. 'tvSets' => 1,
  283. 'updateToSet' => 1,
  284. 'isPurchase' => $params['is_pay'],
  285. 'isEffective' => 0,
  286. 'isOnline' => 2,
  287. 'albumTypes' => '健康',
  288. 'picBox' => config('upload.cdnurl') . $params['image'],
  289. 'albumUpdateTime' => date('YmdHis', time()),
  290. // 'albumCreateTime' => date('YmdHis', time()),
  291. 'tvlist' => [
  292. [
  293. 'cpAlbumId' => $ids,
  294. 'cpTvId' => $ids,
  295. 'tvName' => $params['title'],
  296. 'tvIsEffective' => 0,
  297. 'tvIsOnline' => 2,
  298. 'isPurchase' => $params['is_pay'],
  299. 'playOrder' => 1,
  300. 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/inject/'.$video_url
  301. ]
  302. ]
  303. ];
  304. $data = json_encode($data, 320);
  305. $header = [
  306. 'Content-Type: application/json'
  307. ];
  308. $rs = httpRequest($url, 'POST', $data, $header);
  309. if (!$rs) {
  310. Db::rollback();
  311. $this->error('删除失败');
  312. }
  313. $rs = json_decode($rs, true);
  314. if ($rs['code'] != 'A000000') {
  315. Db::rollback();
  316. $this->error('删除失败');
  317. }
  318. //删除中兴内容
  319. $url2 = 'http://jscp.agency.gitv.tv/epgDeleteSync/v1/' . config('cspid_zx') . '/';
  320. $rs2 = httpRequest($url2, 'POST', $data, $header);
  321. /*if (!$rs2) {
  322. Db::rollback();
  323. $this->error('删除失败');
  324. }
  325. $rs2 = json_decode($rs2, true);
  326. if ($rs2['code'] != 'A000000') {
  327. Db::rollback();
  328. $this->error('删除失败');
  329. }*/
  330. //生成ftp文件
  331. $content = [
  332. 'cpPrvdName' => '健康e家',
  333. 'cpPrvCode' => '41000144',
  334. 'cpPrvType' => '1006',
  335. 'ChnName' => '健康',
  336. 'ChnCode' => '1000020',
  337. 'actors' => '无',
  338. 'directors' => '无',
  339. 'contentYear' => date('Y'),
  340. 'tags' => '',
  341. 'contentTime' => date('Y-m-d H:i:s'),
  342. 'formatType' => '超清'
  343. ];
  344. //生成ftp文件
  345. $content['contentId'] = $params['movieid'];
  346. $content['extraContentID'] = $params['movieid'];
  347. $content['content'] = $params['title'];
  348. $content['intent'] = [
  349. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  350. 'package' => 'com.huxiu.heh.tv',
  351. 'component' => [
  352. 'pkg' => 'com.huxiu.heh.tv',
  353. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  354. ],
  355. 'extras' => [
  356. // 'cmd' => '',
  357. // 'from' => '',
  358. // 'media_id' => ''
  359. 'type_id' => $params['video_type_id'],
  360. 'id' => $params['id']
  361. ]
  362. ];
  363. $content['isEffective'] = $params['status'];
  364. $content['pic'] = one_domain_image($params['image']);
  365. $content['isPaid'] = $params['is_pay'];
  366. $content = json_encode($content, 320);
  367. $filename = 'shipin_'.date('Ymd').'_'.date('His').'_increment'.'.json';
  368. error_log(print_r($content, 1) . PHP_EOL, 3, './jiankang/' . $filename);
  369. Db::commit();
  370. $this->success();
  371. }
  372. }