Video.php 16 KB

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