You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
345 lines
14 KiB
345 lines
14 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | YFCMF [ WE CAN DO IT MORE SIMPLE ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: rainfer <81818832@qq.com>
|
|
// +----------------------------------------------------------------------
|
|
namespace app\admin\controller;
|
|
|
|
use think\Db;
|
|
use OSS\OssClient;
|
|
use OSS\Core\OssException;
|
|
|
|
class Video extends Base
|
|
{
|
|
/**
|
|
* 宣传片列表
|
|
*/
|
|
public function video_list()
|
|
{
|
|
$vd_cid=input('cid',0,'intval');
|
|
$where['type_type']=16;
|
|
if($vd_cid){
|
|
$where['vd_cid']=$vd_cid;
|
|
}
|
|
$videos=Db::name('video')->alias('a')
|
|
->join(config('database.prefix').'type b','a.vd_cid=b.type_id')
|
|
->where($where)->order('vd_order,vd_time desc')->paginate(config('paginate.list_rows'),false,['query'=>get_query()]);
|
|
$show = $videos->render();
|
|
$show=preg_replace("(<a[^>]*page[=|/](\d+).+?>(.+?)<\/a>)","<a href='javascript:ajax_page($1);'>$2</a>",$show);
|
|
$this->assign('page',$show);
|
|
$this->assign('videos',$videos);
|
|
$this->assign('vd_cid',$vd_cid);
|
|
$vd_cids=Db::name('type')->where('type_type',16)->order('type_order')->select();
|
|
$this->assign('vd_cids',$vd_cids);
|
|
if(request()->isAjax()){
|
|
return $this->fetch('ajax_video_list');
|
|
}else{
|
|
return $this->fetch();
|
|
}
|
|
}
|
|
/**
|
|
* 添加显示
|
|
*/
|
|
public function video_add()
|
|
{
|
|
$vd_cid=input('cid',0,'intval');
|
|
if (!request()->isAjax()){
|
|
$vd_cids=Db::name('type')->where('type_type',16)->order('type_order')->select();
|
|
$this->assign('vd_cids',$vd_cids);
|
|
$this->assign('vd_cid',$vd_cid);
|
|
return $this->fetch();
|
|
}else{
|
|
//上传图片部分
|
|
$img_one='';
|
|
$file = request()->file('pic_one');
|
|
$validate = config('upload_validate');
|
|
//单图
|
|
if ($file) {
|
|
$info = $file[0]->validate($validate)->rule('uniqid')->move(ROOT_PATH . config('upload_path') . DS . date('Y-m-d'));
|
|
if ($info) {
|
|
$img_url = config('upload_path'). '/' . date('Y-m-d') . '/' . $info->getFilename();
|
|
//写入数据库
|
|
$data['uptime'] = time();
|
|
$data['filesize'] = $info->getSize();
|
|
$data['path'] = $img_url;
|
|
Db::name('plug_files')->insert($data);
|
|
$img_one = $img_url;
|
|
} else {
|
|
$this->error($file->getError(), url('admin/Video/video_list',['cid'=>$vd_cid]));//否则就是上传错误,显示错误原因
|
|
}
|
|
}
|
|
//视频(使用oss)
|
|
$files = request()->file('file_all');
|
|
$fileall_url='';
|
|
if($files){
|
|
if(config('aliyun_oss.oss_open')){
|
|
$config=config('aliyun_oss');
|
|
$oss=new \OSS\OssClient($config['accesskey'],$config['secretkey'],$config['endpoint'],true);
|
|
foreach ($files as $file) {
|
|
$fileinfo=$file->getInfo();
|
|
$filename=$fileinfo['name'];
|
|
$path=$fileinfo['tmp_name'];
|
|
try{
|
|
$oss->uploadFile($config['bucket'],$filename,$path);
|
|
} catch(OssException $e) {
|
|
$this->error($e->getMessage(), url('admin/Video/video_list',['cid'=>$vd_cid]));//否则就是上传错误,显示错误原因
|
|
}
|
|
$file_url = $config['endpoint'].'/'.$filename;
|
|
//写入数据库
|
|
$data['uptime'] = time();
|
|
$data['filesize'] = $fileinfo['size'];
|
|
$data['path'] = $file_url;
|
|
Db::name('plug_files')->insert($data);
|
|
$fileall_url = $file_url;
|
|
}
|
|
}else{
|
|
$validate = config('upload_validate');
|
|
foreach ($files as $file) {
|
|
$info = $file->validate($validate)->rule('uniqid')->move(ROOT_PATH . config('upload_path') . DS . date('Y-m-d'));
|
|
if ($info) {
|
|
$file_url = config('upload_path'). '/' . date('Y-m-d') . '/' . $info->getFilename();
|
|
//写入数据库
|
|
$data['uptime'] = time();
|
|
$data['filesize'] = $info->getSize();
|
|
$data['path'] = $file_url;
|
|
Db::name('plug_files')->insert($data);
|
|
$fileall_url = $file_url;
|
|
} else {
|
|
$this->error($file->getError(), url('admin/Video/video_list',['cid'=>$vd_cid]));//否则就是上传错误,显示错误原因
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$file_path=request()->post('file_path');
|
|
if(empty($fileall_url)&&$file_path){
|
|
$fileall_url=$file_path;
|
|
}
|
|
$sl_data=array(
|
|
'vd_name'=>input('vd_name'),
|
|
'vd_img'=>$img_one,//封面图片路径
|
|
'vd_status'=>input('vd_status',0),
|
|
'vd_content'=>htmlspecialchars_decode(input('vd_content')),
|
|
'vd_uid'=>session('admin_auth.aid'),
|
|
'vd_time'=>time(),
|
|
'vd_order'=>input('vd_order',50,'intval'),
|
|
'vd_video'=>$fileall_url,
|
|
'vd_cid'=>$vd_cid
|
|
);
|
|
$rst=Db::name('video')->insert($sl_data);
|
|
if($rst){
|
|
$this->success('添加成功',url('admin/Video/video_list',['cid'=>$vd_cid]));
|
|
}else{
|
|
$this->error('添加失败',url('admin/Video/video_list',['cid'=>$vd_cid]));
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* 编辑显示
|
|
*/
|
|
public function video_edit()
|
|
{
|
|
$vd_cid=input('cid',0,'intval');
|
|
if (!request()->isAjax()) {
|
|
$vd_id = input('vd_id');
|
|
if (empty($vd_id)) {
|
|
if($vd_cid){
|
|
$this->error('参数错误', url('admin/Link/link_list',['cid'=>$vd_cid]));
|
|
}else{
|
|
$this->error('参数错误', url('admin/Link/link_list'));
|
|
}
|
|
}
|
|
$video_list = Db::name('video')->find($vd_id);
|
|
$this->assign('video_list', $video_list);
|
|
$vd_cids=Db::name('type')->where('type_type',16)->order('type_order')->select();
|
|
$this->assign('vd_cids',$vd_cids);
|
|
$this->assign('vd_cid',$video_list['vd_cid']);
|
|
return $this->fetch();
|
|
}else{
|
|
$img_one='';
|
|
$file = request()->file('pic_one');
|
|
$validate = config('upload_validate');
|
|
//单图
|
|
if (!empty($file)) {
|
|
$info = $file[0]->validate($validate)->rule('uniqid')->move(ROOT_PATH . config('upload_path') . DS . date('Y-m-d'));
|
|
if ($info) {
|
|
$img_url = config('upload_path'). '/' . date('Y-m-d') . '/' . $info->getFilename();
|
|
//写入数据库
|
|
$data['uptime'] = time();
|
|
$data['filesize'] = $info->getSize();
|
|
$data['path'] = $img_url;
|
|
Db::name('plug_files')->insert($data);
|
|
$img_one = $img_url;
|
|
} else {
|
|
$this->error($file->getError(), url('admin/Video/video_list',['cid'=>$vd_cid]));//否则就是上传错误,显示错误原因
|
|
}
|
|
}
|
|
//视频
|
|
$files = request()->file('file_all');
|
|
$fileall_url='';
|
|
if($files){
|
|
if(config('aliyun_oss.oss_open')){
|
|
$config=config('aliyun_oss');
|
|
$oss=new \OSS\OssClient($config['accesskey'],$config['secretkey'],$config['endpoint'],true);
|
|
foreach ($files as $file) {
|
|
$fileinfo=$file->getInfo();
|
|
$filename=$fileinfo['name'];
|
|
$path=$fileinfo['tmp_name'];
|
|
try{
|
|
$oss->uploadFile($config['bucket'],$filename,$path);
|
|
} catch(OssException $e) {
|
|
$this->error($e->getMessage(), url('admin/Video/video_list',['cid'=>$vd_cid]));//否则就是上传错误,显示错误原因
|
|
}
|
|
$file_url = $config['endpoint'].'/'.$filename;
|
|
//写入数据库
|
|
$data['uptime'] = time();
|
|
$data['filesize'] = $fileinfo['size'];
|
|
$data['path'] = $file_url;
|
|
Db::name('plug_files')->insert($data);
|
|
$fileall_url = $file_url;
|
|
}
|
|
}else{
|
|
$validate = config('upload_validate');
|
|
foreach ($files as $file) {
|
|
$info = $file->validate($validate)->rule('uniqid')->move(ROOT_PATH . config('upload_path') . DS . date('Y-m-d'));
|
|
if ($info) {
|
|
$file_url = config('upload_path'). '/' . date('Y-m-d') . '/' . $info->getFilename();
|
|
//写入数据库
|
|
$data['uptime'] = time();
|
|
$data['filesize'] = $info->getSize();
|
|
$data['path'] = $file_url;
|
|
Db::name('plug_files')->insert($data);
|
|
$fileall_url = $file_url;
|
|
} else {
|
|
$this->error($file->getError(), url('admin/Video/video_list',['cid'=>$vd_cid]));//否则就是上传错误,显示错误原因
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$file_path=request()->post('file_path');
|
|
if(empty($fileall_url)&&$file_path){
|
|
$fileall_url=$file_path;
|
|
}
|
|
$sl_data=array(
|
|
'vd_id'=>input('vd_id'),
|
|
'vd_name'=>input('vd_name'),
|
|
'vd_status'=>input('vd_status',0),
|
|
'vd_content'=>htmlspecialchars_decode(input('vd_content')),
|
|
'vd_order'=>input('vd_order',50,'intval'),
|
|
'vd_cid'=>$vd_cid
|
|
);
|
|
//图片字段处理
|
|
if(!empty($img_one)){
|
|
$sl_data['vd_img']=$img_one;
|
|
}
|
|
if(!empty($fileall_url)){
|
|
$sl_data['vd_video']=$fileall_url;
|
|
}
|
|
$rst=Db::name('video')->update($sl_data);
|
|
if($rst!==false){
|
|
$this->success('修改成功',url('admin/Video/video_list',['cid'=>$vd_cid]));
|
|
}else{
|
|
$this->error('修改失败',url('admin/Video/video_list',['cid'=>$vd_cid]));
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* 排序
|
|
*/
|
|
public function video_order()
|
|
{
|
|
$vd_cid=input('cid',0,'intval');
|
|
if (!request()->isAjax()){
|
|
if($vd_cid){
|
|
$this->error('提交方式不正确', url('admin/Video/video_list',['cid'=>$vd_cid]));
|
|
}else{
|
|
$this->error('提交方式不正确', url('admin/Video/video_list'));
|
|
}
|
|
}else{
|
|
foreach (input('post.') as $vd_id => $vd_order){
|
|
Db::name('video')->update(['vd_id'=>$vd_id,'vd_order'=>$vd_order]);
|
|
}
|
|
if($vd_cid){
|
|
$this->success('排序更新成功',url('admin/Video/video_list',['cid'=>$vd_cid]));
|
|
}else{
|
|
$this->success('排序更新成功',url('admin/Video/video_list'));
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* 删除(单个)
|
|
*/
|
|
public function video_del()
|
|
{
|
|
$p=input('p');
|
|
$rst=Db::name('video')->delete(input('vd_id'));
|
|
$vd_cid=input('cid',0,'intval');
|
|
if($rst!==false){
|
|
if($vd_cid){
|
|
$this->success('删除成功',url('admin/Video/video_list',array('p'=>$p,'cid'=>$vd_cid)));
|
|
}else{
|
|
$this->success('删除成功',url('admin/Video/video_list',array('p'=>$p)));
|
|
}
|
|
}else{
|
|
if($vd_cid){
|
|
$this -> error("删除失败!",url('admin/Video/video_list',array('p'=>$p,'cid'=>$vd_cid)));
|
|
}else{
|
|
$this -> error("删除失败!",url('admin/Video/video_list',array('p'=>$p)));
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* 删除(全选)
|
|
*/
|
|
public function video_alldel()
|
|
{
|
|
$p = input('p');
|
|
$ids = input('vd_id/a');
|
|
$vd_cid=input('cid',0,'intval');
|
|
if(empty($ids)){
|
|
if($vd_cid){
|
|
$this -> error("请选择待删除数据",url('admin/Video/video_list',array('p'=>$p,'cid'=>$vd_cid)));
|
|
}else{
|
|
$this -> error("请选择待删除数据",url('admin/Video/video_list',array('p'=>$p)));
|
|
}
|
|
}
|
|
if(is_array($ids)){
|
|
$where = 'vd_id in('.implode(',',$ids).')';
|
|
}else{
|
|
$where = 'vd_id='.$ids;
|
|
}
|
|
$rst=Db::name('video')->where($where)->delete();
|
|
if($rst!==false){
|
|
if($vd_cid){
|
|
$this->success("删除成功",url('admin/Video/video_list',array('p'=>$p,'cid'=>$vd_cid)));
|
|
}else{
|
|
$this->success("删除成功",url('admin/Video/video_list',array('p'=>$p)));
|
|
}
|
|
}else{
|
|
if($vd_cid){
|
|
$this -> error("删除失败!",url('admin/Video/video_list',array('p'=>$p,'cid'=>$vd_cid)));
|
|
}else{
|
|
$this -> error("删除失败!",url('admin/Video/video_list',array('p'=>$p)));
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* 审核/取消审核
|
|
*/
|
|
public function video_state()
|
|
{
|
|
$id=input('x');
|
|
$status=Db::name('video')->where(array('vd_id'=>$id))->value('vd_status');
|
|
if($status==1){
|
|
$statedata = array('vd_status'=>0);
|
|
Db::name('video')->where(array('vd_id'=>$id))->setField($statedata);
|
|
$this->success('未审');
|
|
}else{
|
|
$statedata = array('vd_status'=>1);
|
|
Db::name('video')->where(array('vd_id'=>$id))->setField($statedata);
|
|
$this->success('已审');
|
|
}
|
|
}
|
|
}
|