<?php
/**
 * +----------------------------------------------------------------------
 * 版本新增
 * +----------------------------------------------------------------------
 * 官网：https://www.sw-x.cn
 * +----------------------------------------------------------------------
 * 作者：小黄牛 <1731223728@qq.com>
 * +----------------------------------------------------------------------
 * 开源协议：http://www.apache.org/licenses/LICENSE-2.0
 * +----------------------------------------------------------------------
*/

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

class Insert extends Admin
{

    /**
     * @AopBefore(class="app\aop\AdminLogin", function="before")
     * @RequestMapping(route="/admin/edition/insert", method="GET|POST", title="版本新增")
    */
    public function run() {
        if (\x\Request::is_ajax()) {
            return $this->_insert();
        }
        $Db = new \x\Db();
        $item_list = $Db->name('item')->order('id ASC')->select();
        $Db->return();
        $this->assign('item_list', $item_list);
        $this->assign('status', edition_status());
        return $this->display();
    }

    // Ajax处理
    private function _insert() {
        $Db = new \x\Db();
        $param = \x\Request::post();
        $param['create_time'] = time();
        if (!empty($param['start_time'])) {$param['start_time'] = strtotime($param['start_time']);}else{$param['start_time'] = 0;}
        if (!empty($param['final_start_time'])) {$param['final_start_time'] = strtotime($param['final_start_time']);}else{$param['final_start_time'] = 0;}
        if (!empty($param['test_time'])) {$param['test_time'] = strtotime($param['test_time']);}else{$param['test_time'] = 0;}
        if (!empty($param['final_test_time'])) {$param['final_test_time'] = strtotime($param['final_test_time']);}else{$param['final_test_time'] = 0;}
        if (!empty($param['publish_time'])) {$param['publish_time'] = strtotime($param['publish_time']);}else{$param['publish_time'] = 0;}
        if (!empty($param['final_publish_time'])) {$param['final_publish_time'] = strtotime($param['final_publish_time']);}else{$param['final_publish_time'] = 0;}

        $res = $Db->name('edition')->insert($param);
        $Db->return();

        if ($res != false) {
            return $this->returnJson('00', '创建成功！');
        }
        return $this->returnJson('01', '创建失败！');
    }

}

