Vod.php 27 KB

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