<?php
// +----------------------------------------------------------------------
// | [ WE CAN DO IT MORE SIMPLE  ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2020 rights reserved.
// +----------------------------------------------------------------------
// | Author: TABLE ME
// +----------------------------------------------------------------------
// | Date: 2020-08-31 20:43
// +----------------------------------------------------------------------

namespace app\admin\controller\v1;

use app\BaseController;
use app\model\admin\AdminRole;
use app\Request;
use library\services\UtilService;

class SiteRole extends  BaseController
{

    public function list(Request $request) {
       [$sassId] = UtilService::getMore(
            [
                ['sassId','','empty','参数错误']
            ]
        ,$request,true);
       $role = (new AdminRole);
       $role->setSassId($sassId);
       $listAr =$role->getRoleData();
       $result = [];
       foreach ($listAr as $v) {
           $d = [];
           $d['name'] = $v['name'];
           $d['status'] = $v['status'];
           $d['is_system'] = $v['is_system'];
           $d['id'] = $v['id'];
           $result[] = $d;
       }
       return app('json')->success($result);
    }

    /**
     * 角色添加
     */
    public function save(){
       $post = UtilService::getMore([
           ['id','0'],
            ['sassId','','empty','参数错误'],
            ['name','','empty','请输入角色名'],
            ['status',0]
        ]);
       $bool = (new AdminRole)->saveRole($post);
        if($bool)
            return app('json')->success("操作成功", []);
        else
            return app('json')->fail(AdminRole::getErrorInfo());
    }

    /**
     * 删除数据
     * @param Request $request
     */
    public function del(Request $request) {
        [$id] = UtilService::getMore(
            [
                ['id','0']
            ],
            $request,true
        );
        AdminRole::del($id);
        return app('json')->success("删除成功", []);
    }
}