<?php
/*
 * 愚子方提供解码
 * 联系QQ: 179210540
 * 仅提供学习使用
 */
class VersionAction extends Action {
    public function index(){
		header('content-type:text/html;charset=utf-8');
		//V2.6.0升级
		$Model = M();
		$prefix = C('DB_PREFIX');
		$Model->query("CREATE TABLE IF NOT EXISTS `{$prefix}sent` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,`order_id` int(12) DEFAULT '0',`order_status` tinyint(1) DEFAULT '0',`sent_status` tinyint(1) DEFAULT '0',`mobile` varchar(15) DEFAULT NULL,`sent_content` text,`sent_time` datetime DEFAULT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8");
		$Model->query("CREATE TABLE IF NOT EXISTS `{$prefix}receive` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,`order_id` int(12) DEFAULT '0',`mobile` varchar(15) DEFAULT NULL,`receive_content` text,`receive_time` datetime DEFAULT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8");
		
		$Model->query("CREATE TABLE IF NOT EXISTS `{$prefix}order_fengye` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `adgroup_id` varchar(20) DEFAULT NULL, `adgroup_name` varchar(200) DEFAULT NULL, `advertiser_id` varchar(20) DEFAULT NULL, `account_id` varchar(20) DEFAULT NULL, `order_id` varchar(20) DEFAULT NULL, `page_name` varchar(100) DEFAULT NULL, `package_info` text, `quantity` int(5) DEFAULT NULL, `price` decimal(12,2) DEFAULT NULL, `total_price` decimal(12,2) DEFAULT NULL, `user_name` varchar(20) DEFAULT NULL, `user_phone` varchar(20) DEFAULT NULL, `user_province` varchar(20) DEFAULT NULL, `user_city` varchar(20) DEFAULT NULL, `user_area` varchar(20) DEFAULT NULL, `user_address` varchar(100) DEFAULT NULL, `user_ip` varchar(20) DEFAULT NULL, `order_time` datetime DEFAULT NULL, `user_message` varchar(100) DEFAULT NULL, `url` varchar(255) DEFAULT NULL, `add_time` int(10) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `order_id` (`order_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8");
		
		$Order = M('Order');
		$Order->query('alter table __TABLE__ modify column payment varchar(20);');
		$fields = $Order->query('desc __TABLE__ `update_user_id`');
		if(empty($fields)){ $Order->query("ALTER TABLE __TABLE__ add `update_user_id`  int(12) NOT NULL DEFAULT  '0'  after update_time"); }
		$fields = $Order->query('desc __TABLE__ `file`');
		if(empty($fields)){ $Order->query("ALTER TABLE __TABLE__ add `file` varchar(200) after add_time"); }
		$Order->query('update __TABLE__ set payment="payOnDelivery" where payment="1"');
		$Order->query('update __TABLE__ set payment="alipay" where payment="2"');
		$Order->query('update __TABLE__ set payment="wxpay" where payment="3"');
		$Order->query('update __TABLE__ set payment="codepay-1" where payment="4"');
		$Order->query('update __TABLE__ set payment="paypay-1" where payment="44"');
		$Order->query('update __TABLE__ set payment="creaditcard" where payment="66"');
		
		
		$Item = M('Item');
		$fields = $Item->query('desc __TABLE__ `slideshow`');
		if(empty($fields)){ $Item->query("ALTER TABLE __TABLE__ add `slideshow`  text  after thumb"); }
		$Item->query("UPDATE __TABLE__ SET slideshow=image WHERE slideshow IS NULL");
		$fields = $Item->query('desc __TABLE__ `weixin`');
		if(empty($fields)){ $Item->query("ALTER TABLE __TABLE__ add `weixin` text after redirect_uri"); }
		$fields = $Item->query('desc __TABLE__ `min_num`');
		if(empty($fields)){ $Item->query("ALTER TABLE __TABLE__ add `min_num` int(3) DEFAULT 1 after salenum "); }
		$fields = $Item->query('desc __TABLE__ `max_num`');
		if(empty($fields)){ $Item->query("ALTER TABLE __TABLE__ add `max_num` int(5) DEFAULT 10 after min_num"); }
		$fields = $Item->query('desc __TABLE__ `javascript`');
		if(empty($fields)){ $Item->query("ALTER TABLE __TABLE__ add `javascript` text after remark"); }
		$fields = $Item->query('desc __TABLE__ `purchase_url`');
		if(empty($fields)){ $Item->query("ALTER TABLE __TABLE__ add `purchase_url` text after add_time"); }
		$fields = $Item->query('desc __TABLE__ `domain`');
		if(empty($fields)){ $Item->query("ALTER TABLE __TABLE__ add `domain` text after purchase_url"); }
	
		$update = './Public/Database/update.lock';
		if(file_exists($update)){ unlink($update); }
		
		$this->success('升级完成',U('Index/index'));
    }

}










	