123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <?php
- namespace app\admin\controller;
- use think\facade\View;
- use think\facade\Lang;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Link extends AdminControl
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/link.lang.php');
- }
- public function index()
- {
- $condition = array();
- $link_title = input('get.link_title');
- if ($link_title) {
- $condition[] = array('link_title', 'like', "%$link_title%");
- }
- $link_model = model('link');
- $link_list = $link_model->getLinkList($condition, 10);
- View::assign('link_list', $link_list);
- View::assign('show_page', $link_model->page_info->render());
- View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
- $this->setAdminCurItem('index');
- return View::fetch('');
- }
- /**
- * 新增友情链接
- * */
- public function add()
- {
- if (!(request()->isPost())) {
- $link = [
- 'link_id' => '',
- 'link_title' => '',
- 'link_pic' => '',
- 'link_url' => '',
- 'link_sort' => 255,
- ];
- View::assign('link', $link);
- return View::fetch('form');
- } else {
- //上传图片
- $link_pic = '';
- if ($_FILES['link_pic']['name'] != '') {
- $file_name = date('YmdHis') . rand(10000, 99999) . '.png';
- $res = ds_upload_pic(DIR_ADMIN . DIRECTORY_SEPARATOR . 'link', 'link_pic', $file_name);
- if ($res['code']) {
- $link_pic = $res['data']['file_name'];
- } else {
- $this->error($res['msg']);
- }
- }
- $data = array(
- 'link_title' => input('post.link_title'),
- 'link_pic' => $link_pic,
- 'link_url' => input('post.link_url'),
- 'link_sort' => input('post.link_sort'),
- );
- $link_validate = ds_validate('link');
- if (!$link_validate->scene('add')->check($data)) {
- $this->error($link_validate->getError());
- }
- $result = model('link')->addLink($data);
- if ($result) {
- dsLayerOpenSuccess(lang('ds_common_save_succ'), (string) url('Link/index'));
- } else {
- $this->error(lang('ds_common_save_fail'));
- }
- }
- }
- /**
- * 编辑友情链接
- * */
- public function edit()
- {
- $link_id = input('param.link_id');
- if (empty($link_id)) {
- $this->error(lang('param_error'));
- }
- $link = model('link')->getOneLink($link_id);
- if (!request()->isPost()) {
- View::assign('link', $link);
- return View::fetch('form');
- } else {
- $data = array(
- 'link_title' => input('post.link_title'),
- 'link_sort' => input('post.link_sort'),
- 'link_url' => input('post.link_url'),
- );
- //上传图片
- if ($_FILES['link_pic']['name'] != '') {
- $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . DIR_ADMIN . DIRECTORY_SEPARATOR . 'link';
- $file_name = date('YmdHis') . rand(10000, 99999) . '.png';
- $res = ds_upload_pic(DIR_ADMIN . DIRECTORY_SEPARATOR . 'link', 'link_pic', $file_name);
- if ($res['code']) {
- $file_name = $res['data']['file_name'];
- $data['link_pic'] = $file_name;
- //删除原有友情链接图片
- @unlink($upload_file . DIRECTORY_SEPARATOR . $link['link_pic']);
- } else {
- $this->error($res['msg']);
- }
- }
- $link_validate = ds_validate('link');
- if (!$link_validate->scene('edit')->check($data)) {
- $this->error($link_validate->getError());
- }
- $result = model('link')->editLink($data, $link_id);
- if ($result >= 0) {
- dsLayerOpenSuccess(lang('ds_common_save_succ'), (string) url('Link/index'));
- } else {
- $this->error(lang('ds_common_save_fail'));
- }
- }
- }
- public function drop()
- {
- $link_id = intval(input('param.link_id'));
- if (empty($link_id)) {
- $this->error(lang('param_error'));
- }
- $result = model('link')->delLink($link_id);
- if ($result) {
- ds_json_encode(10000, lang('ds_common_op_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_op_fail'));
- }
- }
- /**
- * ajax操作
- */
- public function ajax()
- {
- $result = -1;
- switch (input('get.branch')) {
- case 'link':
- $model_link = model('link');
- $link_id = intval(input('get.id'));
- $update_array = array();
- $update_array[input('get.column')] = trim(input('get.value'));
- $result = $model_link->editLink($update_array, $link_id);
- break;
- }
- if ($result >= 0) {
- echo 'true';
- }
- }
- /**
- * 获取卖家栏目列表,针对控制器下的栏目
- */
- protected function getAdminItemList()
- {
- $menu_array = array(
- array(
- 'name' => 'index',
- 'text' => lang('ds_manage'),
- 'url' => (string) url('Link/index')
- ),
- array(
- 'name' => 'add',
- 'text' => lang('ds_add'),
- 'url' => "javascript:dsLayerOpen('" . (string) url('Link/add') . "','" . lang('ds_add') . "')"
- )
- );
- return $menu_array;
- }
- }
|