| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 | <?phpnamespace Admin\Controller;/** * 样式管理 * @author   brent * @version  0.0.1 */class CollectController 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_collect');    }    /**     * [Index 文章列表]     * @author   Devil     * @blog     http://gong.gg/     * @version  0.0.1     * @datetime 2016-12-06T21:31:53+0800     */    public function Index() {        //关键字        $keyword = I('keyword');        if($keyword){            $where['uid'] = ['like',"%$keyword%"];        }        $listRows = I('listRows',100,'intval');        if($p = I('p',1,'intval')){            $offset = ($p-1)*$listRows;        }        $acts = M('activity_v2')->field('id,activity_name')->select();        $this->assign('acts', $acts);        //活动id        $act_id = trim(I('act_id'));          if($act_id){            $where['act_id'] = $act_id;        }else{            $act_id = M('activity_v2')->max('id');        }        $List = $this->table                ->where($where)                ->order('id desc')                ->limit($offset,$listRows)                ->select();        $activitys = M('activity_v2')->where(['id'=>$act_id])->find();        if($activitys['collect_list']){            $collects = json_decode($activitys['collect_list'],true);            $collects = array_column($collects, null,'collect_id');        }        foreach ($List as $key=>$row) {            $List[$key]['activity_name'] = $activitys['activity_name'];            if($collects){                $List[$key]['collect_name']  = $collects[$row['collect_id']]['collect_name'];            }        }        $count = $this->table->where($where)->count();        $Page = new \Think\Page($count, $listRows);        $Page->parameter .= "&p=[PAGE]";        $Page->parameter .= "&act_id=".$act_id;        $Page->parameter .= "&keyword=".$keyword;        $Page = $this->page_config($Page);        $show = $Page->show();        $this->assign('page', $show);        $this->assign('List', $List);        //获取所有活动        $this->assign('keyword', $keyword);        $this->assign('act_id', $act_id);        $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'));            }        }        $data = M('Activity_v2')->field('id,activity_name')->select();        $this->assign('Acts', $data);        $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() {        $m = $this->table;        $data = I('post.');        $data['created_at'] = $data['collect_date'] ?  : date('Y-m-d H:i:s');        $data['operate'] = 1;        // 数据添加        if ($m->add($data)) {            $this->ajaxReturn('更新成功');        } else {            $this->ajaxReturn('更新失败',400);        }    }    /**     * [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);        }    }    public function Search()    {        $act_id = I('act_id');        if(empty($act_id)){            echo json_encode(array());            die;        }        $data['activity'] = M('Activity_v2')->where(['id'=>$act_id])->find();                $data['activity']['start_at'] = $data['activity']['start_at'];                $data['activity']['end_at'] = $data['activity']['end_at'];//         dump(json_decode($data['activity']['prize_list'],true));        $data['collects'] = json_decode($data['activity']['collect_list'],true);        echo json_encode($data);    }}
 |