* Date: 2018-4-3
*/
namespace app\admin\controller;
use think\Page;
use think\Db;
use think\Cache;
class ZcPosition 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) {
$get[$key] = addslashes(trim($get[$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]);
}
}
}
//增加地区条件
if(!empty($get['map']) && $get['map'] == '-1'){
}else{
if(!empty($get['map']) && (int)$get['map'] > 0) {
//查找
$zc_ids = Db::name('zc_map')->where('map_id','=',(int)$get['map'])->column('zc_id');
$condition['a.id'] = array('IN', $zc_ids);
}else{
if(isset($get['map'])) {
$condition['a.type'] = array('eq', 0);
}
}
}
//var_dump($condition);
// 多语言
//$condition['a.lang'] = array('eq', $this->admin_lang);
$adPositionM = Db::name('zc_position');
$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');
//var_dump($condition);die;
// 每组获取三张图片
$pids = get_arr_column($list, 'id');
$ad = Db::name('zc')
->where(['pid' => ['IN', $pids], 'lang' => $this->admin_lang])
->order('pid asc, id asc')
->select();
foreach ($list as $k => $v) {
/*
if (1 == $v['type']) {
// 图片封面图片
$v['ad'] = [];
foreach ($ad as $m => $n) {
if ($v['id'] == $n['pid']) {
$n['litpic'] = get_default_pic($n['litpic']); // 支持子目录
$v['ad'][] = $n;
unset($ad[$m]);
} else {
continue;
}
}
// 若没有内容则显示默认图片
if (empty($v['ad'])) {
$v['ad_count'] = 0;
$v['ad'][]['litpic'] = ROOT_DIR . '/public/static/common/images/not_adv.jpg';
} else {
$v['ad_count'] = count($v['ad']);
}
// 广告类型
$v['type_name'] = '图片';
} else if (2 == $v['type']) {
// 多媒体封面图片
$v['ad'][]['litpic'] = ROOT_DIR . '/public/static/admin/images/ad_type_media.png';
// 广告类型
$v['type_name'] = '多媒体';
} else if (3 == $v['type']) {
// HTML代码封面图片
$v['ad'][]['litpic'] = ROOT_DIR . '/public/static/admin/images/ad_type_html.png';
// 广告类型
$v['type_name'] = 'HTML代码';
}*/
//处理图片
$v['ad'] = [];
foreach ($ad as $m => $n) {
if ($v['id'] == $n['pid']) {
$n['litpic'] = get_default_pic($n['litpic']); // 支持子目录
$v['ad'][] = $n;
unset($ad[$m]);
} else {
continue;
}
}
// 若没有内容则显示默认图片
if (empty($v['ad'])) {
$v['ad_count'] = 0;
$v['ad'][]['litpic'] = ROOT_DIR . '/public/static/common/images/not_adv.jpg';
} else {
$v['ad_count'] = count($v['ad']);
}
if((int)$v['type'] == 0){
$v['type_name'] = '全国';
}else{
//获取中间表
$map_ids = Db::name('zc_map')
->where('is_del','=',0)
->where('zc_id', $v['id'])
->column('map_id');
//获取地区
$oneList = Db::name('citysite')
->where('id','in',$map_ids)
->select();
foreach ($oneList as $k2 => $v2) {
$v['type_name'] .= $v2['name'].',';
}
}
$list[$k] = $v;
}
$show = $Page->show();// 分页显示输出
$this->assign('page',$show);// 赋值分页输出
$this->assign('list',$list);// 赋值数据集
$this->assign('pager',$Page);// 赋值分页对象
/*多语言模式下,广告位ID显示主体语言的ID和属性title名称*/
$main_adv_list = [];
if ($this->admin_lang != $this->main_lang && empty($this->globalConfig['language_split'])) {
$attr_values = get_arr_column($list, 'id');
$languageAttrRow = Db::name('language_attr')->field('attr_name,attr_value')->where([
'attr_value' => ['IN', $attr_values],
'attr_group' => 'ad_position',
'lang' => $this->admin_lang,
])->getAllWithIndex('attr_value');
$ids = [];
foreach ($languageAttrRow as $key => $val) {
$tid_tmp = str_replace('adp', '', $val['attr_name']);
array_push($ids, intval($tid_tmp));
}
$main_advRow = Db::name('zc_position')->field("id,title,CONCAT('adp', id) AS attr_name")
->where([
'id' => ['IN', $ids],
'lang' => $this->main_lang,
])->getAllWithIndex('attr_name');
foreach ($list as $key => $val) {
$key_tmp = !empty($languageAttrRow[$val['id']]['attr_name']) ? $languageAttrRow[$val['id']]['attr_name'] : '';
$main_adv_list[$val['id']] = [
'id' => !empty($main_advRow[$key_tmp]['id']) ? $main_advRow[$key_tmp]['id'] : '',
'title' => !empty($main_advRow[$key_tmp]['title']) ? $main_advRow[$key_tmp]['title'] : '',
];
}
}
$this->assign('main_adv_list', $main_adv_list);
/*end*/
//查找区域数据
$pro_list = Db::name('citysite')->where(['level'=>1,'is_open'=>1])->select();
//var_dump($pro_list);
$this->assign('pro_list', $pro_list);
return $this->fetch();
}
/**
* 新增
*/
public function add()
{
//防止php超时
function_exists('set_time_limit') && set_time_limit(0);
if (is_language() && empty($this->globalConfig['language_split'])) {
$this->language_access(); // 多语言功能操作权限
}
if (IS_POST) {
$post = input('post.');
//var_dump($post);
//die;
/*
* array(11) { ["title"]=> string(12) "建筑职称" ["type"]=> string(1) "1" ["img_id"]=> array(1) { [0]=> string(0) "" } ["img_litpic"]=> array(1) { [0]=> string(67) "https://oss.zc10000.com/uploads/allimg/20240528/1-24052R01005Z4.png" } ["img_title"]=> array(1) { [0]=> string(0) "" } ["img_links"]=> array(1) { [0]=> string(0) "" } ["img_intro"]=> array(1) { [0]=> string(0) "" } ["img_target"]=> array(1) { [0]=> string(1) "0" } ["video_litpic"]=> string(0) "" ["html_intro"]=> string(0) "" ["intro"]=> string(0) "" }
*/
//var_dump($post);die;
$map = array(
'title' => trim($post['title']),
'lang' => $this->admin_lang,
);
if(Db::name('zc_position')->where($map)->count() > 0){
$this->error('该职称名称已存在,请检查', url('ZcPosition/index'));
}
if((int)$post['type'] === 1) {
if(empty($post['map']) || !is_array($post['map'])) {
$this->error('请选择至少一个地区', url('ZcPosition/index'));
}
}
// 添加广告位置表信息
$data = array(
'title' => trim($post['title']),
'type' => $post['type'], //职称地区 全国或者地区
'intro' => $post['intro'], //备注
'admin_id' => session('admin_id'),
'lang' => $this->admin_lang,
'add_time' => getTime(),
'update_time' => getTime(),
);
$insertID = Db::name('zc_position')->insertGetId($data);
if (!empty($insertID)) {
//处理多选
if((int)$post['type'] === 1){
//$post['map'] 已验证 是非空数组
//插入中间表
$map_data = [];
foreach ($post['map'] as $k => $v) {
$map_data[] = [
'map_id' => $v,
'zc_id' => $insertID,
'add_time' => time(),
'is_del' => 0,
'del_time' => 0
];
}
Db::name('zc_map')->insertAll($map_data);
}else{
//属于全国 不需要添加区域
}
// 同步广告位置ID到多语言的模板变量里,添加多语言广告位
//$this->syn_add_language_attribute($insertID);
// 读取组合广告位的图片及信息
$AdData = [];
if (!empty($post['img_litpic'])) { // 图片类型
$i = 1;
foreach ($post['img_litpic'] as $key => $value) {
if (!empty($value)) {
// 去掉http:
$value = str_replace("http:", "", $value);
// 去掉https:
$value = str_replace("https:", "", $value);
// 主要参数
$AdData['litpic'] = $value;
$AdData['pid'] = $insertID;
$AdData['title'] = trim($post['img_title'][$key]);
$AdData['links'] = $post['img_links'][$key];
$AdData['intro'] = $post['img_intro'][$key];
$target = !empty($post['img_target'][$key]) ? 1 : 0;
$AdData['target'] = $target;
// 其他参数
$AdData['media_type'] = 1;
$AdData['admin_id'] = session('admin_id');
$AdData['lang'] = $this->admin_lang;
$AdData['sort_order'] = $i++;
$AdData['add_time'] = getTime();
$AdData['update_time'] = getTime();
// 添加到广告图表
$ad_id = Db::name('zc')->add($AdData);
// 同步多语言
//$this->syn_add_ad_language_attribute($ad_id);
}
}
}
//Cache::clear('ad');
adminLog('新增职称:'.$post['title']);
$this->success("操作成功", url('ZcPosition/index'));
} else {
$this->error("操作失败", url('ZcPosition/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('global.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);
//查找区域数据
$pro_list = Db::name('citysite')->where(['level'=>1,'is_open'=>1])->select();
//var_dump($pro_list);
$this->assign('pro_list', $pro_list);
return $this->fetch();
}
/**
* 编辑
*/
public function edit()
{
if (IS_POST) {
$post = input('post.');
if (!empty($post['id'])) {
$post['id'] = intval($post['id']);
if (array_key_exists($post['id'], $this->ad_position_system_id)) {
$this->error("不可更改系统预定义位置", url('ZcPosition/edit',array('id'=>$post['id'])));
}
/* 判断除自身外是否还有相同广告名称已存在 */
$map = array(
'id' => array('NEQ', $post['id']),
'title' => trim($post['title']),
//'lang' => $this->admin_lang,
);
if (Db::name('zc_position')->where($map)->count() > 0) $this->error('该职称名称已存在,请检查');
/* END */
if((int)$post['type'] === 1) {
if(empty($post['map']) || !is_array($post['map'])) {
$this->error('请选择至少一个地区', url('ZcPosition/index'));
}
}
/* 判断广告是否切换广告类型 */
// $where = [
// 'id' => $post['id'],
// 'type' => $post['type'],
// 'lang' => $this->admin_lang
// ];
// if (Db::name('zc_position')->where($where)->count() == 0) {
// // 已切换广告类型,清除广告中的广告内容
// $where = [
// 'pid' => $post['id'],
// 'lang' => $this->admin_lang
// ];
// Db::name('zc')->where($where)->delete();
// }
/* END */
/* 修改广告主体信息 */
$data = array(
'id' => $post['id'],
'title' => trim($post['title']),
'type' => $post['type'], //全国或者地区
'intro' => $post['intro'],
'update_time' => getTime(),
);
$resultID = Db::name('zc_position')->update($data);
/* END */
}
if (!empty($resultID)) {
//处理多选
if((int)$post['type'] === 1){
//$post['map'] 已验证 是非空数组
//先删除旧数据
Db::name('zc_map')->where('zc_id','=',$post['id'])->where('is_del',0)->update([
'is_del' => 1,
'del_time' => time()
]);
//插入中间表
$map_data = [];
foreach ($post['map'] as $k => $v) {
$map_data[] = [
'map_id' => $v,
'zc_id' => $post['id'],
'add_time' => time(),
'is_del' => 0,
'del_time' => 0
];
}
Db::name('zc_map')->insertAll($map_data);
}else{
//属于全国 删除所有区域
Db::name('zc_map')->where('zc_id','=',$post['id'])->where('is_del',0)->update([
'is_del' => 1,
'del_time' => time()
]);
}
$ad_db = Db::name('zc');
if (!empty($post['img_litpic'])) { // 图片类型
// 读取组合广告位的图片及信息
$i = 1;
foreach ($post['img_litpic'] as $key => $value) {
if (!empty($value)) {
// 去掉http:
$value = str_replace("http:", "", $value);
// 去掉https:
$value = str_replace("https:", "", $value);
// 是否新窗口打开
$target = !empty($post['img_target'][$key]) ? 1 : 0;
// 广告位ID,为空则表示添加
$ad_id = $post['img_id'][$key];
if (!empty($ad_id)) {
// 查询更新条件
$where = [
'id' => $ad_id,
'lang' => $this->admin_lang,
];
if ($ad_db->where($where)->count() > 0) {
// 主要参数
$AdData['litpic'] = $value;
$AdData['title'] = $post['img_title'][$key];
$AdData['links'] = $post['img_links'][$key];
$AdData['intro'] = $post['img_intro'][$key];
$AdData['target'] = $target;
// 其他参数
$AdData['sort_order'] = $i++;
$AdData['update_time'] = getTime();
// 更新,不需要同步多语言
$ad_db->where($where)->update($AdData);
} else {
// 主要参数
$AdData['litpic'] = $value;
$AdData['pid'] = $post['id'];
$AdData['title'] = $post['img_title'][$key];
$AdData['links'] = $post['img_links'][$key];
$AdData['intro'] = $post['img_intro'][$key];
$AdData['target'] = $target;
// 其他参数
$AdData['media_type'] = 1;
$AdData['admin_id'] = session('admin_id');
$AdData['lang'] = $this->admin_lang;
$AdData['sort_order'] = $i++;
$AdData['add_time'] = getTime();
$AdData['update_time'] = getTime();
$ad_id = $ad_db->add($AdData);
// 同步多语言
//$this->syn_add_ad_language_attribute($ad_id);
}
} else {
// 主要参数
$AdData['litpic'] = $value;
$AdData['pid'] = $post['id'];
$AdData['title'] = $post['img_title'][$key];
$AdData['links'] = $post['img_links'][$key];
$AdData['intro'] = $post['img_intro'][$key];
$AdData['target'] = $target;
// 其他参数
$AdData['media_type'] = 1;
$AdData['admin_id'] = session('admin_id');
$AdData['lang'] = $this->admin_lang;
$AdData['sort_order'] = $i++;
$AdData['add_time'] = getTime();
$AdData['update_time'] = getTime();
$ad_id = $ad_db->add($AdData);
// 同步多语言
//$this->syn_add_ad_language_attribute($ad_id);
}
}
}
}
//Cache::clear('ad');
adminLog('编辑职称名称:'.$post['title']);
$this->success("操作成功", url('ZcPosition/index'));
} else {
$this->error("操作失败");
}
}
$assign_data = array();
$id = input('id/d');
$field = Db::name('zc_position')->field('a.*')->alias('a')->where(array('a.id'=>$id))->find();
if (empty($field)) $this->error('职称不存在,请联系管理员!');
switch ($field['type']) {
case '1':
$field['type_name'] = '图片';
break;
case '2':
$field['type_name'] = '多媒体';
break;
case '3':
$field['type_name'] = 'HTML代码';
break;
}
$assign_data['field'] = $field;
// 广告
$ad_data = Db::name('zc')->where(array('pid'=>$field['id']))->order('sort_order asc')->select();
foreach ($ad_data as $key => $val) {
if (1 == $val['media_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('global.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('global.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;
//查询关联区域数据
$map_list = Db::name('zc_map')->where(['zc_id'=>$field['id'],'is_del'=>0])->column('map_id');
//var_dump($map_list);die();
$this->assign('$map_list', $map_list);
//查找区域数据
$pro_list = Db::name('citysite')->where(['level'=>1,'is_open'=>1])->select();
foreach ($pro_list as $k=>$v){
if(in_array($v['id'],$map_list) === true){
$pro_list[$k]['is_check'] = "checked";
}else{
$pro_list[$k]['is_check'] = '';
}
}
//var_dump($pro_list);
$this->assign('pro_list', $pro_list);
$this->assign('curr_id', $field['type']);
$this->assign($assign_data);
return $this->fetch();
}
/**
* 删除广告图片
*/
public function del_imgupload()
{
if (is_language() && empty($this->globalConfig['language_split'])) {
$this->language_access(); // 多语言功能操作权限
}
$id_arr = input('del_id/a');
$id_arr = eyIntval($id_arr);
if(IS_POST && !empty($id_arr)){
/*多语言*/
$attr_name_arr = [];
if (empty($this->globalConfig['language_split'])) {
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;
}
} else {
if (get_admin_lang() == get_main_lang()) {
foreach ($id_arr as $key => $val) {
$attr_name_arr[] = 'ad'.$val;
}
}
}
/*--end*/
$r = Db::name('zc')->where([
'id' => ['IN', $id_arr],
])
->delete();
if ($r !== false) {
/*多语言*/
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*/
Cache::clear('ad');
adminLog('删除广告-id:'.implode(',', $id_arr));
}
}
}
public function getZyList()
{
$id = request()->param('id');
$list = Db::name('zczy_position')
->where(['is_del'=>0,'type'=>$id])
->order('type asc')
->select();
$html = '';
foreach ($list as $key => $value) {
$html .= '';
}
$data = [
'code' => 0,
'msg' => '获取成功',
'data' => $html,
];
return json($data);
}
public function getZsList()
{
$id = request()->param('id');
$list = Db::name('zczs_position')
->where(['is_del'=>0,'type'=>$id])
->order('type asc')
->select();
$html = '';
foreach ($list as $key => $value) {
$html .= '';
}
$data = [
'code' => 0,
'msg' => '获取成功',
'data' => $html,
];
return json($data);
}
public function getZsType()
{
$id = request()->param('id');
if($id == 0){
$html = '';
}else{
//查询子集
$list = Db::name('zc_type')
->where('pid','=',$id)
->where('is_del','=',0)
->select();
$html = '';
foreach ($list as $key => $value) {
$html .= '';
}
}
$data = [
'code' => 0,
'msg' => '获取成功',
'data' => $html,
];
return json($data);
}
/*
*
*/
public function getDjList(){
$id = request()->param('id');
//查询组
$list = Db::name('zcdj_position')->where('type',$id)->select();
$html = '';
foreach ($list as $key => $value) {
$html .= ''.$value['title'].'';
}
$data = [
'code' => 0,
'msg' => '获取成功',
'data' => $html,
];
return json($data);
}
/*
*
* 原先的逻辑 是列出所有证书 再验证现有的 选中状态即可
*/
public function choose(){
$id = request()->get('id');
$this->assign('id', $id);
//查询该职称 已有哪些证书
$map_ids = Db::name('zc_zs')->where(['zc_id'=>$id,'is_del'=>0])->column('map_id');
//var_dump($map_ids);
//查询证书列表
/*$list = Db::name('zczs_position')->where(['is_del'=>0])->order('type asc')->select();
foreach ($list as $k=>$v){
if(in_array($v['id'],$map_ids)){
$v['is_check'] = "checked";
}else{
$v['is_check'] = '';
}
$new_data[$v['type']][] = $v;
}*/
$list = Db::name('zczs_position')
->where(['is_del'=>0])
->where('id','in',$map_ids)
->order('type asc')->select();
foreach ($list as $k=>$v){
$v['is_check'] = "checked";
$new_data[$v['type']][] = $v;
}
$this->assign('pro_list', $new_data);
//调用一级分类
$pro_list_t = Db::name('zc_type')
->where('pid',0)
->where('is_del',0)
->where('catid',1)
->select();
/*foreach ($one as $k=>$item) {
Db::name('zc_type')->where('pid',$item['id'])->select();
}*/
//$pro_list_t = ['初级','中级','高级'];
$this->assign('pro_list_t', $pro_list_t);
return $this->fetch();
}
public function choosePost(){
$post = request()->post();
$map = $post['map'];
$id = $post['id'];
//删除旧数据
Db::name('zc_zs')->where(['zc_id'=>$id,'is_del'=>0])->update(['is_del'=>1,'del_time'=>time()]);
//插入新数据
$map_data = [];
foreach ($map as $k => $v) {
$map_data[] = [
'map_id' => $v,
'zc_id' => $id,
'add_time' => time(),
'is_del' => 0,
'del_time' => 0
];
}
Db::name('zc_zs')->insertAll($map_data);
$this->success("操作成功", url('ZcPosition/index'));
}
public function choose2(){
$id = request()->get('id');
$this->assign('id', $id);
//查询该职称 已有哪些证书
$map_ids = Db::name('zc_zy')->where(['zc_id'=>$id,'is_del'=>0])->column('map_id');
//查询证书列表
/*$list = Db::name('zczy_position')->where(['is_del'=>0])->order('type asc')->select();
foreach ($list as $k=>$v){
if(in_array($v['id'],$map_ids)){
$v['is_check'] = "checked";
}else{
$v['is_check'] = '';
}
$new_data[$v['type']][] = $v;
}*/
$list = Db::name('zczy_position')
->where(['is_del'=>0])
->where('id','in',$map_ids)
->order('type asc')->select();
foreach ($list as $k=>$v){
$v['is_check'] = "checked";
$new_data[$v['type']][] = $v;
}
$this->assign('pro_list', $new_data);
//调用一级分类
$pro_list_t = Db::name('zc_type')
->where('pid',0)
->where('is_del',0)
->where('catid',2)
->select();
/*foreach ($one as $k=>$item) {
Db::name('zc_type')->where('pid',$item['id'])->select();
}*/
//$pro_list_t = ['通类','计算机科学','理学','哲学类','教育学类','医学类','中国语言文学类','历史学类','经济学类','法学','体育学类','工商管理类','军事学','新闻传播学类','公共管理类','中医学类','药学类','政治学类','社会学类','艺术类','生物科学类','农学','其他'];
$this->assign('pro_list_t', $pro_list_t);
return $this->fetch();
}
public function choosePost2(){
$post = request()->post();
$map = $post['map'];
$id = $post['id'];
//删除旧数据
Db::name('zc_zy')->where(['zc_id'=>$id,'is_del'=>0])->update(['is_del'=>1,'del_time'=>time()]);
//插入新数据
$map_data = [];
foreach ($map as $k => $v) {
$map_data[] = [
'map_id' => $v,
'zc_id' => $id,
'add_time' => time(),
'is_del' => 0,
'del_time' => 0
];
}
Db::name('zc_zy')->insertAll($map_data);
$this->success("操作成功", url('ZcPosition/index'));
}
public function choose3(){
$id = request()->get('id');
$this->assign('id', $id);
//调用一级分类
$pro_list_t = Db::name('zc_type')
->where('pid',0)
->where('is_del',0)
->where('catid',3)
->select();
/*foreach ($one as $k=>$item) {
Db::name('zc_type')->where('pid',$item['id'])->select();
}*/
//$pro_list_t = ['通类','计算机科学','理学','哲学类','教育学类','医学类','中国语言文学类','历史学类','经济学类','法学','体育学类','工商管理类','军事学','新闻传播学类','公共管理类','中医学类','药学类','政治学类','社会学类','艺术类','生物科学类','农学','其他'];
$this->assign('pro_list_t', $pro_list_t);
$row = Db::name('zc_position')->where('id',$id)->find();
//调用二级分类
$two = Db::name('zc_type')->where('id',$row['dj_group_id'])->find();
$this->assign('curr_id2', $two['id']);
$this->assign('curr_id', $two['pid']);
$pro_list_p = Db::name('zc_type')->where('pid',$two['pid'])->select();
//var_dump($pro_list_p);
$this->assign('pro_list_p', $pro_list_p);
//当前等级ID dj_group_id
$dj_group_id = $row['dj_group_id'];
$list = Db::name('zcdj_position')->where('type',$dj_group_id)->select();
$this->assign('pro_list', $list);
return $this->fetch();
}
public function choosePost3()
{
$param = request()->param();
$id = $param['id'];
//组id $param['type2']
if((int)$param['type2'] > 0){
$data = [
'dj_group_id' => (int)$param['type2'],
'update_time' => time(),
];
$res = Db::name('zc_position')->where('id',$id)->update($data);
//var_dump($res);
$this->success("操作成功", url('ZcPosition/index'));
}else{
$this->error('请选择等级组');
}
}
/**
* 删除
*/
public function del()
{
if (is_language() && empty($this->globalConfig['language_split'])) {
$this->language_access(); // 多语言功能操作权限
}
$id_arr = input('del_id/a');
$id_arr = eyIntval($id_arr);
if(IS_POST && !empty($id_arr)){
foreach ($id_arr as $key => $val) {
if(array_key_exists($val, $this->ad_position_system_id)){
$this->error('系统预定义,不能删除');
}
}
/*多语言*/
$attr_name_arr = [];
foreach ($id_arr as $key => $val) {
$attr_name_arr[] = 'adp'.$val;
}
if (is_language() && empty($this->globalConfig['language_split'])) {
$new_id_arr = Db::name('language_attr')->where([
'attr_name' => ['IN', $attr_name_arr],
'attr_group' => 'ad_position',
])->column('attr_value');
!empty($new_id_arr) && $id_arr = $new_id_arr;
}
/*--end*/
$r = Db::name('zc_position')->where('id','IN',$id_arr)->delete();
if ($r !== false) {
/*多语言*/
if (!empty($attr_name_arr)) {
if (get_admin_lang() == get_main_lang()) {
Db::name('language_attribute')->where([
'attr_name' => ['IN', $attr_name_arr],
'attr_group' => 'ad_position',
])->delete();
}
if (empty($this->globalConfig['language_split'])) {
Db::name('language_attr')->where([
'attr_name' => ['IN', $attr_name_arr],
'attr_group' => 'ad_position',
])->delete();
} else {
Db::name('language_attr')->where([
'attr_value' => ['IN', $id_arr],
'attr_group' => 'ad_position',
])->delete();
}
}
/*--end*/
$ad_ids = Db::name('zc')->where(['pid'=>['IN', $id_arr]])->column('id');
$attr_name_arr = [];
foreach ($ad_ids as $key => $val) {
$attr_name_arr[] = "ad{$val}";
}
$r1 = Db::name('zc')->where('pid','IN',$id_arr)->delete();
if ($r1 !== false) {
/*多语言*/
if (!empty($attr_name_arr)) {
if (get_admin_lang() == get_main_lang()) {
Db::name('language_attribute')->where([
'attr_name' => ['IN', $attr_name_arr],
'attr_group' => 'ad',
])->delete();
}
if (empty($this->globalConfig['language_split'])) {
Db::name('language_attr')->where([
'attr_name' => ['IN', $attr_name_arr],
'attr_group' => 'ad',
])->delete();
} else {
Db::name('language_attr')->where([
'attr_value' => ['IN', $ad_ids],
'attr_group' => 'ad',
])->delete();
}
}
/*--end*/
}
Cache::clear('ad');
adminLog('删除广告-id:'.implode(',', $id_arr));
$this->success('删除成功');
} else {
$this->error('删除失败');
}
}else{
$this->error('参数有误');
}
}
/**
* 打开预览视频
*/
public function open_preview_video()
{
$post = input('post.');
$video_litpic = $post['video_litpic'];
if (!is_http_url($video_litpic)) {
$video_litpic = request()->domain() . handle_subdir_pic($video_litpic, 'media');
}
$this->success('执行成功', $video_litpic);
}
/**
* 检测广告名称是否存在重复
*/
public function detection_title_repeat()
{
if (IS_AJAX_POST) {
$post = input('post.');
$where = [
'id' => ['NEQ', $post['id']],
'title' => trim($post['title']),
'lang' => $this->admin_lang,
];
$count = Db::name('zc_position')->where($where)->count();
if (empty($count)) {
$this->success('检测通过');
} else {
$this->error('该广告名称已存在,请检查');
}
}
}
/**
* 同步新增广告位置ID到多语言的模板变量里
*/
private function syn_add_language_attribute($adp_id)
{
/*单语言情况下不执行多语言代码*/
if (!is_language() || tpCache('language.language_split')) {
return true;
}
/*--end*/
$attr_group = 'ad_position';
$admin_lang = $this->admin_lang;
$main_lang = $this->main_lang;
$languageRow = Db::name('language')->field('mark')->order('id asc')->select();
if (!empty($languageRow) && $admin_lang == $main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
$ad_position_db = Db::name('zc_position');
$result = $ad_position_db->find($adp_id);
$attr_name = 'adp'.$adp_id;
$r = Db::name('language_attribute')->save([
'attr_title' => $result['title'],
'attr_name' => $attr_name,
'attr_group' => $attr_group,
'add_time' => getTime(),
'update_time' => getTime(),
]);
if (false !== $r) {
$data = [];
foreach ($languageRow as $key => $val) {
/*同步新广告位置到其他语言广告位置列表*/
if ($val['mark'] != $admin_lang) {
$addsaveData = $result;
$addsaveData['lang'] = $val['mark'];
$addsaveData['title'] = $val['mark'].$addsaveData['title'];
unset($addsaveData['id']);
$adp_id = $ad_position_db->insertGetId($addsaveData);
}
/*--end*/
/*所有语言绑定在主语言的ID容器里*/
$data[] = [
'attr_name' => $attr_name,
'attr_value' => $adp_id,
'lang' => $val['mark'],
'attr_group' => $attr_group,
'add_time' => getTime(),
'update_time' => getTime(),
];
/*--end*/
}
if (!empty($data)) {
model('LanguageAttr')->saveAll($data);
}
}
}
}
/**
* 同步新增广告ID到多语言的模板变量里
*/
private function syn_add_ad_language_attribute($ad_id)
{
/*单语言情况下不执行多语言代码*/
if (!is_language() || tpCache('language.language_split')) {
return true;
}
/*--end*/
$attr_group = 'ad';
$admin_lang = $this->admin_lang;
$main_lang = get_main_lang();
$languageRow = Db::name('language')->field('mark')->order('id asc')->select();
if (!empty($languageRow) && $admin_lang == $main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
$ad_db = Db::name('zc');
$result = $ad_db->find($ad_id);
$attr_name = 'ad'.$ad_id;
$r = Db::name('language_attribute')->save([
'attr_title' => $result['title'],
'attr_name' => $attr_name,
'attr_group' => $attr_group,
'add_time' => getTime(),
'update_time' => getTime(),
]);
if (false !== $r) {
$data = [];
foreach ($languageRow as $key => $val) {
/*同步新广告到其他语言广告列表*/
if ($val['mark'] != $admin_lang) {
$addsaveData = $result;
$addsaveData['lang'] = $val['mark'];
$newPid = Db::name('language_attr')->where([
'attr_name' => 'adp'.$result['pid'],
'attr_group' => 'ad_position',
'lang' => $val['mark'],
])->getField('attr_value');
$addsaveData['pid'] = $newPid;
$addsaveData['title'] = $val['mark'].$addsaveData['title'];
unset($addsaveData['id']);
$ad_id = $ad_db->insertGetId($addsaveData);
}
/*--end*/
/*所有语言绑定在主语言的ID容器里*/
$data[] = [
'attr_name' => $attr_name,
'attr_value' => $ad_id,
'lang' => $val['mark'],
'attr_group' => $attr_group,
'add_time' => getTime(),
'update_time' => getTime(),
];
/*--end*/
}
if (!empty($data)) {
model('LanguageAttr')->saveAll($data);
}
}
}
}
}