Bez popisu
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.

ZczyPosition.php 44KB

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