Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Other.php 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. class Other extends Base
  17. {
  18. /*
  19. * 初始化操作
  20. */
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. // 判断是否有广告位置
  25. if (strtolower(ACTION_NAME) != 'index') {
  26. $count = Db::name('ad_position')->count('id');
  27. if (empty($count)) {
  28. $this->success('缺少广告位置,正在前往中……', url('AdPosition/add'), '', 3);
  29. exit;
  30. }
  31. }
  32. }
  33. public function index()
  34. {
  35. $list = array();
  36. $get = input('get.');
  37. $pid = input('param.pid/d', 0);
  38. $keywords = input('keywords/s');
  39. $condition = array();
  40. // 应用搜索条件
  41. foreach (['keywords', 'pid'] as $key) {
  42. if (isset($get[$key]) && $get[$key] !== '') {
  43. if ($key == 'keywords') {
  44. $condition['a.title'] = array('LIKE', "%{$get[$key]}%");
  45. } else {
  46. $tmp_key = 'a.'.$key;
  47. $condition[$tmp_key] = array('eq', $get[$key]);
  48. }
  49. }
  50. }
  51. // 多语言
  52. $condition['a.lang'] = array('eq', $this->admin_lang);
  53. $adM = Db::name('ad');
  54. $count = $adM->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  55. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  56. $list = $adM->alias('a')->where($condition)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
  57. /*支持子目录*/
  58. foreach ($list as $key => $val) {
  59. $val['litpic'] = handle_subdir_pic($val['litpic']);
  60. $list[$key] = $val;
  61. }
  62. /*--end*/
  63. $show = $Page->show();// 分页显示输出
  64. $this->assign('page',$show);// 赋值分页输出
  65. $this->assign('list',$list);// 赋值数据集
  66. $this->assign('pager',$Page);// 赋值分页对象
  67. $ad_position = model('AdPosition')->getAll('*','id');
  68. $this->assign('ad_position',$ad_position);
  69. $this->assign('pid',$pid);// 赋值分页对象
  70. return $this->fetch();
  71. }
  72. /**
  73. * 新增
  74. */
  75. public function add()
  76. {
  77. $this->language_access(); // 多语言功能操作权限
  78. if (IS_POST) {
  79. $post = input('post.');
  80. $is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
  81. $litpic = '';
  82. if ($is_remote == 1) {
  83. $litpic = $post['litpic_remote'];
  84. } else {
  85. $litpic = $post['litpic_local'];
  86. }
  87. $newData = array(
  88. 'litpic' => $litpic,
  89. 'admin_id' => session('admin_id'),
  90. 'lang' => $this->admin_lang,
  91. 'sort_order' => 100,
  92. 'add_time' => getTime(),
  93. 'update_time' => getTime(),
  94. );
  95. $data = array_merge($post, $newData);
  96. $insertId = Db::name('ad')->insertGetId($data);
  97. if ($insertId) {
  98. /*同步广告位置ID到多语言的模板变量里*/
  99. $this->syn_add_language_attribute($insertId);
  100. /*--end*/
  101. \think\Cache::clear('ad');
  102. adminLog('新增广告:'.$post['title']);
  103. $this->success("操作成功", url('Other/index'));
  104. } else {
  105. $this->error("操作失败");
  106. }
  107. exit;
  108. }
  109. $pid = input('param.pid/d', 0);
  110. $this->assign('pid', $pid);
  111. $ad_position = model('AdPosition')->getAll('*', 'id');
  112. $this->assign('ad_position', $ad_position);
  113. $ad_media_type = config('global.ad_media_type');
  114. $this->assign('ad_media_type', $ad_media_type);
  115. return $this->fetch();
  116. }
  117. /**
  118. * 编辑
  119. */
  120. public function edit()
  121. {
  122. if (IS_POST) {
  123. $post = input('post.');
  124. if(!empty($post['id'])){
  125. $post['id'] = intval($post['id']);
  126. $is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
  127. $litpic = '';
  128. if ($is_remote == 1) {
  129. $litpic = $post['litpic_remote'];
  130. } else {
  131. $litpic = $post['litpic_local'];
  132. }
  133. $newData = array(
  134. 'litpic' => $litpic,
  135. 'update_time' => getTime(),
  136. );
  137. $data = array_merge($post, $newData);
  138. $r = Db::name('ad')->where([
  139. 'id' => $post['id'],
  140. ])
  141. ->cache(true,null,'ad')
  142. ->update($data);
  143. }
  144. if ($r) {
  145. adminLog('编辑广告');
  146. $this->success("操作成功", url('Other/index'));
  147. } else {
  148. $this->error("操作失败");
  149. }
  150. }
  151. $assign_data = array();
  152. $id = input('id/d');
  153. $field = Db::name('ad')->where([
  154. 'id' => $id,
  155. ])->find();
  156. if (empty($field)) {
  157. $this->error('广告不存在,请联系管理员!');
  158. exit;
  159. }
  160. if (is_http_url($field['litpic'])) {
  161. $field['is_remote'] = 1;
  162. $field['litpic_remote'] = handle_subdir_pic($field['litpic']);
  163. } else {
  164. $field['is_remote'] = 0;
  165. $field['litpic_local'] = handle_subdir_pic($field['litpic']);
  166. }
  167. /*支持子目录*/
  168. $field['intro'] = handle_subdir_pic($field['intro'], 'html');
  169. /*--end*/
  170. $assign_data['field'] = $field;
  171. $assign_data['ad_position'] = model('AdPosition')->getAll('*', 'id');
  172. $assign_data['ad_media_type'] = config('global.ad_media_type');
  173. $this->assign($assign_data);
  174. return $this->fetch();
  175. }
  176. /**
  177. * 删除
  178. */
  179. public function del()
  180. {
  181. $this->language_access(); // 多语言功能操作权限
  182. $id_arr = input('del_id/a');
  183. $id_arr = eyIntval($id_arr);
  184. if(!empty($id_arr)){
  185. /*多语言*/
  186. $attr_name_arr = [];
  187. foreach ($id_arr as $key => $val) {
  188. $attr_name_arr[] = 'ad'.$val;
  189. }
  190. if (is_language()) {
  191. $new_id_arr = Db::name('language_attr')->where([
  192. 'attr_name' => ['IN', $attr_name_arr],
  193. 'attr_group' => 'ad',
  194. ])->column('attr_value');
  195. !empty($new_id_arr) && $id_arr = $new_id_arr;
  196. }
  197. /*--end*/
  198. $r = Db::name('ad')->where([
  199. 'id' => ['IN', $id_arr],
  200. ])
  201. ->cache(true,null,'ad')
  202. ->delete();
  203. if ($r) {
  204. /*多语言*/
  205. if (!empty($attr_name_arr)) {
  206. Db::name('language_attr')->where([
  207. 'attr_name' => ['IN', $attr_name_arr],
  208. 'attr_group' => 'ad',
  209. ])->delete();
  210. Db::name('language_attribute')->where([
  211. 'attr_name' => ['IN', $attr_name_arr],
  212. 'attr_group' => 'ad',
  213. ])->delete();
  214. }
  215. /*--end*/
  216. adminLog('删除广告-id:'.implode(',', $id_arr));
  217. $this->success('删除成功');
  218. } else {
  219. $this->error('删除失败');
  220. }
  221. }else{
  222. $this->error('参数有误');
  223. }
  224. }
  225. /**
  226. * ui美化新增
  227. */
  228. public function ui_add()
  229. {
  230. $this->language_access(); // 多语言功能操作权限
  231. if (IS_POST) {
  232. $post = input('post.');
  233. $is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
  234. $litpic = '';
  235. if ($is_remote == 1) {
  236. $litpic = $post['litpic_remote'];
  237. } else {
  238. $litpic = $post['litpic_local'];
  239. }
  240. $newData = array(
  241. 'media_type' => 1,
  242. 'litpic' => $litpic,
  243. 'lang' => get_current_lang(),
  244. 'add_time' => getTime(),
  245. 'update_time' => getTime(),
  246. );
  247. $data = array_merge($post, $newData);
  248. $insertId = Db::name('ad')->insertGetId($data);
  249. if ($insertId) {
  250. /*同步广告位置ID到多语言的模板变量里*/
  251. $this->syn_add_language_attribute($insertId);
  252. /*--end*/
  253. \think\Cache::clear('ad');
  254. adminLog('新增广告:'.$post['title']);
  255. $this->success('操作成功');
  256. } else {
  257. $this->error('操作失败');
  258. }
  259. }
  260. $edit_id = input('param.edit_id/d', 0);
  261. $pid = input('param.pid/d', 0);
  262. /*多语言*/
  263. $new_pid = model('LanguageAttr')->getBindValue($pid, 'ad_position');
  264. !empty($new_pid) && $pid = $new_pid;
  265. /*--end*/
  266. $assign_data = array();
  267. $assign_data['ad_position'] = model('AdPosition')->getInfo($pid);
  268. $assign_data['edit_id'] = $edit_id;
  269. $this->assign($assign_data);
  270. return $this->fetch();
  271. }
  272. /**
  273. * ui美化编辑
  274. */
  275. public function ui_edit()
  276. {
  277. if (IS_POST) {
  278. $post = input('post.');
  279. if(!empty($post['id'])){
  280. $post['id'] = intval($post['id']);
  281. $is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
  282. $litpic = '';
  283. if ($is_remote == 1) {
  284. $litpic = $post['litpic_remote'];
  285. } else {
  286. $litpic = $post['litpic_local'];
  287. }
  288. $newData = array(
  289. 'litpic' => $litpic,
  290. 'update_time' => getTime(),
  291. );
  292. $data = array_merge($post, $newData);
  293. $r = Db::name('ad')->where([
  294. 'id' => $post['id'],
  295. ])
  296. ->cache(true,null,'ad')
  297. ->update($data);
  298. if ($r) {
  299. adminLog('编辑广告:'.$post['title']);
  300. $this->success('操作成功');
  301. }
  302. }
  303. $this->error('操作失败');
  304. }
  305. $assign_data = array();
  306. $id = input('id/d');
  307. $field = Db::name('ad')->where([
  308. 'id' => $id,
  309. ])->find();
  310. if (empty($field)) {
  311. $this->error('广告不存在,请联系管理员!');
  312. exit;
  313. }
  314. if (is_http_url($field['litpic'])) {
  315. $field['is_remote'] = 1;
  316. $field['litpic_remote'] = $field['litpic'];
  317. } else {
  318. $field['is_remote'] = 0;
  319. $field['litpic_local'] = $field['litpic'];
  320. }
  321. $assign_data['field'] = $field;
  322. $assign_data['ad_position'] = model('AdPosition')->getInfo($field['pid']);
  323. $this->assign($assign_data);
  324. return $this->fetch();
  325. }
  326. /**
  327. * 删除
  328. */
  329. public function ui_del()
  330. {
  331. $this->language_access(); // 多语言功能操作权限
  332. $id_arr = input('del_id/a');
  333. $id_arr = eyIntval($id_arr);
  334. if(!empty($id_arr)){
  335. /*多语言*/
  336. $attr_name_arr = [];
  337. foreach ($id_arr as $key => $val) {
  338. $attr_name_arr[] = 'ad'.$val;
  339. }
  340. if (is_language()) {
  341. $new_id_arr = Db::name('language_attr')->where([
  342. 'attr_name' => ['IN', $attr_name_arr],
  343. 'attr_group' => 'ad',
  344. ])->column('attr_value');
  345. !empty($new_id_arr) && $id_arr = $new_id_arr;
  346. }
  347. /*--end*/
  348. $r = Db::name('ad')->where([
  349. 'id' => ['IN', $id_arr],
  350. ])
  351. ->cache(true,null,'ad')
  352. ->delete();
  353. if ($r) {
  354. /*多语言*/
  355. if (!empty($attr_name_arr)) {
  356. Db::name('language_attr')->where([
  357. 'attr_name' => ['IN', $attr_name_arr],
  358. 'attr_group' => 'ad',
  359. ])->delete();
  360. Db::name('language_attribute')->where([
  361. 'attr_name' => ['IN', $attr_name_arr],
  362. 'attr_group' => 'ad',
  363. ])->delete();
  364. }
  365. /*--end*/
  366. adminLog('删除广告-id:'.implode(',', $id_arr));
  367. $this->success('删除成功');
  368. } else {
  369. $this->error('删除失败');
  370. }
  371. }else{
  372. $this->error('参数有误');
  373. }
  374. }
  375. /**
  376. * 同步新增广告ID到多语言的模板变量里
  377. */
  378. private function syn_add_language_attribute($ad_id)
  379. {
  380. /*单语言情况下不执行多语言代码*/
  381. if (!is_language()) {
  382. return true;
  383. }
  384. /*--end*/
  385. $attr_group = 'ad';
  386. $admin_lang = $this->admin_lang;
  387. $main_lang = get_main_lang();
  388. $languageRow = Db::name('language')->field('mark')->order('id asc')->select();
  389. if (!empty($languageRow) && $admin_lang == $main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
  390. $ad_db = Db::name('ad');
  391. $result = $ad_db->find($ad_id);
  392. $attr_name = 'ad'.$ad_id;
  393. $r = Db::name('language_attribute')->save([
  394. 'attr_title' => $result['title'],
  395. 'attr_name' => $attr_name,
  396. 'attr_group' => $attr_group,
  397. 'add_time' => getTime(),
  398. 'update_time' => getTime(),
  399. ]);
  400. if (false !== $r) {
  401. $data = [];
  402. foreach ($languageRow as $key => $val) {
  403. /*同步新广告到其他语言广告列表*/
  404. if ($val['mark'] != $admin_lang) {
  405. $addsaveData = $result;
  406. $addsaveData['lang'] = $val['mark'];
  407. $newPid = Db::name('language_attr')->where([
  408. 'attr_name' => 'adp'.$result['pid'],
  409. 'attr_group' => 'ad_position',
  410. 'lang' => $val['mark'],
  411. ])->getField('attr_value');
  412. $addsaveData['pid'] = $newPid;
  413. unset($addsaveData['id']);
  414. $ad_id = $ad_db->insertGetId($addsaveData);
  415. }
  416. /*--end*/
  417. /*所有语言绑定在主语言的ID容器里*/
  418. $data[] = [
  419. 'attr_name' => $attr_name,
  420. 'attr_value' => $ad_id,
  421. 'lang' => $val['mark'],
  422. 'attr_group' => $attr_group,
  423. 'add_time' => getTime(),
  424. 'update_time' => getTime(),
  425. ];
  426. /*--end*/
  427. }
  428. if (!empty($data)) {
  429. model('LanguageAttr')->saveAll($data);
  430. }
  431. }
  432. }
  433. }
  434. }