| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 | <?phpnamespace Admin\Controller;/** * 投票管理 * @author   brent * @version  0.0.1 */class VoteController extends CommonController {    protected $table = ''; //表名    /**     * [_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();        //要执行的表        $this->table = M('activity_vote');    }    /**     * [Index 列表]     * @author   Devil     * @blog     http://gong.gg/     * @version  0.0.1     * @datetime 2016-12-06T21:31:53+0800     */    public function Index() {        $where = array();        $listRows = I('listRows') ? I('listRows') : 100;        $keyword = I("keyword", "", "trim");        $keyword && $where['uid'] = array('like', '%' . $keyword . '%');        if (isset($keyword) && !empty($keyword)) {            $this->assign('keyword', $keyword);        }                $page = I('p') ? I('p') : 1;        $this->assign('p', $page);        $list = D('Admin/Vote')->get_vote_list($where, $page, $listRows, $count);        $mengbaos = M('activity_mengbao')->getField('id,name',true);        $Page = new \Think\Page($count, $listRows);        $Page->parameter .= "&p=[PAGE]";        $Page->parameter .= "&listRows=" . $listRows;        $Page->parameter .= "&keyword=" .$keyword;        $Page = $this->page_config($Page);        $show = $Page->show();        $this->assign('page', $show);        $this->assign('List', $list);        $this->assign('Mengbaos', $mengbaos);        $this->display('Index');    }    /**     * [SaveInfo 文章添加/编辑页面]     * @author   Devil     * @blog     http://gong.gg/     * @version  0.0.1     * @datetime 2016-12-14T21:37:02+0800     */    public function SaveInfo() {        // 文章信息        if (empty($_REQUEST['id'])) {            $data = array();        } else {            $data = $this->table->find(I('id'));            if (empty($data)) {                $data = array('id' => I('id'));            }        }        $this->assign('data', $data);        $this->display('SaveInfo');    }    /**     * [Save 文章添加/编辑]     * @author   Devil     * @blog     http://gong.gg/     * @version  0.0.1     * @datetime 2016-12-14T21:37:02+0800     */    public function Save() {        // 是否ajax请求        if (!IS_AJAX) {            $this->error(L('common_unauthorized_access'));        }        // 添加        if (empty($_POST['id'])) {            $this->Add();            // 编辑        } else {            $this->Edit();        }    }    /**     * [Add 文章添加]     * @author   Devil     * @blog     http://gong.gg/     * @version  0.0.1     * @datetime 2016-12-18T16:20:59+0800     */    private function Add() {        $data['uid'] = I('uid');        $data['num'] = I('num');        $data['act_id'] = I('act_id');        $data['date'] = I('date');        $data['created_at'] = I('created_at');        // 数据添加        if ($this->table->add($data)) {            $this->ajaxReturn(L('common_operation_add_success'));        } else {            $this->ajaxReturn(L('common_operation_add_error'), -100);        }    }    /**     * [Edit 文章编辑]     * @author   Devil     * @blog     http://gong.gg/     * @version  0.0.1     * @datetime 2016-12-17T22:13:40+0800     */    private function Edit() {        $id = I('id');        $data = array();        $data['uid'] = I('uid');        $data['num'] = I('num');        $data['act_id'] = I('act_id');        $data['date'] = I('date');        $data['created_at'] = I('created_at');        // 数据更新        if (false !== $this->table->where(array('id' => $id))->save($data)) {            $this->ajaxReturn(L('common_operation_edit_success'));        } else {            $this->ajaxReturn(L('common_operation_edit_error'), -100);        }    }    /**     * [Delete 删除]     * @author   Devil     * @blog     http://gong.gg/     * @version  0.0.1     * @datetime 2016-12-15T11:03:30+0800     */    public function Delete() {        // 是否ajax请求        if (!IS_AJAX) {            $this->error(L('common_unauthorized_access'));        }        // 删除数据        if (!empty($_POST['id'])) {            // 更新            if ($this->table->delete(I('id'))) {                $this->ajaxReturn(L('common_operation_delete_success'));            } else {                $this->ajaxReturn(L('common_operation_delete_error'), -100);            }        } else {            $this->ajaxReturn(L('common_param_error'), -1);        }    }}
 |