Vod.php 30 KB

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