Vod.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. use think\Cache;
  5. use app\common\util\Pinyin;
  6. use app\common\validate\Vod as VodValidate;
  7. class Vod extends Base {
  8. // 设置数据表(不含前缀)
  9. protected $name = 'vod';
  10. // 定义时间戳字段名
  11. protected $createTime = '';
  12. protected $updateTime = '';
  13. // 自动完成
  14. protected $auto = [];
  15. protected $insert = [];
  16. protected $update = [];
  17. public function countData($where)
  18. {
  19. $where2='';
  20. if(!empty($where['_string'])){
  21. $where2 = $where['_string'];
  22. unset($where['_string']);
  23. }
  24. $total = $this->where($where)->where($where2)->count();
  25. return $total;
  26. }
  27. public function listData($where,$order,$page=1,$limit=20,$start=0,$field='*',$addition=1,$totalshow=1)
  28. {
  29. $page = $page > 0 ? (int)$page : 1;
  30. $limit = $limit ? (int)$limit : 20;
  31. $start = $start ? (int)$start : 0;
  32. if(!is_array($where)){
  33. $where = json_decode($where,true);
  34. }
  35. $where2='';
  36. if(!empty($where['_string'])){
  37. $where2 = $where['_string'];
  38. unset($where['_string']);
  39. }
  40. $limit_str = ($limit * ($page-1) + $start) .",".$limit;
  41. if($totalshow==1) {
  42. $total = $this->where($where)->where($where2)->count();
  43. }
  44. $list = Db::name('Vod')->field($field)->where($where)->where($where2)->order($order)->limit($limit_str)->select();
  45. //分类
  46. $type_list = model('Type')->getCache('type_list');
  47. //用户组
  48. $group_list = model('Group')->getCache('group_list');
  49. foreach($list as $k=>$v){
  50. if($addition==1){
  51. if(!empty($v['type_id'])) {
  52. $list[$k]['type'] = $type_list[$v['type_id']];
  53. $list[$k]['type_1'] = $type_list[$list[$k]['type']['type_pid']];
  54. }
  55. if(!empty($v['group_id'])) {
  56. $list[$k]['group'] = $group_list[$v['group_id']];
  57. }
  58. }
  59. }
  60. return ['code'=>1,'msg'=>lang('data_list'),'page'=>$page,'pagecount'=>ceil($total/$limit),'limit'=>$limit,'total'=>$total,'list'=>$list];
  61. }
  62. public function listRepeatData($where,$order,$page=1,$limit=20,$start=0,$field='*',$addition=1)
  63. {
  64. $page = $page > 0 ? (int)$page : 1;
  65. $limit = $limit ? (int)$limit : 20;
  66. $start = $start ? (int)$start : 0;
  67. if(!is_array($where)){
  68. $where = json_decode($where,true);
  69. }
  70. $limit_str = ($limit * ($page-1) + $start) .",".$limit;
  71. $total = $this
  72. ->join('tmpvod t','t.name1 = vod_name')
  73. ->where($where)
  74. ->count();
  75. $list = Db::name('Vod')
  76. ->join('tmpvod t','t.name1 = vod_name')
  77. ->field($field)
  78. ->where($where)
  79. ->order($order)
  80. ->limit($limit_str)
  81. ->select();
  82. //分类
  83. $type_list = model('Type')->getCache('type_list');
  84. //用户组
  85. $group_list = model('Group')->getCache('group_list');
  86. foreach($list as $k=>$v){
  87. if($addition==1){
  88. if(!empty($v['type_id'])) {
  89. $list[$k]['type'] = $type_list[$v['type_id']];
  90. $list[$k]['type_1'] = $type_list[$list[$k]['type']['type_pid']];
  91. }
  92. if(!empty($v['group_id'])) {
  93. $list[$k]['group'] = $group_list[$v['group_id']];
  94. }
  95. }
  96. }
  97. return ['code'=>1,'msg'=>lang('data_list'),'page'=>$page,'pagecount'=>ceil($total/$limit),'limit'=>$limit,'total'=>$total,'list'=>$list];
  98. }
  99. public function listCacheData($lp)
  100. {
  101. if(!is_array($lp)){
  102. $lp = json_decode($lp,true);
  103. }
  104. $order = $lp['order'];
  105. $by = $lp['by'];
  106. $type = $lp['type'];
  107. $ids = $lp['ids'];
  108. $rel = $lp['rel'];
  109. $paging = $lp['paging'];
  110. $pageurl = $lp['pageurl'];
  111. $level = $lp['level'];
  112. $area = $lp['area'];
  113. $lang = $lp['lang'];
  114. $state = $lp['state'];
  115. $wd = $lp['wd'];
  116. $tag = $lp['tag'];
  117. $class = $lp['class'];
  118. $letter = $lp['letter'];
  119. $actor = $lp['actor'];
  120. $director = $lp['director'];
  121. $version = $lp['version'];
  122. $year = $lp['year'];
  123. $start = intval(abs($lp['start']));
  124. $num = intval(abs($lp['num']));
  125. $half = intval(abs($lp['half']));
  126. $weekday = $lp['weekday'];
  127. $tv = $lp['tv'];
  128. $timeadd = $lp['timeadd'];
  129. $timehits = $lp['timehits'];
  130. $time = $lp['time'];
  131. $hitsmonth = $lp['hitsmonth'];
  132. $hitsweek = $lp['hitsweek'];
  133. $hitsday = $lp['hitsday'];
  134. $hits = $lp['hits'];
  135. $not = $lp['not'];
  136. $cachetime = $lp['cachetime'];
  137. $isend = $lp['isend'];
  138. $plot = $lp['plot'];
  139. $typenot = $lp['typenot'];
  140. $name = $lp['name'];
  141. $page = 1;
  142. $where=[];
  143. $totalshow = 0;
  144. if(empty($num)){
  145. $num = 20;
  146. }
  147. if($start>1){
  148. $start--;
  149. }
  150. if(!in_array($paging, ['yes', 'no'])) {
  151. $paging = 'no';
  152. }
  153. $param = mac_param_url();
  154. if($paging=='yes') {
  155. $param = mac_search_len_check($param);
  156. $totalshow = 1;
  157. if(!empty($param['id'])){
  158. //$type = intval($param['id']);
  159. }
  160. if(!empty($param['level'])){
  161. $level = $param['level'];
  162. }
  163. if(!empty($param['ids'])){
  164. $ids = $param['ids'];
  165. }
  166. if(!empty($param['tid'])) {
  167. $tid = intval($param['tid']);
  168. }
  169. if(!empty($param['year'])){
  170. if(strlen($param['year'])==4){
  171. $year = intval($param['year']);
  172. }
  173. elseif(strlen($param['year'])==9){
  174. $s=substr($param['year'],0,4);
  175. $e=substr($param['year'],5,4);
  176. $s1 = intval($s);$s2 = intval($e);
  177. if($s1>$s2){
  178. $s1 = intval($e);$s2 = intval($s);
  179. }
  180. $tmp=[];
  181. for($i=$s1;$i<=$s2;$i++){
  182. $tmp[] = $i;
  183. }
  184. $year = join(',',$tmp);
  185. }
  186. }
  187. if(!empty($param['area'])){
  188. $area = $param['area'];
  189. }
  190. if(!empty($param['lang'])){
  191. $lang = $param['lang'];
  192. }
  193. if(!empty($param['tag'])){
  194. $tag = $param['tag'];
  195. }
  196. if(!empty($param['class'])){
  197. $class = $param['class'];
  198. }
  199. if(!empty($param['state'])){
  200. $state = $param['state'];
  201. }
  202. if(!empty($param['letter'])){
  203. $letter = $param['letter'];
  204. }
  205. if(!empty($param['version'])){
  206. $version = $param['version'];
  207. }
  208. if(!empty($param['actor'])){
  209. $actor = $param['actor'];
  210. }
  211. if(!empty($param['director'])){
  212. $director = $param['director'];
  213. }
  214. if(!empty($param['wd'])){
  215. $wd = $param['wd'];
  216. }
  217. if(!empty($param['name'])){
  218. $name = $param['name'];
  219. }
  220. if(!empty($param['by'])){
  221. $by = $param['by'];
  222. }
  223. if(!empty($param['order'])){
  224. $order = $param['order'];
  225. }
  226. if(!empty($param['page'])){
  227. $page = intval($param['page']);
  228. }
  229. if(isset($param['isend'])){
  230. $isend = intval($param['isend']);
  231. }
  232. foreach($param as $k=>$v){
  233. if(empty($v)){
  234. unset($param[$k]);
  235. }
  236. }
  237. if(empty($pageurl)){
  238. $pageurl = 'vod/type';
  239. }
  240. $param['page'] = 'PAGELINK';
  241. if($pageurl=='vod/type' || $pageurl=='vod/show'){
  242. $type = intval( $GLOBALS['type_id'] );
  243. $type_list = model('Type')->getCache('type_list');
  244. $type_info = $type_list[$type];
  245. $flag='type';
  246. if($pageurl == 'vod/show'){
  247. $flag='show';
  248. }
  249. $pageurl = mac_url_type($type_info,$param,$flag);
  250. }
  251. else{
  252. $pageurl = mac_url($pageurl,$param);
  253. }
  254. }
  255. $where['vod_status'] = ['eq',1];
  256. if(!empty($ids)) {
  257. if($ids!='all'){
  258. $where['vod_id'] = ['in',explode(',',$ids)];
  259. }
  260. }
  261. if(!empty($not)){
  262. $where['vod_id'] = ['not in',explode(',',$not)];
  263. }
  264. if(!empty($rel)){
  265. $tmp = explode(',',$rel);
  266. if(is_numeric($rel) || mac_array_check_num($tmp)==true ){
  267. $where['vod_id'] = ['in',$tmp];
  268. }
  269. else{
  270. $where['vod_rel_vod'] = ['like', mac_like_arr($rel),'OR'];
  271. }
  272. }
  273. if(!empty($level)) {
  274. if($level=='all'){
  275. $level = '1,2,3,4,5,6,7,8,9';
  276. }
  277. $where['vod_level'] = ['in',explode(',',$level)];
  278. }
  279. if(!empty($year)) {
  280. $where['vod_year'] = ['in',explode(',',$year)];
  281. }
  282. if(!empty($area)) {
  283. $where['vod_area'] = ['in',explode(',',$area)];
  284. }
  285. if(!empty($lang)) {
  286. $where['vod_lang'] = ['in',explode(',',$lang)];
  287. }
  288. if(!empty($state)) {
  289. $where['vod_state'] = ['in',explode(',',$state)];
  290. }
  291. if(!empty($version)) {
  292. $where['vod_version'] = ['in',explode(',',$version)];
  293. }
  294. if(!empty($weekday)){
  295. //$where['vod_weekday'] = ['in',explode(',',$weekday)];
  296. $where['vod_weekday'] = ['like', mac_like_arr($weekday),'OR'];
  297. }
  298. if(!empty($tv)){
  299. $where['vod_tv'] = ['in',explode(',',$tv)];
  300. }
  301. if(!empty($timeadd)){
  302. $s = intval(strtotime($timeadd));
  303. $where['vod_time_add'] =['gt',$s];
  304. }
  305. if(!empty($timehits)){
  306. $s = intval(strtotime($timehits));
  307. $where['vod_time_hits'] =['gt',$s];
  308. }
  309. if(!empty($time)){
  310. $s = intval(strtotime($time));
  311. $where['vod_time'] =['gt',$s];
  312. }
  313. if(!empty($letter)){
  314. if(substr($letter,0,1)=='0' && substr($letter,2,1)=='9'){
  315. $letter='0,1,2,3,4,5,6,7,8,9';
  316. }
  317. $where['vod_letter'] = ['in',explode(',',$letter)];
  318. }
  319. if(!empty($type)) {
  320. if($type=='current'){
  321. $type = intval( $GLOBALS['type_id'] );
  322. }
  323. if($type!='all') {
  324. $tmp_arr = explode(',',$type);
  325. $type_list = model('Type')->getCache('type_list');
  326. $type = [];
  327. foreach($type_list as $k2=>$v2){
  328. if(in_array($v2['type_id'].'',$tmp_arr) || in_array($v2['type_pid'].'',$tmp_arr)){
  329. $type[]=$v2['type_id'];
  330. }
  331. }
  332. $type = array_unique($type);
  333. $where['type_id'] = ['in', implode(',',$type) ];
  334. }
  335. }
  336. if(!empty($typenot)){
  337. $where['type_id'] = ['not in',$typenot];
  338. }
  339. if(!empty($tid)) {
  340. $where['type_id|type_id_1'] = ['eq',$tid];
  341. }
  342. if(!in_array($GLOBALS['aid'],[13,14,15]) && !empty($param['id'])){
  343. //$where['vod_id'] = ['not in',$param['id']];
  344. }
  345. if(!empty($hitsmonth)){
  346. $tmp = explode(' ',$hitsmonth);
  347. if(count($tmp)==1){
  348. $where['vod_hits_month'] = ['gt', $tmp];
  349. }
  350. else{
  351. $where['vod_hits_month'] = [$tmp[0],$tmp[1]];
  352. }
  353. }
  354. if(!empty($hitsweek)){
  355. $tmp = explode(' ',$hitsweek);
  356. if(count($tmp)==1){
  357. $where['vod_hits_week'] = ['gt', $tmp];
  358. }
  359. else{
  360. $where['vod_hits_week'] = [$tmp[0],$tmp[1]];
  361. }
  362. }
  363. if(!empty($hitsday)){
  364. $tmp = explode(' ',$hitsday);
  365. if(count($tmp)==1){
  366. $where['vod_hits_day'] = ['gt', $tmp];
  367. }
  368. else{
  369. $where['vod_hits_day'] = [$tmp[0],$tmp[1]];
  370. }
  371. }
  372. if(!empty($hits)){
  373. $tmp = explode(' ',$hits);
  374. if(count($tmp)==1){
  375. $where['vod_hits'] = ['gt', $tmp];
  376. }
  377. else{
  378. $where['vod_hits'] = [$tmp[0],$tmp[1]];
  379. }
  380. }
  381. if(in_array($isend,['0','1'])){
  382. $where['vod_isend'] = $isend;
  383. }
  384. $vod_search = model('VodSearch');
  385. $vod_search_enabled = $vod_search->isFrontendEnabled();
  386. $max_id_count = $vod_search->maxIdCount;
  387. if ($vod_search_enabled) {
  388. // 开启搜索优化,查询并缓存Id
  389. $search_id_list = [];
  390. if(!empty($wd)) {
  391. $role = 'vod_name';
  392. if(!empty($GLOBALS['config']['app']['search_vod_rule'])){
  393. $role .= '|'.$GLOBALS['config']['app']['search_vod_rule'];
  394. }
  395. $where[$role] = ['like', '%' . $wd . '%'];
  396. if (count($search_id_list_tmp = $vod_search->getResultIdList($wd, $role)) <= $max_id_count) {
  397. $search_id_list += $search_id_list_tmp;
  398. unset($where[$role]);
  399. }
  400. }
  401. if(!empty($name)) {
  402. $where['vod_name'] = ['like',mac_like_arr($name),'OR'];
  403. if (count($search_id_list_tmp = $vod_search->getResultIdList($name, 'vod_name')) <= $max_id_count) {
  404. $search_id_list += $search_id_list_tmp;
  405. unset($where['vod_name']);
  406. }
  407. }
  408. if(!empty($tag)) {
  409. $where['vod_tag'] = ['like',mac_like_arr($tag),'OR'];
  410. if (count($search_id_list_tmp = $vod_search->getResultIdList($tag, 'vod_tag', true)) <= $max_id_count) {
  411. $search_id_list += $search_id_list_tmp;
  412. unset($where['vod_tag']);
  413. }
  414. }
  415. if(!empty($class)) {
  416. $where['vod_class'] = ['like',mac_like_arr($class), 'OR'];
  417. if (count($search_id_list_tmp = $vod_search->getResultIdList($class, 'vod_class', true)) <= $max_id_count) {
  418. $search_id_list += $search_id_list_tmp;
  419. unset($where['vod_class']);
  420. }
  421. }
  422. if(!empty($actor)) {
  423. $where['vod_actor'] = ['like', mac_like_arr($actor), 'OR'];
  424. if (count($search_id_list_tmp = $vod_search->getResultIdList($actor, 'vod_actor', true)) <= $max_id_count) {
  425. $search_id_list += $search_id_list_tmp;
  426. unset($where['vod_actor']);
  427. }
  428. }
  429. if(!empty($director)) {
  430. $where['vod_director'] = ['like',mac_like_arr($director),'OR'];
  431. if (count($search_id_list_tmp = $vod_search->getResultIdList($director, 'vod_director', true)) <= $max_id_count) {
  432. $search_id_list += $search_id_list_tmp;
  433. unset($where['vod_director']);
  434. }
  435. }
  436. $search_id_list = array_unique($search_id_list);
  437. if (!empty($search_id_list)) {
  438. $where['_string'] = "vod_id IN (" . join(',', $search_id_list) . ")";
  439. }
  440. } else {
  441. // 不开启搜索优化,使用默认条件
  442. if(!empty($wd)) {
  443. $role = 'vod_name';
  444. if(!empty($GLOBALS['config']['app']['search_vod_rule'])){
  445. $role .= '|'.$GLOBALS['config']['app']['search_vod_rule'];
  446. }
  447. $where[$role] = ['like', '%' . $wd . '%'];
  448. }
  449. if(!empty($name)) {
  450. $where['vod_name'] = ['like',mac_like_arr($name),'OR'];
  451. }
  452. if(!empty($tag)) {
  453. $where['vod_tag'] = ['like',mac_like_arr($tag),'OR'];
  454. }
  455. if(!empty($class)) {
  456. $where['vod_class'] = ['like',mac_like_arr($class), 'OR'];
  457. }
  458. if(!empty($actor)) {
  459. $where['vod_actor'] = ['like', mac_like_arr($actor), 'OR'];
  460. }
  461. if(!empty($director)) {
  462. $where['vod_director'] = ['like',mac_like_arr($director),'OR'];
  463. }
  464. }
  465. if(in_array($plot,['0','1'])){
  466. $where['vod_plot'] = $plot;
  467. }
  468. if(defined('ENTRANCE') && ENTRANCE == 'index' && $GLOBALS['config']['app']['popedom_filter'] ==1){
  469. $type_ids = mac_get_popedom_filter($GLOBALS['user']['group']['group_type']);
  470. if(!empty($type_ids)){
  471. if(!empty($where['type_id'])){
  472. $where['type_id'] = [ $where['type_id'],['not in', explode(',',$type_ids)] ];
  473. }
  474. else{
  475. $where['type_id'] = ['not in', explode(',',$type_ids)];
  476. }
  477. }
  478. }
  479. // 优化随机视频排序rnd的性能问题
  480. // https://github.com/magicblack/maccms10/issues/967
  481. $use_rand = false;
  482. if($by=='rnd'){
  483. $use_rand = true;
  484. $algo2_threshold = 2000;
  485. $data_count = $this->countData($where);
  486. $where_string_addon = "";
  487. if ($data_count > $algo2_threshold) {
  488. $rows = $this->field("vod_id")->where($where)->select();
  489. foreach ($rows as $row) {
  490. $id_list[] = $row['vod_id'];
  491. }
  492. if (
  493. !empty($id_list)
  494. ) {
  495. $random_count = intval($algo2_threshold / 2);
  496. $specified_list = array_rand($id_list, intval($algo2_threshold / 2));
  497. $random_keys = array_rand($id_list, $random_count);
  498. $specified_list = [];
  499. if ($random_count == 1) {
  500. $specified_list[] = $id_list[$random_keys];
  501. } else {
  502. foreach ($random_keys as $key) {
  503. $specified_list[] = $id_list[$key];
  504. }
  505. }
  506. if (!empty($specified_list)) {
  507. $where_string_addon = " AND vod_id IN (" . join(',', $specified_list) . ")";
  508. }
  509. }
  510. }
  511. if (!empty($where_string_addon)) {
  512. $where['_string'] .= $where_string_addon;
  513. $where['_string'] = trim($where['_string'], " AND ");
  514. } else {
  515. if ($data_count % $lp['num'] === 0) {
  516. $page_total = floor($data_count / $lp['num']);
  517. } else {
  518. $page_total = floor($data_count / $lp['num']) + 1;
  519. }
  520. if($data_count < $lp['num']){
  521. $lp['num'] = $data_count;
  522. }
  523. $randi = @mt_rand(1, $page_total);
  524. $page = $randi;
  525. }
  526. $by = 'hits_week';
  527. $order = 'desc';
  528. }
  529. if(!in_array($by, ['id', 'time','time_add','score','hits','hits_day','hits_week','hits_month','up','down','level','rnd'])) {
  530. $by = 'time';
  531. }
  532. if(!in_array($order, ['asc', 'desc'])) {
  533. $order = 'desc';
  534. }
  535. $order= 'vod_'.$by .' ' . $order;
  536. $where_cache = $where;
  537. if($use_rand){
  538. unset($where_cache['vod_id']);
  539. $where_cache['order'] = 'rnd';
  540. }
  541. $cach_name = $GLOBALS['config']['app']['cache_flag']. '_' .md5('vod_listcache_'.http_build_query($where_cache).'_'.$order.'_'.$page.'_'.$num.'_'.$start.'_'.$pageurl);
  542. $res = Cache::get($cach_name);
  543. if(empty($cachetime)){
  544. $cachetime = $GLOBALS['config']['app']['cache_time'];
  545. }
  546. if($GLOBALS['config']['app']['cache_core']==0 || empty($res)) {
  547. $res = $this->listData($where, $order, $page, $num, $start,'*',1, $totalshow);
  548. if($GLOBALS['config']['app']['cache_core']==1) {
  549. Cache::set($cach_name, $res, $cachetime);
  550. }
  551. }
  552. $res['pageurl'] = $pageurl;
  553. $res['half'] = $half;
  554. return $res;
  555. }
  556. public function infoData($where,$field='*',$cache=0)
  557. {
  558. if(empty($where) || !is_array($where)){
  559. return ['code'=>1001,'msg'=>lang('param_err')];
  560. }
  561. $data_cache = false;
  562. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'vod_detail_'.$where['vod_id'][1].'_'.$where['vod_en'][1];
  563. if($where['vod_id'][0]=='eq' || $where['vod_en'][0]=='eq'){
  564. $data_cache = true;
  565. }
  566. if($GLOBALS['config']['app']['cache_core']==1 && $data_cache) {
  567. $info = Cache::get($key);
  568. }
  569. if($GLOBALS['config']['app']['cache_core']==0 || $cache==0 || empty($info['vod_id'])) {
  570. $info = $this->field($field)->where($where)->find();
  571. if (empty($info)) {
  572. return ['code' => 1002, 'msg' => lang('obtain_err')];
  573. }
  574. $info = $info->toArray();
  575. $info['vod_play_list']=[];
  576. $info['vod_down_list']=[];
  577. $info['vod_plot_list']=[];
  578. $info['vod_pic_screenshot_list']=[];
  579. if (!empty($info['vod_play_from'])) {
  580. $info['vod_play_list'] = mac_play_list($info['vod_play_from'], $info['vod_play_url'], $info['vod_play_server'], $info['vod_play_note'], 'play');
  581. }
  582. if (!empty($info['vod_down_from'])) {
  583. $info['vod_down_list'] = mac_play_list($info['vod_down_from'], $info['vod_down_url'], $info['vod_down_server'], $info['vod_down_note'], 'down');
  584. }
  585. if (!empty($info['vod_plot_name'])) {
  586. $info['vod_plot_list'] = mac_plot_list($info['vod_plot_name'], $info['vod_plot_detail']);
  587. }
  588. if(!empty($info['vod_pic_screenshot'])){
  589. $info['vod_pic_screenshot_list'] = mac_screenshot_list($info['vod_pic_screenshot']);
  590. }
  591. //分类
  592. if (!empty($info['type_id'])) {
  593. $type_list = model('Type')->getCache('type_list');
  594. $info['type'] = $type_list[$info['type_id']];
  595. $info['type_1'] = $type_list[$info['type']['type_pid']];
  596. }
  597. //用户组
  598. if (!empty($info['group_id'])) {
  599. $group_list = model('Group')->getCache('group_list');
  600. $info['group'] = $group_list[$info['group_id']];
  601. }
  602. if($GLOBALS['config']['app']['cache_core']==1 && $data_cache && $cache==1) {
  603. Cache::set($key, $info);
  604. }
  605. }
  606. return ['code'=>1,'msg'=>lang('obtain_ok'),'info'=>$info];
  607. }
  608. public function saveData($data)
  609. {
  610. $validate = \think\Loader::validate('Vod');
  611. if(!$validate->check($data)){
  612. return ['code'=>1001,'msg'=>lang('param_err').':'.$validate->getError() ];
  613. }
  614. $key = 'vod_detail_'.$data['vod_id'];
  615. Cache::rm($key);
  616. $key = 'vod_detail_'.$data['vod_en'];
  617. Cache::rm($key);
  618. $key = 'vod_detail_'.$data['vod_id'].'_'.$data['vod_en'];
  619. Cache::rm($key);
  620. $type_list = model('Type')->getCache('type_list');
  621. $type_info = $type_list[$data['type_id']];
  622. $data['type_id_1'] = $type_info['type_pid'];
  623. if(empty($data['vod_en'])){
  624. $data['vod_en'] = Pinyin::get($data['vod_name']);
  625. }
  626. if(empty($data['vod_letter'])){
  627. $data['vod_letter'] = strtoupper(substr($data['vod_en'],0,1));
  628. }
  629. if(!empty($data['vod_content'])) {
  630. $pattern_src = '/<img[\s\S]*?src\s*=\s*[\"|\'](.*?)[\"|\'][\s\S]*?>/';
  631. @preg_match_all($pattern_src, $data['vod_content'], $match_src1);
  632. if (!empty($match_src1)) {
  633. foreach ($match_src1[1] as $v1) {
  634. $v2 = str_replace($GLOBALS['config']['upload']['protocol'] . ':', 'mac:', $v1);
  635. $data['vod_content'] = str_replace($v1, $v2, $data['vod_content']);
  636. }
  637. }
  638. unset($match_src1);
  639. }
  640. if(empty($data['vod_blurb'])){
  641. $data['vod_blurb'] = mac_substring( strip_tags($data['vod_content']) ,100);
  642. }
  643. if(empty($data['vod_play_url'])){
  644. $data['vod_play_url'] = '';
  645. }
  646. if(empty($data['vod_down_url'])){
  647. $data['vod_down_url'] = '';
  648. }
  649. if(!empty($data['vod_pic_screenshot'])){
  650. $data['vod_pic_screenshot'] = str_replace( array(chr(10),chr(13)), array('','#'),$data['vod_pic_screenshot']);
  651. }
  652. if(!empty($data['vod_play_from'])) {
  653. $data['vod_play_from'] = join('$$$', $data['vod_play_from']);
  654. $data['vod_play_server'] = join('$$$', $data['vod_play_server']);
  655. $data['vod_play_note'] = join('$$$', $data['vod_play_note']);
  656. $data['vod_play_url'] = join('$$$', $data['vod_play_url']);
  657. $data['vod_play_url'] = str_replace( array(chr(10),chr(13)), array('','#'),$data['vod_play_url']);
  658. }
  659. else{
  660. $data['vod_play_from'] = '';
  661. $data['vod_play_server'] = '';
  662. $data['vod_play_note'] = '';
  663. $data['vod_play_url'] = '';
  664. }
  665. if(!empty($data['vod_down_from'])) {
  666. $data['vod_down_from'] = join('$$$', $data['vod_down_from']);
  667. $data['vod_down_server'] = join('$$$', $data['vod_down_server']);
  668. $data['vod_down_note'] = join('$$$', $data['vod_down_note']);
  669. $data['vod_down_url'] = join('$$$', $data['vod_down_url']);
  670. $data['vod_down_url'] = str_replace(array(chr(10),chr(13)), array('','#'),$data['vod_down_url']);
  671. }else{
  672. $data['vod_down_from']='';
  673. $data['vod_down_server']='';
  674. $data['vod_down_note']='';
  675. $data['vod_down_url']='';
  676. }
  677. if($data['uptime']==1){
  678. $data['vod_time'] = time();
  679. }
  680. if($data['uptag']==1){
  681. $data['vod_tag'] = mac_get_tag($data['vod_name'], $data['vod_content']);
  682. }
  683. unset($data['uptime']);
  684. unset($data['uptag']);
  685. $data = VodValidate::formatDataBeforeDb($data);
  686. if(!empty($data['vod_id'])){
  687. $where=[];
  688. $where['vod_id'] = ['eq',$data['vod_id']];
  689. $res = $this->allowField(true)->where($where)->update($data);
  690. }
  691. else{
  692. $data['vod_plot'] = 0;
  693. $data['vod_plot_name']='';
  694. $data['vod_plot_detail']='';
  695. $data['vod_time_add'] = time();
  696. $data['vod_time'] = time();
  697. $res = $this->allowField(true)->insert($data, false, true);
  698. if ($res > 0 && model('VodSearch')->isFrontendEnabled()) {
  699. model('VodSearch')->checkAndUpdateTopResults(['vod_id' => $res] + $data);
  700. }
  701. }
  702. if(false === $res){
  703. return ['code'=>1002,'msg'=>lang('save_err').':'.$this->getError() ];
  704. }
  705. return ['code'=>1,'msg'=>lang('save_ok')];
  706. }
  707. public function savePlot($data)
  708. {
  709. $validate = \think\Loader::validate('Vod');
  710. if(!$validate->check($data)){
  711. return ['code'=>1001,'msg'=>lang('param_err').':'.$validate->getError() ];
  712. }
  713. $key = 'vod_detail_'.$data['vod_id'];
  714. Cache::rm($key);
  715. $key = 'vod_detail_'.$data['vod_en'];
  716. Cache::rm($key);
  717. $key = 'vod_detail_'.$data['vod_id'].'_'.$data['vod_en'];
  718. Cache::rm($key);
  719. if(!empty($data['vod_plot_name'])) {
  720. $data['vod_plot'] = 1;
  721. $data['vod_plot_name'] = join('$$$', $data['vod_plot_name']);
  722. $data['vod_plot_detail'] = join('$$$', $data['vod_plot_detail']);
  723. }else{
  724. $data['vod_plot'] = 0;
  725. $data['vod_plot_name']='';
  726. $data['vod_plot_detail']='';
  727. }
  728. if(!empty($data['vod_id'])){
  729. $where=[];
  730. $where['vod_id'] = ['eq',$data['vod_id']];
  731. $res = $this->allowField(true)->where($where)->update($data);
  732. }
  733. else{
  734. $res = false;
  735. }
  736. if(false === $res){
  737. return ['code'=>1002,'msg'=>lang('save_err').':'.$this->getError() ];
  738. }
  739. return ['code'=>1,'msg'=>lang('save_ok')];
  740. }
  741. public function delData($where)
  742. {
  743. $list = $this->listData($where,'',1,9999);
  744. if($list['code'] !==1){
  745. return ['code'=>1001,'msg'=>lang('del_err').':'.$this->getError() ];
  746. }
  747. $path = './';
  748. foreach($list['list'] as $k=>$v){
  749. $pic = $path.$v['vod_pic'];
  750. if(file_exists($pic) && (substr($pic,0,8) == "./upload") || count( explode("./",$pic) ) ==1){
  751. unlink($pic);
  752. }
  753. $pic = $path.$v['vod_pic_thumb'];
  754. if(file_exists($pic) && (substr($pic,0,8) == "./upload") || count( explode("./",$pic) ) ==1){
  755. unlink($pic);
  756. }
  757. $pic = $path.$v['vod_pic_slide'];
  758. if(file_exists($pic) && (substr($pic,0,8) == "./upload") || count( explode("./",$pic) ) ==1){
  759. unlink($pic);
  760. }
  761. if($GLOBALS['config']['view']['vod_detail'] ==2 ){
  762. $lnk = mac_url_vod_detail($v);
  763. $lnk = reset_html_filename($lnk);
  764. if(file_exists($lnk)){
  765. unlink($lnk);
  766. }
  767. }
  768. }
  769. $res = $this->where($where)->delete();
  770. if($res===false){
  771. return ['code'=>1002,'msg'=>lang('del_err').':'.$this->getError() ];
  772. }
  773. return ['code'=>1,'msg'=>lang('del_ok')];
  774. }
  775. public function fieldData($where,$update)
  776. {
  777. if(!is_array($update)){
  778. return ['code'=>1001,'msg'=>lang('param_err')];
  779. }
  780. $res = $this->allowField(true)->where($where)->update($update);
  781. if($res===false){
  782. return ['code'=>1001,'msg'=>lang('set_err').':'.$this->getError() ];
  783. }
  784. $list = $this->field('vod_id,vod_name,vod_en')->where($where)->select();
  785. foreach($list as $k=>$v){
  786. $key = 'vod_detail_'.$v['vod_id'];
  787. Cache::rm($key);
  788. $key = 'vod_detail_'.$v['vod_en'];
  789. Cache::rm($key);
  790. }
  791. return ['code'=>1,'msg'=>lang('set_ok')];
  792. }
  793. public function updateToday($flag='vod')
  794. {
  795. $today = strtotime(date('Y-m-d'));
  796. $where = [];
  797. $where['vod_time'] = ['gt',$today];
  798. if($flag=='type'){
  799. $ids = $this->where($where)->column('type_id');
  800. }
  801. else{
  802. $ids = $this->where($where)->column('vod_id');
  803. }
  804. if(empty($ids)){
  805. $ids = [];
  806. }else{
  807. $ids = array_unique($ids);
  808. }
  809. return ['code'=>1,'msg'=>lang('obtain_ok'),'data'=> join(',',$ids) ];
  810. }
  811. }