<?php
// +----------------------------------------------------------------------
// | 角色编辑
// +----------------------------------------------------------------------
// | Copyright (c) 2018 https://blog.junphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小黄牛 <1731223728@qq.com>
// +----------------------------------------------------------------------

namespace app\controller\admin\item;
use app\controller\SuperClass\Admin;

class Update extends Admin
{

    /**
     * @AopBefore(class="app\aop\AdminLogin", function="before")
     * @RequestMapping(route="/admin/item/update", method="GET|POST", title="角色编辑")
     * @Ioc(class="\x\Db", name="Db")
    */
    public function run() {
        if (\x\Request::is_ajax()) {
            return $this->_update();
        }
        $param = \x\Request::get();

        $admin_list = $this->Db->name('auth_admin')->order('id ASC')->select();
        $this->assign('admin_list', $admin_list);
        $info = $this->Db->name('item')->where('id', $param['id'])->find();
        $this->assign('info', $info);

        $this->Db->return();
        return $this->display();
    }

    // Ajax处理
    private function _update() {
        $param = \x\Request::post();
        $param['update_time'] = time();
        unset($param['file']);
        $res = $this->Db->name('item')->where('id', $param['id'])->update($param);
        $this->Db->return();
        if ($res != false) {
            return $this->returnJson('00', '修改成功！');
        }

        return $this->returnJson('01', '修改失败！');
    }

}

