123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- namespace Admin\Controller;
- /**
- * 友情链接
- * @author Devil
- * @blog http://gong.gg/
- * @version 0.0.1
- * @datetime 2016-12-01T21:51:08+0800
- */
- class LinkController extends CommonController
- {
- /**
- * [_initialize 前置操作-继承公共前置方法]
- * @author Devil
- * @blog http://gong.gg/
- * @version 0.0.1
- * @datetime 2016-12-03T12:39:08+0800
- */
- public function _initialize()
- {
- // 调用父类前置方法
- parent::_initialize();
- // 登录校验
- $this->Is_Login();
- // 权限校验
- $this->Is_Power();
- }
- /**
- * [Index 列表]
- * @author Devil
- * @blog http://gong.gg/
- * @version 0.0.1
- * @datetime 2016-12-06T21:31:53+0800
- */
- public function Index()
- {
- // 获取导航列表
- $list = M('Link')->field(array('id', 'name', 'url', 'describe', 'sort', 'is_enable', 'is_new_window_open'))->order('sort')->select();
- $this->assign('list', $list);
- // 是否新窗口打开
- $this->assign('common_is_new_window_open_list', L('common_is_new_window_open_list'));
- // 是否启用
- $this->assign('common_is_enable_list', L('common_is_enable_list'));
- $this->display('Index');
- }
- /**
- * [Save 数据保存]
- * @author Devil
- * @blog http://gong.gg/
- * @version 0.0.1
- * @datetime 2017-02-05T20:12:30+0800
- */
- public function Save()
- {
- // 是否ajax请求
- if(!IS_AJAX)
- {
- $this->error(L('common_unauthorized_access'));
- }
- // id为空则表示是新增
- $m = D('Link');
- // 公共额外数据处理
- $m->sort = intval(I('sort'));
- $m->describe = I('describe');
- // 添加
- if(empty($_POST['id']))
- {
- if($m->create($_POST, 1))
- {
- // 额外数据处理
- $m->add_time = time();
- $m->name = I('name');
- $m->describe = I('describe');
-
- // 写入数据库
- if($m->add())
- {
- $this->ajaxReturn(L('common_operation_add_success'));
- } else {
- $this->ajaxReturn(L('common_operation_add_error'), -100);
- }
- }
- } else {
- // 编辑
- if($m->create($_POST, 2))
- {
- // 额外数据处理
- $m->name = I('name');
- $m->describe = I('describe');
- // 移除 id
- unset($m->id);
- // 更新数据库
- if($m->where(array('id'=>I('id')))->save())
- {
- $this->ajaxReturn(L('common_operation_edit_success'));
- } else {
- $this->ajaxReturn(L('common_operation_edit_error'), -100);
- }
- }
- }
- $this->ajaxReturn($m->getError(), -1);
- }
- /**
- * [Delete 删除]
- * @author Devil
- * @blog http://gong.gg/
- * @version 0.0.1
- * @datetime 2016-12-09T21:13:47+0800
- */
- public function Delete()
- {
- if(!IS_AJAX)
- {
- $this->error(L('common_unauthorized_access'));
- }
- $m = D('Link');
- if($m->create($_POST, 4))
- {
- if($m->delete($id))
- {
- $this->ajaxReturn(L('common_operation_delete_success'));
- } else {
- $this->ajaxReturn(L('common_operation_delete_error'), -100);
- }
- } else {
- $this->ajaxReturn($m->getError(), -1);
- }
- }
- /**
- * [StateUpdate 状态更新]
- * @author Devil
- * @blog http://gong.gg/
- * @version 0.0.1
- * @datetime 2017-01-12T22:23:06+0800
- */
- public function StateUpdate()
- {
- // 参数
- if(empty($_POST['id']) || !isset($_POST['state']))
- {
- $this->ajaxReturn(L('common_param_error'), -1);
- }
- // 数据更新
- if(M('Link')->where(array('id'=>I('id')))->save(array('is_enable'=>I('state'))))
- {
- $this->ajaxReturn(L('common_operation_edit_success'));
- } else {
- $this->ajaxReturn(L('common_operation_edit_error'), -100);
- }
- }
- }
- ?>
|