Sin descripción
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.

AdPosition.php 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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 AdPosition 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('ad_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. // 每组获取三张图片
  48. $pids = get_arr_column($list, 'id');
  49. $ad = Db::name('ad')->where(['pid' => ['IN', $pids], 'lang' => $this->admin_lang])->order('pid asc, id asc')->select();
  50. foreach ($list as $k => $v) {
  51. if (1 == $v['type']) {
  52. // 图片封面图片
  53. $v['ad'] = [];
  54. foreach ($ad as $m => $n) {
  55. if ($v['id'] == $n['pid']) {
  56. $n['litpic'] = get_default_pic($n['litpic']); // 支持子目录
  57. $v['ad'][] = $n;
  58. unset($ad[$m]);
  59. } else {
  60. continue;
  61. }
  62. }
  63. // 若没有内容则显示默认图片
  64. if (empty($v['ad'])) {
  65. $v['ad_count'] = 0;
  66. $v['ad'][]['litpic'] = ROOT_DIR . '/public/static/common/images/not_adv.jpg';
  67. } else {
  68. $v['ad_count'] = count($v['ad']);
  69. }
  70. // 广告类型
  71. $v['type_name'] = '图片';
  72. } else if (2 == $v['type']) {
  73. // 多媒体封面图片
  74. $v['ad'][]['litpic'] = ROOT_DIR . '/public/static/admin/images/ad_type_media.png';
  75. // 广告类型
  76. $v['type_name'] = '多媒体';
  77. } else if (3 == $v['type']) {
  78. // HTML代码封面图片
  79. $v['ad'][]['litpic'] = ROOT_DIR . '/public/static/admin/images/ad_type_html.png';
  80. // 广告类型
  81. $v['type_name'] = 'HTML代码';
  82. }
  83. $list[$k] = $v;
  84. }
  85. $show = $Page->show();// 分页显示输出
  86. $this->assign('page',$show);// 赋值分页输出
  87. $this->assign('list',$list);// 赋值数据集
  88. $this->assign('pager',$Page);// 赋值分页对象
  89. /*多语言模式下,广告位ID显示主体语言的ID和属性title名称*/
  90. $main_adv_list = [];
  91. if ($this->admin_lang != $this->main_lang && empty($this->globalConfig['language_split'])) {
  92. $attr_values = get_arr_column($list, 'id');
  93. $languageAttrRow = Db::name('language_attr')->field('attr_name,attr_value')->where([
  94. 'attr_value' => ['IN', $attr_values],
  95. 'attr_group' => 'ad_position',
  96. 'lang' => $this->admin_lang,
  97. ])->getAllWithIndex('attr_value');
  98. $ids = [];
  99. foreach ($languageAttrRow as $key => $val) {
  100. $tid_tmp = str_replace('adp', '', $val['attr_name']);
  101. array_push($ids, intval($tid_tmp));
  102. }
  103. $main_advRow = Db::name('ad_position')->field("id,title,CONCAT('adp', id) AS attr_name")
  104. ->where([
  105. 'id' => ['IN', $ids],
  106. 'lang' => $this->main_lang,
  107. ])->getAllWithIndex('attr_name');
  108. foreach ($list as $key => $val) {
  109. $key_tmp = !empty($languageAttrRow[$val['id']]['attr_name']) ? $languageAttrRow[$val['id']]['attr_name'] : '';
  110. $main_adv_list[$val['id']] = [
  111. 'id' => !empty($main_advRow[$key_tmp]['id']) ? $main_advRow[$key_tmp]['id'] : '',
  112. 'title' => !empty($main_advRow[$key_tmp]['title']) ? $main_advRow[$key_tmp]['title'] : '',
  113. ];
  114. }
  115. }
  116. $this->assign('main_adv_list', $main_adv_list);
  117. /*end*/
  118. return $this->fetch();
  119. }
  120. /**
  121. * 新增
  122. */
  123. public function add()
  124. {
  125. //防止php超时
  126. function_exists('set_time_limit') && set_time_limit(0);
  127. if (is_language() && empty($this->globalConfig['language_split'])) {
  128. $this->language_access(); // 多语言功能操作权限
  129. }
  130. if (IS_POST) {
  131. $post = input('post.');
  132. $map = array(
  133. 'title' => trim($post['title']),
  134. 'lang' => $this->admin_lang,
  135. );
  136. if(Db::name('ad_position')->where($map)->count() > 0){
  137. $this->error('该广告名称已存在,请检查', url('AdPosition/index'));
  138. }
  139. // 添加广告位置表信息
  140. $data = array(
  141. 'title' => trim($post['title']),
  142. 'type' => $post['type'],
  143. 'intro' => $post['intro'],
  144. 'admin_id' => session('admin_id'),
  145. 'lang' => $this->admin_lang,
  146. 'add_time' => getTime(),
  147. 'update_time' => getTime(),
  148. );
  149. $insertID = Db::name('ad_position')->insertGetId($data);
  150. if (!empty($insertID)) {
  151. // 同步广告位置ID到多语言的模板变量里,添加多语言广告位
  152. $this->syn_add_language_attribute($insertID);
  153. // 读取组合广告位的图片及信息
  154. $AdData = [];
  155. if (1 == $post['type'] && !empty($post['img_litpic'])) { // 图片类型
  156. $i = 1;
  157. foreach ($post['img_litpic'] as $key => $value) {
  158. if (!empty($value)) {
  159. // 去掉http:
  160. $value = str_replace("http:", "", $value);
  161. // 去掉https:
  162. $value = str_replace("https:", "", $value);
  163. // 主要参数
  164. $AdData['litpic'] = $value;
  165. $AdData['pid'] = $insertID;
  166. $AdData['title'] = trim($post['img_title'][$key]);
  167. $AdData['links'] = $post['img_links'][$key];
  168. $AdData['intro'] = $post['img_intro'][$key];
  169. $target = !empty($post['img_target'][$key]) ? 1 : 0;
  170. $AdData['target'] = $target;
  171. // 其他参数
  172. $AdData['media_type'] = 1;
  173. $AdData['admin_id'] = session('admin_id');
  174. $AdData['lang'] = $this->admin_lang;
  175. $AdData['sort_order'] = $i++;
  176. $AdData['add_time'] = getTime();
  177. $AdData['update_time'] = getTime();
  178. // 添加到广告图表
  179. $ad_id = Db::name('ad')->add($AdData);
  180. // 同步多语言
  181. $this->syn_add_ad_language_attribute($ad_id);
  182. }
  183. }
  184. } else if (2 == $post['type'] && !empty($post['video_litpic'])) { // 媒体类型
  185. // 去掉http:
  186. $video_litpic = str_replace("http:", "", $post['video_litpic']);
  187. // 去掉https:
  188. $video_litpic = str_replace("https:", "", $post['video_litpic']);
  189. // 主要参数
  190. $AdData['litpic'] = $video_litpic;
  191. $AdData['pid'] = $insertID;
  192. $AdData['title'] = trim($post['title']);
  193. // 其他参数
  194. $AdData['intro'] = '';
  195. $AdData['links'] = '';
  196. $AdData['target'] = 0;
  197. $AdData['media_type'] = 2;
  198. $AdData['admin_id'] = session('admin_id');
  199. $AdData['lang'] = $this->admin_lang;
  200. $AdData['sort_order'] = 1;
  201. $AdData['add_time'] = getTime();
  202. $AdData['update_time'] = getTime();
  203. // 添加到广告图表
  204. $ad_id = Db::name('ad')->add($AdData);
  205. // 同步多语言
  206. $this->syn_add_ad_language_attribute($ad_id);
  207. } else if (3 == $post['type'] && !empty($post['html_intro'])) { // HTML代码
  208. // 主要参数
  209. $AdData['pid'] = $insertID;
  210. $AdData['title'] = trim($post['title']);
  211. $AdData['intro'] = $post['html_intro'];
  212. // 其他参数
  213. $AdData['litpic'] = '';
  214. $AdData['links'] = '';
  215. $AdData['target'] = 0;
  216. $AdData['media_type'] = 3;
  217. $AdData['admin_id'] = session('admin_id');
  218. $AdData['lang'] = $this->admin_lang;
  219. $AdData['sort_order'] = 1;
  220. $AdData['add_time'] = getTime();
  221. $AdData['update_time'] = getTime();
  222. // 添加到广告图表
  223. $ad_id = Db::name('ad')->add($AdData);
  224. // 同步多语言
  225. $this->syn_add_ad_language_attribute($ad_id);
  226. }
  227. Cache::clear('ad');
  228. adminLog('新增广告:'.$post['title']);
  229. $this->success("操作成功", url('AdPosition/index'));
  230. } else {
  231. $this->error("操作失败", url('AdPosition/index'));
  232. }
  233. }
  234. // 上传通道
  235. $WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select();
  236. $WeappOpen = [];
  237. foreach ($WeappConfig as $value) {
  238. if ('Qiniuyun' == $value['code']) {
  239. $WeappOpen['qny_open'] = $value['status'];
  240. } else if ('AliyunOss' == $value['code']) {
  241. $WeappOpen['oss_open'] = $value['status'];
  242. } else if ('Cos' == $value['code']) {
  243. $WeappOpen['cos_open'] = $value['status'];
  244. }
  245. }
  246. $this->assign('WeappOpen', $WeappOpen);
  247. // 系统最大上传视频的大小
  248. $upload_max_filesize = upload_max_filesize();
  249. $this->assign('upload_max_filesize', $upload_max_filesize);
  250. // 视频类型
  251. $media_type = tpCache('global.media_type');
  252. $media_type = !empty($media_type) ? $media_type : config('global.media_ext');
  253. $media_type = str_replace(",", "|", $media_type);
  254. $this->assign('media_type', $media_type);
  255. return $this->fetch();
  256. }
  257. /**
  258. * 编辑
  259. */
  260. public function edit()
  261. {
  262. if (IS_POST) {
  263. $post = input('post.');
  264. if (!empty($post['id'])) {
  265. $post['id'] = intval($post['id']);
  266. if (array_key_exists($post['id'], $this->ad_position_system_id)) {
  267. $this->error("不可更改系统预定义位置", url('AdPosition/edit',array('id'=>$post['id'])));
  268. }
  269. /* 判断除自身外是否还有相同广告名称已存在 */
  270. $map = array(
  271. 'id' => array('NEQ', $post['id']),
  272. 'title' => trim($post['title']),
  273. 'lang' => $this->admin_lang,
  274. );
  275. if (Db::name('ad_position')->where($map)->count() > 0) $this->error('该广告名称已存在,请检查');
  276. /* END */
  277. /* 判断广告是否切换广告类型 */
  278. // $where = [
  279. // 'id' => $post['id'],
  280. // 'type' => $post['type'],
  281. // 'lang' => $this->admin_lang
  282. // ];
  283. // if (Db::name('ad_position')->where($where)->count() == 0) {
  284. // // 已切换广告类型,清除广告中的广告内容
  285. // $where = [
  286. // 'pid' => $post['id'],
  287. // 'lang' => $this->admin_lang
  288. // ];
  289. // Db::name('ad')->where($where)->delete();
  290. // }
  291. /* END */
  292. /* 修改广告主体信息 */
  293. $data = array(
  294. 'id' => $post['id'],
  295. 'title' => trim($post['title']),
  296. 'type' => $post['type'],
  297. 'intro' => $post['intro'],
  298. 'update_time' => getTime(),
  299. );
  300. $resultID = Db::name('ad_position')->update($data);
  301. /* END */
  302. }
  303. if (!empty($resultID)) {
  304. $ad_db = Db::name('ad');
  305. if (1 == $post['type'] && !empty($post['img_litpic'])) { // 图片类型
  306. // 读取组合广告位的图片及信息
  307. $i = 1;
  308. foreach ($post['img_litpic'] as $key => $value) {
  309. if (!empty($value)) {
  310. // 去掉http:
  311. $value = str_replace("http:", "", $value);
  312. // 去掉https:
  313. $value = str_replace("https:", "", $value);
  314. // 是否新窗口打开
  315. $target = !empty($post['img_target'][$key]) ? 1 : 0;
  316. // 广告位ID,为空则表示添加
  317. $ad_id = $post['img_id'][$key];
  318. if (!empty($ad_id)) {
  319. // 查询更新条件
  320. $where = [
  321. 'id' => $ad_id,
  322. 'lang' => $this->admin_lang,
  323. ];
  324. if ($ad_db->where($where)->count() > 0) {
  325. // 主要参数
  326. $AdData['litpic'] = $value;
  327. $AdData['title'] = $post['img_title'][$key];
  328. $AdData['links'] = $post['img_links'][$key];
  329. $AdData['intro'] = $post['img_intro'][$key];
  330. $AdData['target'] = $target;
  331. // 其他参数
  332. $AdData['sort_order'] = $i++;
  333. $AdData['update_time'] = getTime();
  334. // 更新,不需要同步多语言
  335. $ad_db->where($where)->update($AdData);
  336. } else {
  337. // 主要参数
  338. $AdData['litpic'] = $value;
  339. $AdData['pid'] = $post['id'];
  340. $AdData['title'] = $post['img_title'][$key];
  341. $AdData['links'] = $post['img_links'][$key];
  342. $AdData['intro'] = $post['img_intro'][$key];
  343. $AdData['target'] = $target;
  344. // 其他参数
  345. $AdData['media_type'] = 1;
  346. $AdData['admin_id'] = session('admin_id');
  347. $AdData['lang'] = $this->admin_lang;
  348. $AdData['sort_order'] = $i++;
  349. $AdData['add_time'] = getTime();
  350. $AdData['update_time'] = getTime();
  351. $ad_id = $ad_db->add($AdData);
  352. // 同步多语言
  353. $this->syn_add_ad_language_attribute($ad_id);
  354. }
  355. } else {
  356. // 主要参数
  357. $AdData['litpic'] = $value;
  358. $AdData['pid'] = $post['id'];
  359. $AdData['title'] = $post['img_title'][$key];
  360. $AdData['links'] = $post['img_links'][$key];
  361. $AdData['intro'] = $post['img_intro'][$key];
  362. $AdData['target'] = $target;
  363. // 其他参数
  364. $AdData['media_type'] = 1;
  365. $AdData['admin_id'] = session('admin_id');
  366. $AdData['lang'] = $this->admin_lang;
  367. $AdData['sort_order'] = $i++;
  368. $AdData['add_time'] = getTime();
  369. $AdData['update_time'] = getTime();
  370. $ad_id = $ad_db->add($AdData);
  371. // 同步多语言
  372. $this->syn_add_ad_language_attribute($ad_id);
  373. }
  374. }
  375. }
  376. } else if (2 == $post['type'] && !empty($post['video_litpic'])) { // 媒体类型
  377. // 去掉http:
  378. $video_litpic = str_replace("http:", "", $post['video_litpic']);
  379. // 去掉https:
  380. $video_litpic = str_replace("https:", "", $post['video_litpic']);
  381. if (!empty($post['video_id'])) {
  382. // 更新广告内容
  383. $AdData['litpic'] = $video_litpic;
  384. $AdData['title'] = trim($post['title']);
  385. $AdData['media_type'] = 2;
  386. $AdData['update_time'] = getTime();
  387. $ad_db->where('id', $post['video_id'])->update($AdData);
  388. } else {
  389. // 新增广告内容
  390. $AdData['litpic'] = $video_litpic;
  391. $AdData['pid'] = $post['id'];
  392. $AdData['title'] = trim($post['title']);
  393. $AdData['links'] = '';
  394. $AdData['intro'] = '';
  395. $AdData['target'] = 0;
  396. $AdData['media_type'] = 2;
  397. $AdData['admin_id'] = session('admin_id');
  398. $AdData['lang'] = $this->admin_lang;
  399. $AdData['sort_order'] = 1;
  400. $AdData['add_time'] = getTime();
  401. $AdData['update_time'] = getTime();
  402. $ad_id = $ad_db->add($AdData);
  403. // 同步多语言
  404. $this->syn_add_ad_language_attribute($ad_id);
  405. }
  406. } else if (3 == $post['type'] && !empty($post['html_intro'])) { // HTML代码
  407. if (!empty($post['html_id'])) {
  408. // 更新广告内容
  409. $AdData['title'] = trim($post['title']);
  410. $AdData['intro'] = $post['html_intro'];
  411. $AdData['media_type'] = 3;
  412. $AdData['update_time'] = getTime();
  413. $ad_db->where('id', $post['html_id'])->update($AdData);
  414. } else {
  415. // 新增广告内容
  416. $AdData['litpic'] = '';
  417. $AdData['pid'] = $post['id'];
  418. $AdData['title'] = trim($post['title']);
  419. $AdData['intro'] = $post['html_intro'];
  420. $AdData['links'] = '';
  421. $AdData['target'] = 0;
  422. $AdData['media_type'] = 3;
  423. $AdData['admin_id'] = session('admin_id');
  424. $AdData['lang'] = $this->admin_lang;
  425. $AdData['sort_order'] = 1;
  426. $AdData['add_time'] = getTime();
  427. $AdData['update_time'] = getTime();
  428. $ad_id = $ad_db->add($AdData);
  429. // 同步多语言
  430. $this->syn_add_ad_language_attribute($ad_id);
  431. }
  432. }
  433. Cache::clear('ad');
  434. adminLog('编辑广告:'.$post['title']);
  435. $this->success("操作成功", url('AdPosition/index'));
  436. } else {
  437. $this->error("操作失败");
  438. }
  439. }
  440. $assign_data = array();
  441. $id = input('id/d');
  442. $field = Db::name('ad_position')->field('a.*')->alias('a')->where(array('a.id'=>$id))->find();
  443. if (empty($field)) $this->error('广告不存在,请联系管理员!');
  444. switch ($field['type']) {
  445. case '1':
  446. $field['type_name'] = '图片';
  447. break;
  448. case '2':
  449. $field['type_name'] = '多媒体';
  450. break;
  451. case '3':
  452. $field['type_name'] = 'HTML代码';
  453. break;
  454. }
  455. $assign_data['field'] = $field;
  456. // 广告
  457. $ad_data = Db::name('ad')->where(array('pid'=>$field['id']))->order('sort_order asc')->select();
  458. foreach ($ad_data as $key => $val) {
  459. if (1 == $val['media_type']) {
  460. $ad_data[$key]['litpic'] = get_default_pic($val['litpic']); // 支持子目录
  461. }
  462. }
  463. $assign_data['ad_data'] = $ad_data;
  464. // 上传通道
  465. $WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select();
  466. $WeappOpen = [];
  467. foreach ($WeappConfig as $value) {
  468. if ('Qiniuyun' == $value['code']) {
  469. $WeappOpen['qny_open'] = $value['status'];
  470. } else if ('AliyunOss' == $value['code']) {
  471. $WeappOpen['oss_open'] = $value['status'];
  472. } else if ('Cos' == $value['code']) {
  473. $WeappOpen['cos_open'] = $value['status'];
  474. }
  475. }
  476. $this->assign('WeappOpen', $WeappOpen);
  477. // 系统最大上传视频的大小
  478. $file_size = tpCache('global.file_size');
  479. $postsize = @ini_get('file_uploads') ? ini_get('post_max_size') : -1;
  480. $fileupload = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : -1;
  481. $min_size = strval($file_size) < strval($postsize) ? $file_size : $postsize;
  482. $min_size = strval($min_size) < strval($fileupload) ? $min_size : $fileupload;
  483. $upload_max_filesize = intval($min_size) * 1024 * 1024;
  484. $assign_data['upload_max_filesize'] = $upload_max_filesize;
  485. // 视频类型
  486. $media_type = tpCache('global.media_type');
  487. $media_type = !empty($media_type) ? $media_type : config('global.media_ext');
  488. $media_type = str_replace(",", "|", $media_type);
  489. $assign_data['media_type'] = $media_type;
  490. $this->assign($assign_data);
  491. return $this->fetch();
  492. }
  493. /**
  494. * 删除广告图片
  495. */
  496. public function del_imgupload()
  497. {
  498. if (is_language() && empty($this->globalConfig['language_split'])) {
  499. $this->language_access(); // 多语言功能操作权限
  500. }
  501. $id_arr = input('del_id/a');
  502. $id_arr = eyIntval($id_arr);
  503. if(IS_POST && !empty($id_arr)){
  504. /*多语言*/
  505. $attr_name_arr = [];
  506. if (empty($this->globalConfig['language_split'])) {
  507. foreach ($id_arr as $key => $val) {
  508. $attr_name_arr[] = 'ad'.$val;
  509. }
  510. if (is_language()) {
  511. $new_id_arr = Db::name('language_attr')->where([
  512. 'attr_name' => ['IN', $attr_name_arr],
  513. 'attr_group' => 'ad',
  514. ])->column('attr_value');
  515. !empty($new_id_arr) && $id_arr = $new_id_arr;
  516. }
  517. } else {
  518. if (get_admin_lang() == get_main_lang()) {
  519. foreach ($id_arr as $key => $val) {
  520. $attr_name_arr[] = 'ad'.$val;
  521. }
  522. }
  523. }
  524. /*--end*/
  525. $r = Db::name('ad')->where([
  526. 'id' => ['IN', $id_arr],
  527. ])
  528. ->delete();
  529. if ($r !== false) {
  530. /*多语言*/
  531. if (!empty($attr_name_arr)) {
  532. Db::name('language_attr')->where([
  533. 'attr_name' => ['IN', $attr_name_arr],
  534. 'attr_group' => 'ad',
  535. ])->delete();
  536. Db::name('language_attribute')->where([
  537. 'attr_name' => ['IN', $attr_name_arr],
  538. 'attr_group' => 'ad',
  539. ])->delete();
  540. }
  541. /*--end*/
  542. Cache::clear('ad');
  543. adminLog('删除广告-id:'.implode(',', $id_arr));
  544. }
  545. }
  546. }
  547. /**
  548. * 删除
  549. */
  550. public function del()
  551. {
  552. if (is_language() && empty($this->globalConfig['language_split'])) {
  553. $this->language_access(); // 多语言功能操作权限
  554. }
  555. $id_arr = input('del_id/a');
  556. $id_arr = eyIntval($id_arr);
  557. if(IS_POST && !empty($id_arr)){
  558. foreach ($id_arr as $key => $val) {
  559. if(array_key_exists($val, $this->ad_position_system_id)){
  560. $this->error('系统预定义,不能删除');
  561. }
  562. }
  563. /*多语言*/
  564. $attr_name_arr = [];
  565. foreach ($id_arr as $key => $val) {
  566. $attr_name_arr[] = 'adp'.$val;
  567. }
  568. if (is_language() && empty($this->globalConfig['language_split'])) {
  569. $new_id_arr = Db::name('language_attr')->where([
  570. 'attr_name' => ['IN', $attr_name_arr],
  571. 'attr_group' => 'ad_position',
  572. ])->column('attr_value');
  573. !empty($new_id_arr) && $id_arr = $new_id_arr;
  574. }
  575. /*--end*/
  576. $r = Db::name('ad_position')->where('id','IN',$id_arr)->delete();
  577. if ($r !== false) {
  578. /*多语言*/
  579. if (!empty($attr_name_arr)) {
  580. if (get_admin_lang() == get_main_lang()) {
  581. Db::name('language_attribute')->where([
  582. 'attr_name' => ['IN', $attr_name_arr],
  583. 'attr_group' => 'ad_position',
  584. ])->delete();
  585. }
  586. if (empty($this->globalConfig['language_split'])) {
  587. Db::name('language_attr')->where([
  588. 'attr_name' => ['IN', $attr_name_arr],
  589. 'attr_group' => 'ad_position',
  590. ])->delete();
  591. } else {
  592. Db::name('language_attr')->where([
  593. 'attr_value' => ['IN', $id_arr],
  594. 'attr_group' => 'ad_position',
  595. ])->delete();
  596. }
  597. }
  598. /*--end*/
  599. $ad_ids = Db::name('ad')->where(['pid'=>['IN', $id_arr]])->column('id');
  600. $attr_name_arr = [];
  601. foreach ($ad_ids as $key => $val) {
  602. $attr_name_arr[] = "ad{$val}";
  603. }
  604. $r1 = Db::name('ad')->where('pid','IN',$id_arr)->delete();
  605. if ($r1 !== false) {
  606. /*多语言*/
  607. if (!empty($attr_name_arr)) {
  608. if (get_admin_lang() == get_main_lang()) {
  609. Db::name('language_attribute')->where([
  610. 'attr_name' => ['IN', $attr_name_arr],
  611. 'attr_group' => 'ad',
  612. ])->delete();
  613. }
  614. if (empty($this->globalConfig['language_split'])) {
  615. Db::name('language_attr')->where([
  616. 'attr_name' => ['IN', $attr_name_arr],
  617. 'attr_group' => 'ad',
  618. ])->delete();
  619. } else {
  620. Db::name('language_attr')->where([
  621. 'attr_value' => ['IN', $ad_ids],
  622. 'attr_group' => 'ad',
  623. ])->delete();
  624. }
  625. }
  626. /*--end*/
  627. }
  628. Cache::clear('ad');
  629. adminLog('删除广告-id:'.implode(',', $id_arr));
  630. $this->success('删除成功');
  631. } else {
  632. $this->error('删除失败');
  633. }
  634. }else{
  635. $this->error('参数有误');
  636. }
  637. }
  638. /**
  639. * 打开预览视频
  640. */
  641. public function open_preview_video()
  642. {
  643. $post = input('post.');
  644. $video_litpic = $post['video_litpic'];
  645. if (!is_http_url($video_litpic)) {
  646. $video_litpic = request()->domain() . handle_subdir_pic($video_litpic, 'media');
  647. }
  648. $this->success('执行成功', $video_litpic);
  649. }
  650. /**
  651. * 检测广告名称是否存在重复
  652. */
  653. public function detection_title_repeat()
  654. {
  655. if (IS_AJAX_POST) {
  656. $post = input('post.');
  657. $where = [
  658. 'id' => ['NEQ', $post['id']],
  659. 'title' => trim($post['title']),
  660. 'lang' => $this->admin_lang,
  661. ];
  662. $count = Db::name('ad_position')->where($where)->count();
  663. if (empty($count)) {
  664. $this->success('检测通过');
  665. } else {
  666. $this->error('该广告名称已存在,请检查');
  667. }
  668. }
  669. }
  670. /**
  671. * 同步新增广告位置ID到多语言的模板变量里
  672. */
  673. private function syn_add_language_attribute($adp_id)
  674. {
  675. /*单语言情况下不执行多语言代码*/
  676. if (!is_language() || tpCache('language.language_split')) {
  677. return true;
  678. }
  679. /*--end*/
  680. $attr_group = 'ad_position';
  681. $admin_lang = $this->admin_lang;
  682. $main_lang = $this->main_lang;
  683. $languageRow = Db::name('language')->field('mark')->order('id asc')->select();
  684. if (!empty($languageRow) && $admin_lang == $main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
  685. $ad_position_db = Db::name('ad_position');
  686. $result = $ad_position_db->find($adp_id);
  687. $attr_name = 'adp'.$adp_id;
  688. $r = Db::name('language_attribute')->save([
  689. 'attr_title' => $result['title'],
  690. 'attr_name' => $attr_name,
  691. 'attr_group' => $attr_group,
  692. 'add_time' => getTime(),
  693. 'update_time' => getTime(),
  694. ]);
  695. if (false !== $r) {
  696. $data = [];
  697. foreach ($languageRow as $key => $val) {
  698. /*同步新广告位置到其他语言广告位置列表*/
  699. if ($val['mark'] != $admin_lang) {
  700. $addsaveData = $result;
  701. $addsaveData['lang'] = $val['mark'];
  702. $addsaveData['title'] = $val['mark'].$addsaveData['title'];
  703. unset($addsaveData['id']);
  704. $adp_id = $ad_position_db->insertGetId($addsaveData);
  705. }
  706. /*--end*/
  707. /*所有语言绑定在主语言的ID容器里*/
  708. $data[] = [
  709. 'attr_name' => $attr_name,
  710. 'attr_value' => $adp_id,
  711. 'lang' => $val['mark'],
  712. 'attr_group' => $attr_group,
  713. 'add_time' => getTime(),
  714. 'update_time' => getTime(),
  715. ];
  716. /*--end*/
  717. }
  718. if (!empty($data)) {
  719. model('LanguageAttr')->saveAll($data);
  720. }
  721. }
  722. }
  723. }
  724. /**
  725. * 同步新增广告ID到多语言的模板变量里
  726. */
  727. private function syn_add_ad_language_attribute($ad_id)
  728. {
  729. /*单语言情况下不执行多语言代码*/
  730. if (!is_language() || tpCache('language.language_split')) {
  731. return true;
  732. }
  733. /*--end*/
  734. $attr_group = 'ad';
  735. $admin_lang = $this->admin_lang;
  736. $main_lang = get_main_lang();
  737. $languageRow = Db::name('language')->field('mark')->order('id asc')->select();
  738. if (!empty($languageRow) && $admin_lang == $main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
  739. $ad_db = Db::name('ad');
  740. $result = $ad_db->find($ad_id);
  741. $attr_name = 'ad'.$ad_id;
  742. $r = Db::name('language_attribute')->save([
  743. 'attr_title' => $result['title'],
  744. 'attr_name' => $attr_name,
  745. 'attr_group' => $attr_group,
  746. 'add_time' => getTime(),
  747. 'update_time' => getTime(),
  748. ]);
  749. if (false !== $r) {
  750. $data = [];
  751. foreach ($languageRow as $key => $val) {
  752. /*同步新广告到其他语言广告列表*/
  753. if ($val['mark'] != $admin_lang) {
  754. $addsaveData = $result;
  755. $addsaveData['lang'] = $val['mark'];
  756. $newPid = Db::name('language_attr')->where([
  757. 'attr_name' => 'adp'.$result['pid'],
  758. 'attr_group' => 'ad_position',
  759. 'lang' => $val['mark'],
  760. ])->getField('attr_value');
  761. $addsaveData['pid'] = $newPid;
  762. $addsaveData['title'] = $val['mark'].$addsaveData['title'];
  763. unset($addsaveData['id']);
  764. $ad_id = $ad_db->insertGetId($addsaveData);
  765. }
  766. /*--end*/
  767. /*所有语言绑定在主语言的ID容器里*/
  768. $data[] = [
  769. 'attr_name' => $attr_name,
  770. 'attr_value' => $ad_id,
  771. 'lang' => $val['mark'],
  772. 'attr_group' => $attr_group,
  773. 'add_time' => getTime(),
  774. 'update_time' => getTime(),
  775. ];
  776. /*--end*/
  777. }
  778. if (!empty($data)) {
  779. model('LanguageAttr')->saveAll($data);
  780. }
  781. }
  782. }
  783. }
  784. }