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.

ZcwdPosition.php 46KB

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