123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- namespace app\admin\controller;
- use app\data\model\DataXwCategory;
- use app\data\model\DataBestKnowledgeAd;
- use think\admin\Controller;
- /**
- * 新闻报道
- * Class BestKnowledgeAd
- * @package app\admin\controller\BestKnowledgeAd
- */
- class BestKnowledgeAd extends Controller
- {
- /**
- * 新闻广告列表
- * @auth true
- * @menu true
- */
- public function ad_index(){
- $this->title='广告列表';
- DataBestKnowledgeAd::mQuery()->layTable();
- }
- /**
- * 新闻广告添加
- * @auth true
- * @menu true
- */
- public function ad_add(){
- $this->ad_vali();
- $this->assign('category',DataXwCategory::show()->select());
- DataBestKnowledgeAd::mForm('ad_form');
- }
- /**
- * 新闻广告编辑
- * @auth true
- * @menu true
- */
- public function ad_edit(){
- $this->ad_vali();
- $this->assign('category',DataXwCategory::show()->select());
- DataBestKnowledgeAd::mForm('ad_form');
- }
- protected function ad_vali(){
- if($this->request->isPost()){
- $this->_vali([
- 'title.max:50'=>'标题过长',
- ]);
- }
- }
- /**
- * 新闻广告删除
- * @auth true
- * @menu true
- */
- public function ad_del(){
- $ids=$this->request->post('id');
- DataBestKnowledgeAd::whereIn('id',$ids)->select()->each(function ($d){$d->delete();});
- $this->success('删除成功');
- }
- /**
- * 新闻广告上下架
- * @auth true
- * @menu true
- */
- public function ad_state(){
- DataBestKnowledgeAd::mSave([
- 'status'=>$this->request->post('status'),
- ]);
- }
- public function _form_filter($vo){
- if ($this->request->isGet()) {
- }elseif ($this->request->isPost()){
- $vo['content'] = $this->textcl($vo['content']);
- // $vo['user_id'] = null;
- // var_dump($vo);die;
- if($this->request->action() == 'edit' || $this->request->action() == 'add'){
- isset($vo['id']) ? DataBestKnowledge::mk()->where('id',$vo['id'])->update($vo) : DataBestKnowledge::mk()->insert($vo);
- $this->success('数据更新成功',in_array($this->request->action(),['add','edit','ad_add','ad_edit'])? 'javascript:history.back()':'');
- }else if(($this->request->action() == 'ad_add' || $this->request->action() == 'ad_edit')){
- isset($vo['id']) ? DataBestKnowledgeAd::mk()->where('id',$vo['id'])->update($vo) : DataBestKnowledgeAd::mk()->insert($vo);
- $this->success('数据更新成功',in_array($this->request->action(),['add','edit','ad_add','ad_edit'])? 'javascript:history.back()':'');
- }
- }
- }
- /**
- * 表单结果处理
- * @param boolean $state
- */
- protected function _form_result(bool $state)
- {
- if ($state) {
- $this->success('保存成功!',in_array($this->request->action(),['add','edit','ad_add','ad_edit'])? 'javascript:history.back()':'');
- }
- }
- //视频加封面(阿里云文件)
- public function textcl($string = ''){
- // $string = '<div>
- // <video controls="controls" width="100%"><source src="https://shipcccn.oss-cn-shanghai.aliyuncs.com/dd/天文学家系列.mp4" type="audio/mp4" /></video>
- // </div>
- //
- // <p>11111</p>
- //
- // <div>
- // <video controls="controls" width="100%"><source src="https://shipcccn.oss-cn-shanghai.aliyuncs.com/dd/96326ec38bb7761ef74b7623e94e886c.mp4" type="audio/mp4" /></video>
- // </div>
- //
- // <p>111216546485465468</p>'; // 原始字符串
- $position = strpos($string, '<video '); // 获取'video'在字符串中的位置
- if ($position !== false) {
- preg_match_all('/<video[^>]*>(.*?)<\/video>/s', $string, $matches);
- if (isset($matches[1])) {
- // echo "视频标签内容为:" . htmlspecialchars($matches[0][1]);die;
- } else {
- return $string;
- // echo "未找到视频标签";
- }
- foreach ($matches[0] as $k => $v){
- //获取src部分 拼凑封面地址
- $pattern_src = '/\bsrc\b\s*=\s*[\'\"]?([^\'\"]*)[\'\"]?/i';
- preg_match_all($pattern_src,$matches[0][$k],$matchSrc);
- $url = $matchSrc[1][0];
- $url = $url.'?x-oss-process=video/snapshot,t_10000,m_fast';
- $replacement_d = '<video controls="controls" poster="'.$url.'" width="100%">';
- //第一次替换
- $originalString = $matches[0][$k]; //这是原始字符串
- $replacement = $replacement_d; //被替换后的内容
- $searchValue = '<video controls="controls" width="100%">'; //要替换的部分
- // 将 $searchValue 替换为 $replacement
- $newString = str_replace($searchValue, $replacement, $originalString);
- //第二次替换
- $originalString = $string; //这是原始字符串
- $replacement = $newString; //被替换后的内容
- $searchValue = $matches[0][$k]; //要替换的部分
- $newString = str_replace($searchValue, $replacement, $originalString);
- $string = $newString;
- }
- //echo $newString;die; // 输出结果为"这是被替换后的内容";
- return $newString;
- } else {
- return $string;
- // echo "未找到'video'关键词";
- }
- }
- /**
- * 新闻报道设置
- * @auth true
- * @menu true
- */
- public function config(){
- if($this->request->isGet()){
- $this->title='间隔设置';
- $this->assign('vo',sysconf('config_xw.'));
- $this->fetch();
- }else{
- $data=$this->_vali([
- 'split_num2.require'=>'间隔数必须',
- 'user_avatar2.require'=>'头像数必须',
- 'user_avatar2.url'=>'头像链接有误',
- 'username2.require'=>'名称必须',
- 'split_num2.gt:0'=>'间隔数必须大于0',
- ]);
- sysconf('config_xw',$data);
- $this->success('保存成功');
- }
- }
- }
|