No Description
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.

ZczsPosition.php 44KB

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