暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ZcPosition.php 46KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\admin\controller;
  14. use think\Page;
  15. use think\Db;
  16. use think\Cache;
  17. class ZcPosition extends Base
  18. {
  19. private $ad_position_system_id = array(); // 系统默认位置ID,不可删除
  20. public function _initialize() {
  21. parent::_initialize();
  22. }
  23. public function index()
  24. {
  25. $list = array();
  26. $get = input('get.');
  27. $keywords = input('keywords/s');
  28. $condition = [];
  29. // 应用搜索条件
  30. foreach (['keywords', 'type'] as $key) {
  31. $get[$key] = addslashes(trim($get[$key]));
  32. if (isset($get[$key]) && $get[$key] !== '') {
  33. if ($key == 'keywords') {
  34. $condition['a.title'] = array('LIKE', "%{$get[$key]}%");
  35. } else {
  36. $tmp_key = 'a.'.$key;
  37. $condition[$tmp_key] = array('eq', $get[$key]);
  38. }
  39. }
  40. }
  41. //增加地区条件
  42. if(!empty($get['map']) && $get['map'] == '-1'){
  43. }else{
  44. if(!empty($get['map']) && (int)$get['map'] > 0) {
  45. //查找
  46. $zc_ids = Db::name('zc_map')->where('map_id','=',(int)$get['map'])->column('zc_id');
  47. $condition['a.id'] = array('IN', $zc_ids);
  48. }else{
  49. if(isset($get['map'])) {
  50. $condition['a.type'] = array('eq', 0);
  51. }
  52. }
  53. }
  54. //var_dump($condition);
  55. // 多语言
  56. //$condition['a.lang'] = array('eq', $this->admin_lang);
  57. $adPositionM = Db::name('zc_position');
  58. $count = $adPositionM->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  59. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  60. $list = $adPositionM->alias('a')->where($condition)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->getAllWithIndex('id');
  61. //var_dump($condition);die;
  62. // 每组获取三张图片
  63. $pids = get_arr_column($list, 'id');
  64. $ad = Db::name('zc')
  65. ->where(['pid' => ['IN', $pids], 'lang' => $this->admin_lang])
  66. ->order('pid asc, id asc')
  67. ->select();
  68. foreach ($list as $k => $v) {
  69. /*
  70. if (1 == $v['type']) {
  71. // 图片封面图片
  72. $v['ad'] = [];
  73. foreach ($ad as $m => $n) {
  74. if ($v['id'] == $n['pid']) {
  75. $n['litpic'] = get_default_pic($n['litpic']); // 支持子目录
  76. $v['ad'][] = $n;
  77. unset($ad[$m]);
  78. } else {
  79. continue;
  80. }
  81. }
  82. // 若没有内容则显示默认图片
  83. if (empty($v['ad'])) {
  84. $v['ad_count'] = 0;
  85. $v['ad'][]['litpic'] = ROOT_DIR . '/public/static/common/images/not_adv.jpg';
  86. } else {
  87. $v['ad_count'] = count($v['ad']);
  88. }
  89. // 广告类型
  90. $v['type_name'] = '图片';
  91. } else if (2 == $v['type']) {
  92. // 多媒体封面图片
  93. $v['ad'][]['litpic'] = ROOT_DIR . '/public/static/admin/images/ad_type_media.png';
  94. // 广告类型
  95. $v['type_name'] = '多媒体';
  96. } else if (3 == $v['type']) {
  97. // HTML代码封面图片
  98. $v['ad'][]['litpic'] = ROOT_DIR . '/public/static/admin/images/ad_type_html.png';
  99. // 广告类型
  100. $v['type_name'] = 'HTML代码';
  101. }*/
  102. //处理图片
  103. $v['ad'] = [];
  104. foreach ($ad as $m => $n) {
  105. if ($v['id'] == $n['pid']) {
  106. $n['litpic'] = get_default_pic($n['litpic']); // 支持子目录
  107. $v['ad'][] = $n;
  108. unset($ad[$m]);
  109. } else {
  110. continue;
  111. }
  112. }
  113. // 若没有内容则显示默认图片
  114. if (empty($v['ad'])) {
  115. $v['ad_count'] = 0;
  116. $v['ad'][]['litpic'] = ROOT_DIR . '/public/static/common/images/not_adv.jpg';
  117. } else {
  118. $v['ad_count'] = count($v['ad']);
  119. }
  120. if((int)$v['type'] == 0){
  121. $v['type_name'] = '全国';
  122. }else{
  123. //获取中间表
  124. $map_ids = Db::name('zc_map')
  125. ->where('is_del','=',0)
  126. ->where('zc_id', $v['id'])
  127. ->column('map_id');
  128. //获取地区
  129. $oneList = Db::name('citysite')
  130. ->where('id','in',$map_ids)
  131. ->select();
  132. foreach ($oneList as $k2 => $v2) {
  133. $v['type_name'] .= $v2['name'].',';
  134. }
  135. }
  136. $list[$k] = $v;
  137. }
  138. $show = $Page->show();// 分页显示输出
  139. $this->assign('page',$show);// 赋值分页输出
  140. $this->assign('list',$list);// 赋值数据集
  141. $this->assign('pager',$Page);// 赋值分页对象
  142. /*多语言模式下,广告位ID显示主体语言的ID和属性title名称*/
  143. $main_adv_list = [];
  144. if ($this->admin_lang != $this->main_lang && empty($this->globalConfig['language_split'])) {
  145. $attr_values = get_arr_column($list, 'id');
  146. $languageAttrRow = Db::name('language_attr')->field('attr_name,attr_value')->where([
  147. 'attr_value' => ['IN', $attr_values],
  148. 'attr_group' => 'ad_position',
  149. 'lang' => $this->admin_lang,
  150. ])->getAllWithIndex('attr_value');
  151. $ids = [];
  152. foreach ($languageAttrRow as $key => $val) {
  153. $tid_tmp = str_replace('adp', '', $val['attr_name']);
  154. array_push($ids, intval($tid_tmp));
  155. }
  156. $main_advRow = Db::name('zc_position')->field("id,title,CONCAT('adp', id) AS attr_name")
  157. ->where([
  158. 'id' => ['IN', $ids],
  159. 'lang' => $this->main_lang,
  160. ])->getAllWithIndex('attr_name');
  161. foreach ($list as $key => $val) {
  162. $key_tmp = !empty($languageAttrRow[$val['id']]['attr_name']) ? $languageAttrRow[$val['id']]['attr_name'] : '';
  163. $main_adv_list[$val['id']] = [
  164. 'id' => !empty($main_advRow[$key_tmp]['id']) ? $main_advRow[$key_tmp]['id'] : '',
  165. 'title' => !empty($main_advRow[$key_tmp]['title']) ? $main_advRow[$key_tmp]['title'] : '',
  166. ];
  167. }
  168. }
  169. $this->assign('main_adv_list', $main_adv_list);
  170. /*end*/
  171. //查找区域数据
  172. $pro_list = Db::name('citysite')->where(['level'=>1,'is_open'=>1])->select();
  173. //var_dump($pro_list);
  174. $this->assign('pro_list', $pro_list);
  175. return $this->fetch();
  176. }
  177. /**
  178. * 新增
  179. */
  180. public function add()
  181. {
  182. //防止php超时
  183. function_exists('set_time_limit') && set_time_limit(0);
  184. if (is_language() && empty($this->globalConfig['language_split'])) {
  185. $this->language_access(); // 多语言功能操作权限
  186. }
  187. if (IS_POST) {
  188. $post = input('post.');
  189. //var_dump($post);
  190. //die;
  191. /*
  192. * 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) "" }
  193. */
  194. //var_dump($post);die;
  195. $map = array(
  196. 'title' => trim($post['title']),
  197. 'lang' => $this->admin_lang,
  198. );
  199. if(Db::name('zc_position')->where($map)->count() > 0){
  200. $this->error('该职称名称已存在,请检查', url('ZcPosition/index'));
  201. }
  202. if((int)$post['type'] === 1) {
  203. if(empty($post['map']) || !is_array($post['map'])) {
  204. $this->error('请选择至少一个地区', url('ZcPosition/index'));
  205. }
  206. }
  207. // 添加广告位置表信息
  208. $data = array(
  209. 'title' => trim($post['title']),
  210. 'type' => $post['type'], //职称地区 全国或者地区
  211. 'intro' => $post['intro'], //备注
  212. 'admin_id' => session('admin_id'),
  213. 'lang' => $this->admin_lang,
  214. 'add_time' => getTime(),
  215. 'update_time' => getTime(),
  216. );
  217. $insertID = Db::name('zc_position')->insertGetId($data);
  218. if (!empty($insertID)) {
  219. //处理多选
  220. if((int)$post['type'] === 1){
  221. //$post['map'] 已验证 是非空数组
  222. //插入中间表
  223. $map_data = [];
  224. foreach ($post['map'] as $k => $v) {
  225. $map_data[] = [
  226. 'map_id' => $v,
  227. 'zc_id' => $insertID,
  228. 'add_time' => time(),
  229. 'is_del' => 0,
  230. 'del_time' => 0
  231. ];
  232. }
  233. Db::name('zc_map')->insertAll($map_data);
  234. }else{
  235. //属于全国 不需要添加区域
  236. }
  237. // 同步广告位置ID到多语言的模板变量里,添加多语言广告位
  238. //$this->syn_add_language_attribute($insertID);
  239. // 读取组合广告位的图片及信息
  240. $AdData = [];
  241. if (!empty($post['img_litpic'])) { // 图片类型
  242. $i = 1;
  243. foreach ($post['img_litpic'] as $key => $value) {
  244. if (!empty($value)) {
  245. // 去掉http:
  246. $value = str_replace("http:", "", $value);
  247. // 去掉https:
  248. $value = str_replace("https:", "", $value);
  249. // 主要参数
  250. $AdData['litpic'] = $value;
  251. $AdData['pid'] = $insertID;
  252. $AdData['title'] = trim($post['img_title'][$key]);
  253. $AdData['links'] = $post['img_links'][$key];
  254. $AdData['intro'] = $post['img_intro'][$key];
  255. $target = !empty($post['img_target'][$key]) ? 1 : 0;
  256. $AdData['target'] = $target;
  257. // 其他参数
  258. $AdData['media_type'] = 1;
  259. $AdData['admin_id'] = session('admin_id');
  260. $AdData['lang'] = $this->admin_lang;
  261. $AdData['sort_order'] = $i++;
  262. $AdData['add_time'] = getTime();
  263. $AdData['update_time'] = getTime();
  264. // 添加到广告图表
  265. $ad_id = Db::name('zc')->add($AdData);
  266. // 同步多语言
  267. //$this->syn_add_ad_language_attribute($ad_id);
  268. }
  269. }
  270. }
  271. //Cache::clear('ad');
  272. adminLog('新增职称:'.$post['title']);
  273. $this->success("操作成功", url('ZcPosition/index'));
  274. } else {
  275. $this->error("操作失败", url('ZcPosition/index'));
  276. }
  277. }
  278. // 上传通道
  279. $WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select();
  280. $WeappOpen = [];
  281. foreach ($WeappConfig as $value) {
  282. if ('Qiniuyun' == $value['code']) {
  283. $WeappOpen['qny_open'] = $value['status'];
  284. } else if ('AliyunOss' == $value['code']) {
  285. $WeappOpen['oss_open'] = $value['status'];
  286. } else if ('Cos' == $value['code']) {
  287. $WeappOpen['cos_open'] = $value['status'];
  288. }
  289. }
  290. $this->assign('WeappOpen', $WeappOpen);
  291. // 系统最大上传视频的大小
  292. $upload_max_filesize = upload_max_filesize();
  293. $this->assign('upload_max_filesize', $upload_max_filesize);
  294. // 视频类型
  295. $media_type = tpCache('global.media_type');
  296. $media_type = !empty($media_type) ? $media_type : config('global.media_ext');
  297. $media_type = str_replace(",", "|", $media_type);
  298. $this->assign('media_type', $media_type);
  299. //查找区域数据
  300. $pro_list = Db::name('citysite')->where(['level'=>1,'is_open'=>1])->select();
  301. //var_dump($pro_list);
  302. $this->assign('pro_list', $pro_list);
  303. return $this->fetch();
  304. }
  305. /**
  306. * 编辑
  307. */
  308. public function edit()
  309. {
  310. if (IS_POST) {
  311. $post = input('post.');
  312. if (!empty($post['id'])) {
  313. $post['id'] = intval($post['id']);
  314. if (array_key_exists($post['id'], $this->ad_position_system_id)) {
  315. $this->error("不可更改系统预定义位置", url('ZcPosition/edit',array('id'=>$post['id'])));
  316. }
  317. /* 判断除自身外是否还有相同广告名称已存在 */
  318. $map = array(
  319. 'id' => array('NEQ', $post['id']),
  320. 'title' => trim($post['title']),
  321. //'lang' => $this->admin_lang,
  322. );
  323. if (Db::name('zc_position')->where($map)->count() > 0) $this->error('该职称名称已存在,请检查');
  324. /* END */
  325. if((int)$post['type'] === 1) {
  326. if(empty($post['map']) || !is_array($post['map'])) {
  327. $this->error('请选择至少一个地区', url('ZcPosition/index'));
  328. }
  329. }
  330. /* 判断广告是否切换广告类型 */
  331. // $where = [
  332. // 'id' => $post['id'],
  333. // 'type' => $post['type'],
  334. // 'lang' => $this->admin_lang
  335. // ];
  336. // if (Db::name('zc_position')->where($where)->count() == 0) {
  337. // // 已切换广告类型,清除广告中的广告内容
  338. // $where = [
  339. // 'pid' => $post['id'],
  340. // 'lang' => $this->admin_lang
  341. // ];
  342. // Db::name('zc')->where($where)->delete();
  343. // }
  344. /* END */
  345. /* 修改广告主体信息 */
  346. $data = array(
  347. 'id' => $post['id'],
  348. 'title' => trim($post['title']),
  349. 'type' => $post['type'], //全国或者地区
  350. 'intro' => $post['intro'],
  351. 'update_time' => getTime(),
  352. );
  353. $resultID = Db::name('zc_position')->update($data);
  354. /* END */
  355. }
  356. if (!empty($resultID)) {
  357. //处理多选
  358. if((int)$post['type'] === 1){
  359. //$post['map'] 已验证 是非空数组
  360. //先删除旧数据
  361. Db::name('zc_map')->where('zc_id','=',$post['id'])->where('is_del',0)->update([
  362. 'is_del' => 1,
  363. 'del_time' => time()
  364. ]);
  365. //插入中间表
  366. $map_data = [];
  367. foreach ($post['map'] as $k => $v) {
  368. $map_data[] = [
  369. 'map_id' => $v,
  370. 'zc_id' => $post['id'],
  371. 'add_time' => time(),
  372. 'is_del' => 0,
  373. 'del_time' => 0
  374. ];
  375. }
  376. Db::name('zc_map')->insertAll($map_data);
  377. }else{
  378. //属于全国 删除所有区域
  379. Db::name('zc_map')->where('zc_id','=',$post['id'])->where('is_del',0)->update([
  380. 'is_del' => 1,
  381. 'del_time' => time()
  382. ]);
  383. }
  384. $ad_db = Db::name('zc');
  385. if (!empty($post['img_litpic'])) { // 图片类型
  386. // 读取组合广告位的图片及信息
  387. $i = 1;
  388. foreach ($post['img_litpic'] as $key => $value) {
  389. if (!empty($value)) {
  390. // 去掉http:
  391. $value = str_replace("http:", "", $value);
  392. // 去掉https:
  393. $value = str_replace("https:", "", $value);
  394. // 是否新窗口打开
  395. $target = !empty($post['img_target'][$key]) ? 1 : 0;
  396. // 广告位ID,为空则表示添加
  397. $ad_id = $post['img_id'][$key];
  398. if (!empty($ad_id)) {
  399. // 查询更新条件
  400. $where = [
  401. 'id' => $ad_id,
  402. 'lang' => $this->admin_lang,
  403. ];
  404. if ($ad_db->where($where)->count() > 0) {
  405. // 主要参数
  406. $AdData['litpic'] = $value;
  407. $AdData['title'] = $post['img_title'][$key];
  408. $AdData['links'] = $post['img_links'][$key];
  409. $AdData['intro'] = $post['img_intro'][$key];
  410. $AdData['target'] = $target;
  411. // 其他参数
  412. $AdData['sort_order'] = $i++;
  413. $AdData['update_time'] = getTime();
  414. // 更新,不需要同步多语言
  415. $ad_db->where($where)->update($AdData);
  416. } else {
  417. // 主要参数
  418. $AdData['litpic'] = $value;
  419. $AdData['pid'] = $post['id'];
  420. $AdData['title'] = $post['img_title'][$key];
  421. $AdData['links'] = $post['img_links'][$key];
  422. $AdData['intro'] = $post['img_intro'][$key];
  423. $AdData['target'] = $target;
  424. // 其他参数
  425. $AdData['media_type'] = 1;
  426. $AdData['admin_id'] = session('admin_id');
  427. $AdData['lang'] = $this->admin_lang;
  428. $AdData['sort_order'] = $i++;
  429. $AdData['add_time'] = getTime();
  430. $AdData['update_time'] = getTime();
  431. $ad_id = $ad_db->add($AdData);
  432. // 同步多语言
  433. //$this->syn_add_ad_language_attribute($ad_id);
  434. }
  435. } else {
  436. // 主要参数
  437. $AdData['litpic'] = $value;
  438. $AdData['pid'] = $post['id'];
  439. $AdData['title'] = $post['img_title'][$key];
  440. $AdData['links'] = $post['img_links'][$key];
  441. $AdData['intro'] = $post['img_intro'][$key];
  442. $AdData['target'] = $target;
  443. // 其他参数
  444. $AdData['media_type'] = 1;
  445. $AdData['admin_id'] = session('admin_id');
  446. $AdData['lang'] = $this->admin_lang;
  447. $AdData['sort_order'] = $i++;
  448. $AdData['add_time'] = getTime();
  449. $AdData['update_time'] = getTime();
  450. $ad_id = $ad_db->add($AdData);
  451. // 同步多语言
  452. //$this->syn_add_ad_language_attribute($ad_id);
  453. }
  454. }
  455. }
  456. }
  457. //Cache::clear('ad');
  458. adminLog('编辑职称名称:'.$post['title']);
  459. $this->success("操作成功", url('ZcPosition/index'));
  460. } else {
  461. $this->error("操作失败");
  462. }
  463. }
  464. $assign_data = array();
  465. $id = input('id/d');
  466. $field = Db::name('zc_position')->field('a.*')->alias('a')->where(array('a.id'=>$id))->find();
  467. if (empty($field)) $this->error('职称不存在,请联系管理员!');
  468. switch ($field['type']) {
  469. case '1':
  470. $field['type_name'] = '图片';
  471. break;
  472. case '2':
  473. $field['type_name'] = '多媒体';
  474. break;
  475. case '3':
  476. $field['type_name'] = 'HTML代码';
  477. break;
  478. }
  479. $assign_data['field'] = $field;
  480. // 广告
  481. $ad_data = Db::name('zc')->where(array('pid'=>$field['id']))->order('sort_order asc')->select();
  482. foreach ($ad_data as $key => $val) {
  483. if (1 == $val['media_type']) {
  484. $ad_data[$key]['litpic'] = get_default_pic($val['litpic']); // 支持子目录
  485. }
  486. }
  487. $assign_data['ad_data'] = $ad_data;
  488. // 上传通道
  489. $WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select();
  490. $WeappOpen = [];
  491. foreach ($WeappConfig as $value) {
  492. if ('Qiniuyun' == $value['code']) {
  493. $WeappOpen['qny_open'] = $value['status'];
  494. } else if ('AliyunOss' == $value['code']) {
  495. $WeappOpen['oss_open'] = $value['status'];
  496. } else if ('Cos' == $value['code']) {
  497. $WeappOpen['cos_open'] = $value['status'];
  498. }
  499. }
  500. $this->assign('WeappOpen', $WeappOpen);
  501. // 系统最大上传视频的大小
  502. $file_size = tpCache('global.file_size');
  503. $postsize = @ini_get('file_uploads') ? ini_get('post_max_size') : -1;
  504. $fileupload = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : -1;
  505. $min_size = strval($file_size) < strval($postsize) ? $file_size : $postsize;
  506. $min_size = strval($min_size) < strval($fileupload) ? $min_size : $fileupload;
  507. $upload_max_filesize = intval($min_size) * 1024 * 1024;
  508. $assign_data['upload_max_filesize'] = $upload_max_filesize;
  509. // 视频类型
  510. $media_type = tpCache('global.media_type');
  511. $media_type = !empty($media_type) ? $media_type : config('global.media_ext');
  512. $media_type = str_replace(",", "|", $media_type);
  513. $assign_data['media_type'] = $media_type;
  514. //查询关联区域数据
  515. $map_list = Db::name('zc_map')->where(['zc_id'=>$field['id'],'is_del'=>0])->column('map_id');
  516. //var_dump($map_list);die();
  517. $this->assign('$map_list', $map_list);
  518. //查找区域数据
  519. $pro_list = Db::name('citysite')->where(['level'=>1,'is_open'=>1])->select();
  520. foreach ($pro_list as $k=>$v){
  521. if(in_array($v['id'],$map_list) === true){
  522. $pro_list[$k]['is_check'] = "checked";
  523. }else{
  524. $pro_list[$k]['is_check'] = '';
  525. }
  526. }
  527. //var_dump($pro_list);
  528. $this->assign('pro_list', $pro_list);
  529. $this->assign('curr_id', $field['type']);
  530. $this->assign($assign_data);
  531. return $this->fetch();
  532. }
  533. /**
  534. * 删除广告图片
  535. */
  536. public function del_imgupload()
  537. {
  538. if (is_language() && empty($this->globalConfig['language_split'])) {
  539. $this->language_access(); // 多语言功能操作权限
  540. }
  541. $id_arr = input('del_id/a');
  542. $id_arr = eyIntval($id_arr);
  543. if(IS_POST && !empty($id_arr)){
  544. /*多语言*/
  545. $attr_name_arr = [];
  546. if (empty($this->globalConfig['language_split'])) {
  547. foreach ($id_arr as $key => $val) {
  548. $attr_name_arr[] = 'ad'.$val;
  549. }
  550. if (is_language()) {
  551. $new_id_arr = Db::name('language_attr')->where([
  552. 'attr_name' => ['IN', $attr_name_arr],
  553. 'attr_group' => 'ad',
  554. ])->column('attr_value');
  555. !empty($new_id_arr) && $id_arr = $new_id_arr;
  556. }
  557. } else {
  558. if (get_admin_lang() == get_main_lang()) {
  559. foreach ($id_arr as $key => $val) {
  560. $attr_name_arr[] = 'ad'.$val;
  561. }
  562. }
  563. }
  564. /*--end*/
  565. $r = Db::name('zc')->where([
  566. 'id' => ['IN', $id_arr],
  567. ])
  568. ->delete();
  569. if ($r !== false) {
  570. /*多语言*/
  571. if (!empty($attr_name_arr)) {
  572. Db::name('language_attr')->where([
  573. 'attr_name' => ['IN', $attr_name_arr],
  574. 'attr_group' => 'ad',
  575. ])->delete();
  576. Db::name('language_attribute')->where([
  577. 'attr_name' => ['IN', $attr_name_arr],
  578. 'attr_group' => 'ad',
  579. ])->delete();
  580. }
  581. /*--end*/
  582. Cache::clear('ad');
  583. adminLog('删除广告-id:'.implode(',', $id_arr));
  584. }
  585. }
  586. }
  587. public function getZyList()
  588. {
  589. $id = request()->param('id');
  590. $list = Db::name('zczy_position')
  591. ->where(['is_del'=>0,'type'=>$id])
  592. ->order('type asc')
  593. ->select();
  594. $html = '<option value="0">请选择</option>';
  595. foreach ($list as $key => $value) {
  596. $html .= '<option value="'.$value['id'].'">'.$value['title'].'</option>';
  597. }
  598. $data = [
  599. 'code' => 0,
  600. 'msg' => '获取成功',
  601. 'data' => $html,
  602. ];
  603. return json($data);
  604. }
  605. public function getZsList()
  606. {
  607. $id = request()->param('id');
  608. $list = Db::name('zczs_position')
  609. ->where(['is_del'=>0,'type'=>$id])
  610. ->order('type asc')
  611. ->select();
  612. $html = '<option value="0">请选择</option>';
  613. foreach ($list as $key => $value) {
  614. $html .= '<option value="'.$value['id'].'">'.$value['title'].'</option>';
  615. }
  616. $data = [
  617. 'code' => 0,
  618. 'msg' => '获取成功',
  619. 'data' => $html,
  620. ];
  621. return json($data);
  622. }
  623. public function getZsType()
  624. {
  625. $id = request()->param('id');
  626. if($id == 0){
  627. $html = '<option value="0">请选择</option>';
  628. }else{
  629. //查询子集
  630. $list = Db::name('zc_type')
  631. ->where('pid','=',$id)
  632. ->where('is_del','=',0)
  633. ->select();
  634. $html = '<option value="0">请选择</option>';
  635. foreach ($list as $key => $value) {
  636. $html .= '<option value="'.$value['id'].'">'.$value['name'].'</option>';
  637. }
  638. }
  639. $data = [
  640. 'code' => 0,
  641. 'msg' => '获取成功',
  642. 'data' => $html,
  643. ];
  644. return json($data);
  645. }
  646. /*
  647. *
  648. */
  649. public function getDjList(){
  650. $id = request()->param('id');
  651. //查询组
  652. $list = Db::name('zcdj_position')->where('type',$id)->select();
  653. $html = '';
  654. foreach ($list as $key => $value) {
  655. $html .= '<span style="margin-right: 10px;">'.$value['title'].'</span>';
  656. }
  657. $data = [
  658. 'code' => 0,
  659. 'msg' => '获取成功',
  660. 'data' => $html,
  661. ];
  662. return json($data);
  663. }
  664. /*
  665. *
  666. * 原先的逻辑 是列出所有证书 再验证现有的 选中状态即可
  667. */
  668. public function choose(){
  669. $id = request()->get('id');
  670. $this->assign('id', $id);
  671. //查询该职称 已有哪些证书
  672. $map_ids = Db::name('zc_zs')->where(['zc_id'=>$id,'is_del'=>0])->column('map_id');
  673. //var_dump($map_ids);
  674. //查询证书列表
  675. /*$list = Db::name('zczs_position')->where(['is_del'=>0])->order('type asc')->select();
  676. foreach ($list as $k=>$v){
  677. if(in_array($v['id'],$map_ids)){
  678. $v['is_check'] = "checked";
  679. }else{
  680. $v['is_check'] = '';
  681. }
  682. $new_data[$v['type']][] = $v;
  683. }*/
  684. $list = Db::name('zczs_position')
  685. ->where(['is_del'=>0])
  686. ->where('id','in',$map_ids)
  687. ->order('type asc')->select();
  688. foreach ($list as $k=>$v){
  689. $v['is_check'] = "checked";
  690. $new_data[$v['type']][] = $v;
  691. }
  692. $this->assign('pro_list', $new_data);
  693. //调用一级分类
  694. $pro_list_t = Db::name('zc_type')
  695. ->where('pid',0)
  696. ->where('is_del',0)
  697. ->where('catid',1)
  698. ->select();
  699. /*foreach ($one as $k=>$item) {
  700. Db::name('zc_type')->where('pid',$item['id'])->select();
  701. }*/
  702. //$pro_list_t = ['初级','中级','高级'];
  703. $this->assign('pro_list_t', $pro_list_t);
  704. return $this->fetch();
  705. }
  706. public function choosePost(){
  707. $post = request()->post();
  708. $map = $post['map'];
  709. $id = $post['id'];
  710. //删除旧数据
  711. Db::name('zc_zs')->where(['zc_id'=>$id,'is_del'=>0])->update(['is_del'=>1,'del_time'=>time()]);
  712. //插入新数据
  713. $map_data = [];
  714. foreach ($map as $k => $v) {
  715. $map_data[] = [
  716. 'map_id' => $v,
  717. 'zc_id' => $id,
  718. 'add_time' => time(),
  719. 'is_del' => 0,
  720. 'del_time' => 0
  721. ];
  722. }
  723. Db::name('zc_zs')->insertAll($map_data);
  724. $this->success("操作成功", url('ZcPosition/index'));
  725. }
  726. public function choose2(){
  727. $id = request()->get('id');
  728. $this->assign('id', $id);
  729. //查询该职称 已有哪些证书
  730. $map_ids = Db::name('zc_zy')->where(['zc_id'=>$id,'is_del'=>0])->column('map_id');
  731. //查询证书列表
  732. /*$list = Db::name('zczy_position')->where(['is_del'=>0])->order('type asc')->select();
  733. foreach ($list as $k=>$v){
  734. if(in_array($v['id'],$map_ids)){
  735. $v['is_check'] = "checked";
  736. }else{
  737. $v['is_check'] = '';
  738. }
  739. $new_data[$v['type']][] = $v;
  740. }*/
  741. $list = Db::name('zczy_position')
  742. ->where(['is_del'=>0])
  743. ->where('id','in',$map_ids)
  744. ->order('type asc')->select();
  745. foreach ($list as $k=>$v){
  746. $v['is_check'] = "checked";
  747. $new_data[$v['type']][] = $v;
  748. }
  749. $this->assign('pro_list', $new_data);
  750. //调用一级分类
  751. $pro_list_t = Db::name('zc_type')
  752. ->where('pid',0)
  753. ->where('is_del',0)
  754. ->where('catid',2)
  755. ->select();
  756. /*foreach ($one as $k=>$item) {
  757. Db::name('zc_type')->where('pid',$item['id'])->select();
  758. }*/
  759. //$pro_list_t = ['通类','计算机科学','理学','哲学类','教育学类','医学类','中国语言文学类','历史学类','经济学类','法学','体育学类','工商管理类','军事学','新闻传播学类','公共管理类','中医学类','药学类','政治学类','社会学类','艺术类','生物科学类','农学','其他'];
  760. $this->assign('pro_list_t', $pro_list_t);
  761. return $this->fetch();
  762. }
  763. public function choosePost2(){
  764. $post = request()->post();
  765. $map = $post['map'];
  766. $id = $post['id'];
  767. //删除旧数据
  768. Db::name('zc_zy')->where(['zc_id'=>$id,'is_del'=>0])->update(['is_del'=>1,'del_time'=>time()]);
  769. //插入新数据
  770. $map_data = [];
  771. foreach ($map as $k => $v) {
  772. $map_data[] = [
  773. 'map_id' => $v,
  774. 'zc_id' => $id,
  775. 'add_time' => time(),
  776. 'is_del' => 0,
  777. 'del_time' => 0
  778. ];
  779. }
  780. Db::name('zc_zy')->insertAll($map_data);
  781. $this->success("操作成功", url('ZcPosition/index'));
  782. }
  783. public function choose3(){
  784. $id = request()->get('id');
  785. $this->assign('id', $id);
  786. //调用一级分类
  787. $pro_list_t = Db::name('zc_type')
  788. ->where('pid',0)
  789. ->where('is_del',0)
  790. ->where('catid',3)
  791. ->select();
  792. /*foreach ($one as $k=>$item) {
  793. Db::name('zc_type')->where('pid',$item['id'])->select();
  794. }*/
  795. //$pro_list_t = ['通类','计算机科学','理学','哲学类','教育学类','医学类','中国语言文学类','历史学类','经济学类','法学','体育学类','工商管理类','军事学','新闻传播学类','公共管理类','中医学类','药学类','政治学类','社会学类','艺术类','生物科学类','农学','其他'];
  796. $this->assign('pro_list_t', $pro_list_t);
  797. $row = Db::name('zc_position')->where('id',$id)->find();
  798. //调用二级分类
  799. $two = Db::name('zc_type')->where('id',$row['dj_group_id'])->find();
  800. $this->assign('curr_id2', $two['id']);
  801. $this->assign('curr_id', $two['pid']);
  802. $pro_list_p = Db::name('zc_type')->where('pid',$two['pid'])->select();
  803. //var_dump($pro_list_p);
  804. $this->assign('pro_list_p', $pro_list_p);
  805. //当前等级ID dj_group_id
  806. $dj_group_id = $row['dj_group_id'];
  807. $list = Db::name('zcdj_position')->where('type',$dj_group_id)->select();
  808. $this->assign('pro_list', $list);
  809. return $this->fetch();
  810. }
  811. public function choosePost3()
  812. {
  813. $param = request()->param();
  814. $id = $param['id'];
  815. //组id $param['type2']
  816. if((int)$param['type2'] > 0){
  817. $data = [
  818. 'dj_group_id' => (int)$param['type2'],
  819. 'update_time' => time(),
  820. ];
  821. $res = Db::name('zc_position')->where('id',$id)->update($data);
  822. //var_dump($res);
  823. $this->success("操作成功", url('ZcPosition/index'));
  824. }else{
  825. $this->error('请选择等级组');
  826. }
  827. }
  828. /**
  829. * 删除
  830. */
  831. public function del()
  832. {
  833. if (is_language() && empty($this->globalConfig['language_split'])) {
  834. $this->language_access(); // 多语言功能操作权限
  835. }
  836. $id_arr = input('del_id/a');
  837. $id_arr = eyIntval($id_arr);
  838. if(IS_POST && !empty($id_arr)){
  839. foreach ($id_arr as $key => $val) {
  840. if(array_key_exists($val, $this->ad_position_system_id)){
  841. $this->error('系统预定义,不能删除');
  842. }
  843. }
  844. /*多语言*/
  845. $attr_name_arr = [];
  846. foreach ($id_arr as $key => $val) {
  847. $attr_name_arr[] = 'adp'.$val;
  848. }
  849. if (is_language() && empty($this->globalConfig['language_split'])) {
  850. $new_id_arr = Db::name('language_attr')->where([
  851. 'attr_name' => ['IN', $attr_name_arr],
  852. 'attr_group' => 'ad_position',
  853. ])->column('attr_value');
  854. !empty($new_id_arr) && $id_arr = $new_id_arr;
  855. }
  856. /*--end*/
  857. $r = Db::name('zc_position')->where('id','IN',$id_arr)->delete();
  858. if ($r !== false) {
  859. /*多语言*/
  860. if (!empty($attr_name_arr)) {
  861. if (get_admin_lang() == get_main_lang()) {
  862. Db::name('language_attribute')->where([
  863. 'attr_name' => ['IN', $attr_name_arr],
  864. 'attr_group' => 'ad_position',
  865. ])->delete();
  866. }
  867. if (empty($this->globalConfig['language_split'])) {
  868. Db::name('language_attr')->where([
  869. 'attr_name' => ['IN', $attr_name_arr],
  870. 'attr_group' => 'ad_position',
  871. ])->delete();
  872. } else {
  873. Db::name('language_attr')->where([
  874. 'attr_value' => ['IN', $id_arr],
  875. 'attr_group' => 'ad_position',
  876. ])->delete();
  877. }
  878. }
  879. /*--end*/
  880. $ad_ids = Db::name('zc')->where(['pid'=>['IN', $id_arr]])->column('id');
  881. $attr_name_arr = [];
  882. foreach ($ad_ids as $key => $val) {
  883. $attr_name_arr[] = "ad{$val}";
  884. }
  885. $r1 = Db::name('zc')->where('pid','IN',$id_arr)->delete();
  886. if ($r1 !== false) {
  887. /*多语言*/
  888. if (!empty($attr_name_arr)) {
  889. if (get_admin_lang() == get_main_lang()) {
  890. Db::name('language_attribute')->where([
  891. 'attr_name' => ['IN', $attr_name_arr],
  892. 'attr_group' => 'ad',
  893. ])->delete();
  894. }
  895. if (empty($this->globalConfig['language_split'])) {
  896. Db::name('language_attr')->where([
  897. 'attr_name' => ['IN', $attr_name_arr],
  898. 'attr_group' => 'ad',
  899. ])->delete();
  900. } else {
  901. Db::name('language_attr')->where([
  902. 'attr_value' => ['IN', $ad_ids],
  903. 'attr_group' => 'ad',
  904. ])->delete();
  905. }
  906. }
  907. /*--end*/
  908. }
  909. Cache::clear('ad');
  910. adminLog('删除广告-id:'.implode(',', $id_arr));
  911. $this->success('删除成功');
  912. } else {
  913. $this->error('删除失败');
  914. }
  915. }else{
  916. $this->error('参数有误');
  917. }
  918. }
  919. /**
  920. * 打开预览视频
  921. */
  922. public function open_preview_video()
  923. {
  924. $post = input('post.');
  925. $video_litpic = $post['video_litpic'];
  926. if (!is_http_url($video_litpic)) {
  927. $video_litpic = request()->domain() . handle_subdir_pic($video_litpic, 'media');
  928. }
  929. $this->success('执行成功', $video_litpic);
  930. }
  931. /**
  932. * 检测广告名称是否存在重复
  933. */
  934. public function detection_title_repeat()
  935. {
  936. if (IS_AJAX_POST) {
  937. $post = input('post.');
  938. $where = [
  939. 'id' => ['NEQ', $post['id']],
  940. 'title' => trim($post['title']),
  941. 'lang' => $this->admin_lang,
  942. ];
  943. $count = Db::name('zc_position')->where($where)->count();
  944. if (empty($count)) {
  945. $this->success('检测通过');
  946. } else {
  947. $this->error('该广告名称已存在,请检查');
  948. }
  949. }
  950. }
  951. /**
  952. * 同步新增广告位置ID到多语言的模板变量里
  953. */
  954. private function syn_add_language_attribute($adp_id)
  955. {
  956. /*单语言情况下不执行多语言代码*/
  957. if (!is_language() || tpCache('language.language_split')) {
  958. return true;
  959. }
  960. /*--end*/
  961. $attr_group = 'ad_position';
  962. $admin_lang = $this->admin_lang;
  963. $main_lang = $this->main_lang;
  964. $languageRow = Db::name('language')->field('mark')->order('id asc')->select();
  965. if (!empty($languageRow) && $admin_lang == $main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
  966. $ad_position_db = Db::name('zc_position');
  967. $result = $ad_position_db->find($adp_id);
  968. $attr_name = 'adp'.$adp_id;
  969. $r = Db::name('language_attribute')->save([
  970. 'attr_title' => $result['title'],
  971. 'attr_name' => $attr_name,
  972. 'attr_group' => $attr_group,
  973. 'add_time' => getTime(),
  974. 'update_time' => getTime(),
  975. ]);
  976. if (false !== $r) {
  977. $data = [];
  978. foreach ($languageRow as $key => $val) {
  979. /*同步新广告位置到其他语言广告位置列表*/
  980. if ($val['mark'] != $admin_lang) {
  981. $addsaveData = $result;
  982. $addsaveData['lang'] = $val['mark'];
  983. $addsaveData['title'] = $val['mark'].$addsaveData['title'];
  984. unset($addsaveData['id']);
  985. $adp_id = $ad_position_db->insertGetId($addsaveData);
  986. }
  987. /*--end*/
  988. /*所有语言绑定在主语言的ID容器里*/
  989. $data[] = [
  990. 'attr_name' => $attr_name,
  991. 'attr_value' => $adp_id,
  992. 'lang' => $val['mark'],
  993. 'attr_group' => $attr_group,
  994. 'add_time' => getTime(),
  995. 'update_time' => getTime(),
  996. ];
  997. /*--end*/
  998. }
  999. if (!empty($data)) {
  1000. model('LanguageAttr')->saveAll($data);
  1001. }
  1002. }
  1003. }
  1004. }
  1005. /**
  1006. * 同步新增广告ID到多语言的模板变量里
  1007. */
  1008. private function syn_add_ad_language_attribute($ad_id)
  1009. {
  1010. /*单语言情况下不执行多语言代码*/
  1011. if (!is_language() || tpCache('language.language_split')) {
  1012. return true;
  1013. }
  1014. /*--end*/
  1015. $attr_group = 'ad';
  1016. $admin_lang = $this->admin_lang;
  1017. $main_lang = get_main_lang();
  1018. $languageRow = Db::name('language')->field('mark')->order('id asc')->select();
  1019. if (!empty($languageRow) && $admin_lang == $main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
  1020. $ad_db = Db::name('zc');
  1021. $result = $ad_db->find($ad_id);
  1022. $attr_name = 'ad'.$ad_id;
  1023. $r = Db::name('language_attribute')->save([
  1024. 'attr_title' => $result['title'],
  1025. 'attr_name' => $attr_name,
  1026. 'attr_group' => $attr_group,
  1027. 'add_time' => getTime(),
  1028. 'update_time' => getTime(),
  1029. ]);
  1030. if (false !== $r) {
  1031. $data = [];
  1032. foreach ($languageRow as $key => $val) {
  1033. /*同步新广告到其他语言广告列表*/
  1034. if ($val['mark'] != $admin_lang) {
  1035. $addsaveData = $result;
  1036. $addsaveData['lang'] = $val['mark'];
  1037. $newPid = Db::name('language_attr')->where([
  1038. 'attr_name' => 'adp'.$result['pid'],
  1039. 'attr_group' => 'ad_position',
  1040. 'lang' => $val['mark'],
  1041. ])->getField('attr_value');
  1042. $addsaveData['pid'] = $newPid;
  1043. $addsaveData['title'] = $val['mark'].$addsaveData['title'];
  1044. unset($addsaveData['id']);
  1045. $ad_id = $ad_db->insertGetId($addsaveData);
  1046. }
  1047. /*--end*/
  1048. /*所有语言绑定在主语言的ID容器里*/
  1049. $data[] = [
  1050. 'attr_name' => $attr_name,
  1051. 'attr_value' => $ad_id,
  1052. 'lang' => $val['mark'],
  1053. 'attr_group' => $attr_group,
  1054. 'add_time' => getTime(),
  1055. 'update_time' => getTime(),
  1056. ];
  1057. /*--end*/
  1058. }
  1059. if (!empty($data)) {
  1060. model('LanguageAttr')->saveAll($data);
  1061. }
  1062. }
  1063. }
  1064. }
  1065. }