<?php
$output = '';
$output.="<?php\n";
$output.="\n";
$output.="namespace App\\Modules\\Manage\\Controllers;\n";
$output.="\n";
$output.="use App\\Models\\".$this->className.";\n";
$output.="use App\\Modules\\Manage\\Controllers\\Base\\BaseController;\n";
$output.="use App\\Common\\Code;\n";
$output.="use App\\Common\\Msg;\n";
$output.="\n";
$output.="/**\n";
$output.=" * ".$this->className."\n";
$output.=" * @author Chengcheng\n";
$output.=" * @date ".date('Y-m-d H:i:s')."\n";
$output.=" */\n";
$output.=" class ".$this->className."Controller extends BaseController\n";
$output.="{\n";
$output.="    /**\n";
$output.="     * 设置不需要登录的的Action,不加Action前缀\n";
$output.="     * @author Chengcheng\n";
$output.="     * @date ".date('Y-m-d H:i:s')." \n";
$output.="     * @return array\n";
$output.="     */\n";
$output.="    protected function noLogin()\n";
$output.="    {\n";
$output.="        // 以下Action不需要登录权限\n";
$output.="        return [];\n";
$output.="    }\n";
$output.="\n";
$output.="    /**\n";
$output.="     * 设置不需要权限验证的Action,不加Action前缀\n";
$output.="     * @author Chengcheng\n";
$output.="     * @date ".date('Y-m-d H:i:s')." \n";
$output.="     * @return array\n";
$output.="     */\n";
$output.="    protected function noAuth()\n";
$output.="    {\n";
$output.="        // 以下Action不需要角色权限\n";
$output.="        return [];\n";
$output.="    }\n";
$output.="\n";
$output.="    /**\n";
$output.="     * 列表\n";
$output.="     * @author ChengCheng\n";
$output.="     * @date ".date('Y-m-d H:i:s')." \n";
$output.="     * @return array\n";
$output.="     */\n";
$output.="    public function get".$this->className."List()\n";
$output.="    {\n";
$output.="        /*\n";
$output.="         * 1 获取输入参数\n";
$output.="         * pageNum              页码\n";
$output.="         * pageSize             页面大小\n";
$output.="         * orders               排序，数组结构，支持多维度排序\n";
$output.="         * id                   ID\n";
$output.="         * */\n";
$output.="        \$this->requestData['pageNum']   = \$this->input('pageNum', null);\n";
$output.="        \$this->requestData['pageSize']  = \$this->input('pageSize', null);\n";
$output.="        \$this->requestData['orders']    = \$this->input('orders', null);\n";
$output.="        \$this->requestData['id']        = \$this->input('id', null);\n";
$output.="        \n";
$output.="        //2 查找信息\n";
$output.="        \$data = ".$this->className."::model()->lists(\$this->requestData);\n";
$output.="        \n";
$output.="        //3 设置返回结果\n";
$output.="        \$result['code'] = Code::SYSTEM_OK;\n";
$output.="        \$result['msg']  = Msg::SYSTEM_OK;\n";
$output.="        \$result['data'] = \$data;\n";
$output.="        \n";
$output.="        //4 返回结果\n";
$output.="        return \$this->ajaxReturn(\$result);\n";
$output.="    }\n";
$output.="\n";
$output.="    /**\n";
$output.="     * 编辑\n";
$output.="     * @author ChengCheng\n";
$output.="     * @date ".date('Y-m-d H:i:s')." \n";
$output.="     * @return array\n";
$output.="     */\n";
$output.="    public function edit".$this->className."()\n";
$output.="    {\n";
$output.="        /*\n";
$output.="         * 1 获取输入参数\n";

foreach($this->fields as $f){
$output.="         * ".str_pad($f['field'],20)."".$f['comment']."\n";
}
$output.="         * */\n";
foreach($this->fields as $f){
$output.="        ".str_pad("\$this->requestData['".$f['field']."']",40)."= \$this->input('".$f['field']."', null);\n";
}
$output.="        \n";
$output.="        //2 编辑信息\n";
$output.="        \$data = ".$this->className."::model()->edit(\$this->requestData);\n";
$output.="        \n";
$output.="        //3 设置结果\n";
$output.="        \$result['code'] = Code::SYSTEM_OK;\n";
$output.="        \$result['msg']  = Msg::SYSTEM_OK;\n";
$output.="        \$result['data'] = \$data;\n";
$output.="        \n";
$output.="        //4 返回结果\n";
$output.="        return \$this->ajaxReturn(\$result);\n";
$output.="    }\n";
$output.="\n";
$output.="    /**\n";
$output.="     * 删除\n";
$output.="     * @author ChengCheng\n";
$output.="     * @date ".date('Y-m-d H:i:s')." \n";
$output.="     * @return array\n";
$output.="     */\n";
$output.="    public function delete".$this->className."()\n";
$output.="    {\n";
$output.="        //1 获取输入参数 id\n";
$output.="        \$id = \$this->input('id', null);\n";
$output.="        \n";
$output.="        //2 检查参数\n";
$output.="        if (empty(\$id)) {\n";
$output.="            \$result['code'] = Code::SYSTEM_PARAMETER_FORMAT_ERROR;\n";
$output.="            \$result['msg']  = sprintf(Msg::SYSTEM_PARAMETER_FORMAT_ERROR, 'id');\n";
$output.="            return \$this->ajaxReturn(\$result);\n";
$output.="        }\n";
$output.="        \n";
$output.="        //3 删除\n";
$output.="        \$data           = ".$this->className."::model()->where('id', \$id)->delete();\n";
$output.="        \$result['code'] = Code::SYSTEM_OK;\n";
$output.="        \$result['msg']  = Msg::SYSTEM_OK;\n";
$output.="        \$result['data'] = \$data;\n";
$output.="        //3 返回结果\n";
$output.="        return \$this->ajaxReturn(\$result);\n";
$output.="    }\n";
$output.="}\n";
?>
<?php echo $output; ?>