Link.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Link extends AdminControl {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/link.lang.php');
  21. }
  22. public function index() {
  23. $condition = array();
  24. $link_title = input('get.link_title');
  25. if ($link_title) {
  26. $condition[] = array('link_title', 'like', "%$link_title%");
  27. }
  28. $link_model = model('link');
  29. $link_list = $link_model->getLinkList($condition, 10);
  30. View::assign('link_list', $link_list);
  31. View::assign('show_page', $link_model->page_info->render());
  32. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  33. $this->setAdminCurItem('index');
  34. return View::fetch('');
  35. }
  36. /**
  37. * 新增友情链接
  38. * */
  39. public function add() {
  40. if (!(request()->isPost())) {
  41. $link = [
  42. 'link_id' => '',
  43. 'link_title' => '',
  44. 'link_pic' => '',
  45. 'link_url' => '',
  46. 'link_sort' => 255,
  47. ];
  48. View::assign('link', $link);
  49. return View::fetch('form');
  50. } else {
  51. //上传图片
  52. $link_pic = '';
  53. if ($_FILES['link_pic']['name'] != '') {
  54. $file_name = date('YmdHis') . rand(10000, 99999).'.png';
  55. $res=ds_upload_pic(DIR_ADMIN . DIRECTORY_SEPARATOR . 'link','link_pic',$file_name);
  56. if($res['code']){
  57. $link_pic=$res['data']['file_name'];
  58. }else{
  59. $this->error($res['msg']);
  60. }
  61. }
  62. $data = array(
  63. 'link_title' => input('post.link_title'),
  64. 'link_pic' => $link_pic,
  65. 'link_url' => input('post.link_url'),
  66. 'link_sort' => input('post.link_sort'),
  67. );
  68. $link_validate = ds_validate('link');
  69. if (!$link_validate->scene('add')->check($data)) {
  70. $this->error($link_validate->getError());
  71. }
  72. $result = model('link')->addLink($data);
  73. if ($result) {
  74. dsLayerOpenSuccess(lang('ds_common_save_succ'), (string) url('Link/index'));
  75. } else {
  76. $this->error(lang('ds_common_save_fail'));
  77. }
  78. }
  79. }
  80. /**
  81. * 编辑友情链接
  82. * */
  83. public function edit() {
  84. $link_id = input('param.link_id');
  85. if (empty($link_id)) {
  86. $this->error(lang('param_error'));
  87. }
  88. $link = model('link')->getOneLink($link_id);
  89. if (!request()->isPost()) {
  90. View::assign('link', $link);
  91. return View::fetch('form');
  92. } else {
  93. $data = array(
  94. 'link_title' => input('post.link_title'),
  95. 'link_sort' => input('post.link_sort'),
  96. 'link_url' => input('post.link_url'),
  97. );
  98. //上传图片
  99. if ($_FILES['link_pic']['name'] != '') {
  100. $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . DIR_ADMIN . DIRECTORY_SEPARATOR . 'link';
  101. $file_name = date('YmdHis') . rand(10000, 99999).'.png';
  102. $res=ds_upload_pic(DIR_ADMIN . DIRECTORY_SEPARATOR . 'link','link_pic',$file_name);
  103. if($res['code']){
  104. $file_name=$res['data']['file_name'];
  105. $data['link_pic'] = $file_name;
  106. //删除原有友情链接图片
  107. @unlink($upload_file . DIRECTORY_SEPARATOR . $link['link_pic']);
  108. }else{
  109. $this->error($res['msg']);
  110. }
  111. }
  112. $link_validate = ds_validate('link');
  113. if (!$link_validate->scene('edit')->check($data)) {
  114. $this->error($link_validate->getError());
  115. }
  116. $result = model('link')->editLink($data, $link_id);
  117. if ($result >= 0) {
  118. dsLayerOpenSuccess(lang('ds_common_save_succ'), (string) url('Link/index'));
  119. } else {
  120. $this->error(lang('ds_common_save_fail'));
  121. }
  122. }
  123. }
  124. public function drop() {
  125. $link_id = intval(input('param.link_id'));
  126. if (empty($link_id)) {
  127. $this->error(lang('param_error'));
  128. }
  129. $result = model('link')->delLink($link_id);
  130. if ($result) {
  131. ds_json_encode(10000, lang('ds_common_op_succ'));
  132. } else {
  133. ds_json_encode(10001, lang('ds_common_op_fail'));
  134. }
  135. }
  136. /**
  137. * ajax操作
  138. */
  139. public function ajax() {
  140. $result = -1;
  141. switch (input('get.branch')) {
  142. case 'link':
  143. $model_link = model('link');
  144. $link_id = intval(input('get.id'));
  145. $update_array = array();
  146. $update_array[input('get.column')] = trim(input('get.value'));
  147. $result = $model_link->editLink($update_array, $link_id);
  148. break;
  149. }
  150. if ($result >= 0) {
  151. echo 'true';
  152. }
  153. }
  154. /**
  155. * 获取卖家栏目列表,针对控制器下的栏目
  156. */
  157. protected function getAdminItemList() {
  158. $menu_array = array(
  159. array(
  160. 'name' => 'index',
  161. 'text' => lang('ds_manage'),
  162. 'url' => (string) url('Link/index')
  163. ),
  164. array(
  165. 'name' => 'add',
  166. 'text' => lang('ds_add'),
  167. 'url' => "javascript:dsLayerOpen('" . (string) url('Link/add') . "','" . lang('ds_add') . "')"
  168. )
  169. );
  170. return $menu_array;
  171. }
  172. }