Links.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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\Cache;
  16. class Links extends Base
  17. {
  18. public function index()
  19. {
  20. $list = array();
  21. $keywords = input('keywords/s');
  22. $condition = array();
  23. if (!empty($keywords)) {
  24. $condition['title'] = array('LIKE', "%{$keywords}%");
  25. }
  26. // 多语言
  27. $condition['lang'] = array('eq', $this->admin_lang);
  28. $linksM = M('links');
  29. $count = $linksM->where($condition)->count('id');// 查询满足要求的总记录数
  30. $Page = $pager = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  31. $list = $linksM->where($condition)->order('sort_order asc, id asc')->limit($Page->firstRow.','.$Page->listRows)->select();
  32. $show = $Page->show();// 分页显示输出
  33. $this->assign('page',$show);// 赋值分页输出
  34. $this->assign('list',$list);// 赋值数据集
  35. $this->assign('pager',$pager);// 赋值分页对象
  36. return $this->fetch();
  37. }
  38. /**
  39. * 添加友情链接
  40. */
  41. public function add()
  42. {
  43. if (IS_POST) {
  44. $post = input('post.');
  45. // 处理LOGO
  46. $is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
  47. $logo = '';
  48. if ($is_remote == 1) {
  49. $logo = $post['logo_remote'];
  50. } else {
  51. $logo = $post['logo_local'];
  52. }
  53. $post['logo'] = $logo;
  54. // --存储数据
  55. $nowData = array(
  56. 'typeid' => empty($post['typeid']) ? 1 : $post['typeid'],
  57. 'url' => trim($post['url']),
  58. 'lang' => $this->admin_lang,
  59. 'sort_order' => 100,
  60. 'add_time' => getTime(),
  61. 'update_time' => getTime(),
  62. );
  63. $data = array_merge($post, $nowData);
  64. $insertId = M('links')->insertGetId($data);
  65. if (false !== $insertId) {
  66. Cache::clear('links');
  67. adminLog('新增友情链接:'.$post['title']);
  68. $this->success("操作成功!", url('Links/index'));
  69. }else{
  70. $this->error("操作失败!", url('Links/index'));
  71. }
  72. exit;
  73. }
  74. return $this->fetch();
  75. }
  76. /**
  77. * 编辑友情链接
  78. */
  79. public function edit()
  80. {
  81. if (IS_POST) {
  82. $post = input('post.');
  83. $r = false;
  84. if(!empty($post['id'])){
  85. // 处理LOGO
  86. $is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
  87. $logo = '';
  88. if ($is_remote == 1) {
  89. $logo = $post['logo_remote'];
  90. } else {
  91. $logo = $post['logo_local'];
  92. }
  93. $post['logo'] = $logo;
  94. // --存储数据
  95. $nowData = array(
  96. 'typeid' => empty($post['typeid']) ? 1 : $post['typeid'],
  97. 'url' => trim($post['url']),
  98. 'update_time' => getTime(),
  99. );
  100. $data = array_merge($post, $nowData);
  101. $r = M('links')->where([
  102. 'id' => $post['id'],
  103. 'lang' => $this->admin_lang,
  104. ])
  105. ->cache(true, null, "links")
  106. ->update($data);
  107. }
  108. if (false !== $r) {
  109. adminLog('编辑友情链接:'.$post['title']);
  110. $this->success("操作成功!",url('Links/index'));
  111. }else{
  112. $this->error("操作失败!",url('Links/index'));
  113. }
  114. exit;
  115. }
  116. $id = input('id/d');
  117. $info = M('links')->where([
  118. 'id' => $id,
  119. 'lang' => $this->admin_lang,
  120. ])->find();
  121. if (empty($info)) {
  122. $this->error('数据不存在,请联系管理员!');
  123. exit;
  124. }
  125. if (is_http_url($info['logo'])) {
  126. $info['is_remote'] = 1;
  127. $info['logo_remote'] = handle_subdir_pic($info['logo']);
  128. } else {
  129. $info['is_remote'] = 0;
  130. $info['logo_local'] = handle_subdir_pic($info['logo']);
  131. }
  132. $this->assign('info',$info);
  133. return $this->fetch();
  134. }
  135. /**
  136. * 删除友情链接
  137. */
  138. public function del()
  139. {
  140. if (IS_POST) {
  141. $id_arr = input('del_id/a');
  142. $id_arr = eyIntval($id_arr);
  143. if(!empty($id_arr)){
  144. $result = M('links')->field('title')
  145. ->where([
  146. 'id' => ['IN', $id_arr],
  147. 'lang' => $this->admin_lang,
  148. ])->select();
  149. $title_list = get_arr_column($result, 'title');
  150. $r = M('links')->where([
  151. 'id' => ['IN', $id_arr],
  152. 'lang' => $this->admin_lang,
  153. ])
  154. ->cache(true, null, "links")
  155. ->delete();
  156. if($r){
  157. adminLog('删除友情链接:'.implode(',', $title_list));
  158. $this->success('删除成功');
  159. }else{
  160. $this->error('删除失败');
  161. }
  162. } else {
  163. $this->error('参数有误');
  164. }
  165. }
  166. $this->error('非法访问');
  167. }
  168. }