AdminAddscoreController.php 4.8 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <bronet@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\portal\model\AddScoreModel;

use cmf\controller\AdminBaseController;
use think\Db;
use think\Loader;


class AdminAddscoreController extends AdminBaseController
{
    /**
     * 获得积分设置
     * @adminMenu(
     *     'name'   => '获得积分设置',
     *     'parent' => 'portal/AdminScore/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '获得积分设置',
     *     'param'  => ''
     * )
     */
    public function index(){
        $data = $this->request->param();
        $final = $this->adminIndex($data);
        $where_coo = $final['where_arr'];
        $where_coo['status'] = 1;
        $coo_list = Db::name('AddScore')->where($where_coo)->order('create_time desc')
        ->paginate(10,false,['query'=>$final['page_arr']]);
        $page = $coo_list->render();
        $this->assign('page',$page);
        $this->assign('list',$coo_list);
        return $this->fetch();
    }


    /**
     * 添加获得积分
     * @adminMenu(
     *     'name'   => '添加获得积分',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '添加获得积分',
     *     'param'  => ''
     * )
     */
    public function add()
    {
        $data = $this->request->param();
        if($data){
//            添加数据
            $model = new AddScoreModel();
            $validate = Loader::validate('AddScore');
            if(!$validate->check($data)){
                $mes = $validate->getError();
                $this->error("$mes");
            }
            $final = $model->isUpdate(false)->save($data);
            if($final){
                $this->success('成功',url('index'));
            }else{
                $this->error('失败');
            }
        }else{
            return $this->fetch();
        }
    }


    /**
     * 查看获得积分
     * @adminMenu(
     *     'name'   => '查看获得积分',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '查看获得积分',
     *     'param'  => ''
     * )
     */
    public function view()
    {
        $where_find['id'] = $this->request->param('id');
        $list = Db::name('AddScore')->where($where_find)->find();
        $this->assign('list',$list);
        return $this->fetch();
    }


    /**
     * 编辑获得积分
     * @adminMenu(
     *     'name'   => '编辑获得积分',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '编辑获得积分',
     *     'param'  => ''
     * )
     */
    public function edit()
    {
//            添加数据
        $data = $this->request->post();
        $validate = Loader::validate('AddScore');
        if(!$validate->check($data)){
            $mes = $validate->getError();
            $this->error("$mes");
        }
        $model = new AddScoreModel();
        $final = $model->isUpdate(true)->save($data);
        if($final){
            $this->success('成功',url('index'));
        }else{
            $this->error('失败');
        }
    }


    /**
     * 删除获得积分
     * @adminMenu(
     *     'name'   => '删除获得积分',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除获得积分',
     *     'param'  => ''
     * )
     */
    public function del(){
        $ids = $this->request->post();
        $id = $this->request->param('id');
        if($ids){
            $add_del['id'] = array('in',$ids['ids']);
        }else if($id){
            $add_del['id'] = $id;
        }else{
            $this->error('删除失败');
        }
        $add_del['status'] = 9;
        $model = new AddScoreModel();
        $del = $model->isUpdate(true)->allowField(true)->save($add_del);
        if($del){
            $this->success('删除成功',url('index'));
        }else{
            $this->error('删除失败');
        }
    }
}