<?php
/**
 * @brief 升级更新控制器
 */
class Update extends IController
{
	/**
	 * @brief 升级更新
	 */
	public function index()
	{
		set_time_limit(0);

		$sql = array(
			"alter table `{pre}topic` add column `goods_ids` text COMMENT '商品ID(逗号分隔)';",

			"alter table `{pre}bill` add column `bill_no` varchar(255) NOT NULL COMMENT '付款单号B2021010101010000';",
			"alter table `{pre}bill` add column `payment_no` varchar(255) DEFAULT NULL COMMENT '支付平台回执单号';",
			"alter table `{pre}bill` add column `way` varchar(255) NOT NULL COMMENT '结算方式:wechat,offline';",

			"ALTER TABLE `{pre}bill` DROP `apply_time`;",
			"ALTER TABLE `{pre}bill` DROP `is_pay`;",
			"ALTER TABLE `{pre}bill` DROP `apply_content`;",
			"ALTER TABLE `{pre}bill` DROP `pay_content`;",
			"ALTER TABLE `{pre}bill` DROP `start_time`;",
			"ALTER TABLE `{pre}bill` DROP `end_time`;",

			"alter table `{pre}oauth_user` add column `openid_mini` varchar(80) NOT NULL default '' COMMENT 'openid参数只针对微信小程序';",
		);

		foreach($sql as $key => $val)
		{
		    IDBFactory::getDB()->query( $this->_c($val) );
		}

        //清空runtime缓存
		$runtimePath = IWeb::$app->getBasePath().'runtime';
		$result      = IFile::clearDir($runtimePath);
		die("升级成功!! V5.9版本");
	}

	public function _c($sql)
	{
		return str_replace('{pre}',IWeb::$app->config['DB']['tablePre'],$sql);
	}
}