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

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