* Date: 2018-4-3 */ namespace app\admin\controller; use think\Page; use think\Db; class Casevideo extends Base { private $ad_position_system_id = array(); // 系统默认位置ID,不可删除 public function _initialize() { parent::_initialize(); } public function index() { $list = array(); $get = input('get.'); $keywords = input('keywords/s'); $condition = []; // 应用搜索条件 foreach (['keywords', 'type'] as $key) { if (isset($get[$key]) && $get[$key] !== '') { if ($key == 'keywords') { $condition['a.title'] = array('LIKE', "%{$get[$key]}%"); } else { $tmp_key = 'a.'.$key; $condition[$tmp_key] = array('eq', $get[$key]); } } } // 多语言 // $condition['a.lang'] = array('eq', $this->admin_lang); $adPositionM = M('casevideo'); $count = $adPositionM->alias('a')->where($condition)->count();// 查询满足要求的总记录数 $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数 $list = $adPositionM->alias('a')->where($condition)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->getAllWithIndex('id'); // 每组获取三张图片 $pids = get_arr_column($list, 'id'); $ad = M('ad')->where(['pid' => ['IN', $pids], 'lang' => $this->admin_lang])->order('pid asc, id asc')->select(); foreach ($list as $k => $v) { $v['createtime'] = date('Y-m-d H:i:s',$v['createtime']); // 支持子目录 $v['litpic'] = ROOT_DIR . '/public/static/admin/images/ad_type_media.png'; $list[$k] = $v; } $show = $Page->show();// 分页显示输出 $this->assign('page',$show);// 赋值分页输出 $this->assign('list',$list);// 赋值数据集 $this->assign('pager',$Page);// 赋值分页对象 return $this->fetch(); } /** * 新增 */ public function add() { //防止php超时 function_exists('set_time_limit') && set_time_limit(0); $this->language_access(); // 多语言功能操作权限 if (IS_POST) { $post = input('post.'); // 添加广告位置表信息 $data = array( 'title' => trim($post['title']), 'video'=>$post['video_litpic'], 'admin_id' => session('admin_id'), 'createtime' => getTime(), ); $insertID = M('casevideo')->insertGetId($data); if (!empty($insertID)) { adminLog('新增平台:'.$post['title']); $this->success("操作成功", url('casevideo/index')); } else { $this->error("操作失败", url('casevideo/index')); } } // 上传通道 $WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select(); $WeappOpen = []; foreach ($WeappConfig as $value) { if ('Qiniuyun' == $value['code']) { $WeappOpen['qny_open'] = $value['status']; } else if ('AliyunOss' == $value['code']) { $WeappOpen['oss_open'] = $value['status']; } else if ('Cos' == $value['code']) { $WeappOpen['cos_open'] = $value['status']; } } $this->assign('WeappOpen', $WeappOpen); // 系统最大上传视频的大小 $upload_max_filesize = upload_max_filesize(); $this->assign('upload_max_filesize', $upload_max_filesize); // 视频类型 $media_type = tpCache('basic.media_type'); $media_type = !empty($media_type) ? $media_type : config('global.media_ext'); $media_type = str_replace(",", "|", $media_type); $this->assign('media_type', $media_type); return $this->fetch(); } /** * 编辑 */ public function edit() { if (IS_POST) { $post = input('post.'); if (!empty($post['id'])) { // if (array_key_exists($post['id'], $this->ad_position_system_id)) { // $this->error("不可更改系统预定义位置", url('Platform/edit',array('id'=>$post['id']))); // } $data = array( 'id' => $post['id'], 'title' => trim($post['title']), 'video'=>$post['video_litpic'], 'createtime' => getTime(), ); $resultID = Db::name('casevideo')->update($data); /* END */ } if (!empty($resultID)) { adminLog('编辑广告:'.$post['title']); $this->success("操作成功", url('casevideo/index')); } else { $this->error("操作失败"); } } $assign_data = array(); $id = input('id/d'); $field = M('casevideo')->field('a.*')->alias('a')->where(array('a.id'=>$id))->find(); if (empty($field)) $this->error('广告不存在,请联系管理员!'); $assign_data['field'] = $field; /* // 广告 $ad_data = Db::name('ad')->where(array('pid'=>$field['id']))->order('sort_order asc')->select(); foreach ($ad_data as $key => $val) { if (1 == $val['type']) { $ad_data[$key]['litpic'] = get_default_pic($val['litpic']); // 支持子目录 } } $assign_data['ad_data'] = $ad_data;*/ // 上传通道 $WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select(); $WeappOpen = []; foreach ($WeappConfig as $value) { if ('Qiniuyun' == $value['code']) { $WeappOpen['qny_open'] = $value['status']; } else if ('AliyunOss' == $value['code']) { $WeappOpen['oss_open'] = $value['status']; } else if ('Cos' == $value['code']) { $WeappOpen['cos_open'] = $value['status']; } } $this->assign('WeappOpen', $WeappOpen); // 系统最大上传视频的大小 $file_size = tpCache('basic.file_size'); $postsize = @ini_get('file_uploads') ? ini_get('post_max_size') : -1; $fileupload = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : -1; $min_size = strval($file_size) < strval($postsize) ? $file_size : $postsize; $min_size = strval($min_size) < strval($fileupload) ? $min_size : $fileupload; $upload_max_filesize = intval($min_size) * 1024 * 1024; $assign_data['upload_max_filesize'] = $upload_max_filesize; // 视频类型 $media_type = tpCache('basic.media_type'); $media_type = !empty($media_type) ? $media_type : config('global.media_ext'); $media_type = str_replace(",", "|", $media_type); $assign_data['media_type'] = $media_type; $this->assign($assign_data); return $this->fetch(); } /** * 删除广告图片 */ public function del_imgupload() { $this->language_access(); // 多语言功能操作权限 $id_arr = input('del_id/a'); $id_arr = eyIntval($id_arr); if(IS_POST && !empty($id_arr)){ /*多语言*/ $attr_name_arr = []; foreach ($id_arr as $key => $val) { $attr_name_arr[] = 'ad'.$val; } if (is_language()) { $new_id_arr = Db::name('language_attr')->where([ 'attr_name' => ['IN', $attr_name_arr], 'attr_group' => 'ad', ])->column('attr_value'); !empty($new_id_arr) && $id_arr = $new_id_arr; } /*--end*/ $r = Db::name('ad')->where([ 'id' => ['IN', $id_arr], ]) ->cache(true,null,'ad') ->delete(); if ($r) { /*多语言*/ if (!empty($attr_name_arr)) { Db::name('language_attr')->where([ 'attr_name' => ['IN', $attr_name_arr], 'attr_group' => 'ad', ])->delete(); Db::name('language_attribute')->where([ 'attr_name' => ['IN', $attr_name_arr], 'attr_group' => 'ad', ])->delete(); } /*--end*/ adminLog('删除广告-id:'.implode(',', $id_arr)); } } } /** * 删除 */ public function del() { $this->language_access(); // 多语言功能操作权限 $id_arr = input('del_id/a'); $id_arr = eyIntval($id_arr); if(IS_POST && !empty($id_arr)){ $r = M('casevideo')->where('id','IN',$id_arr)->delete(); if ($r) { adminLog('删除广告-id:'.implode(',', $id_arr)); $this->success('删除成功'); } else { $this->error('删除1失败'); } }else{ $this->error('参数有误'); } } }