<?php
/* 快捷商城系统
 * 版本号：2.0
 * 官网：http://www.kjcms.cn
 * 2015-02-16
 */
class ctl_index extends mod_index{
	function act_cart() {
		$this->cart_list = cls_mall::cart_list();
		$app_act = '';
		if(count($this->cart_list['list'])<1) $app_act = 'cart.null';
		$this->user_info = fun_kj::get_address();
		$this->areainfo = fun_kj::get_area_all();
		$this->paymethod = cls_config::get("paymethod" , "mall");
		return $this->get_view($app_act);
	}
	function act_cart_go() {
		$this->cart_list = cls_mall::cart_list();
		$app_act = '';
		if(count($this->cart_list['list'])<1) $app_act = 'cart.null';
		$this->user_info = fun_kj::get_address();
		$this->areainfo = fun_kj::get_area_all();
		$this->paymethod = cls_config::get("paymethod" , "mall");
		return $this->get_view($app_act);
	}

	function act_cart_ok() {
		$id = fun_get::get("id");
		$obj_order = cls_obj::db()->get_one("select order_pay_method,order_total_pay,order_id,order_state from " . cls_config::DB_PRE . "mall_order where order_id='" . $id . "'");
		$this->paymethod_list = cls_config::get("paymethod" , "mall");
		if($obj_order['order_pay_method'] == 'bankpayment') {
			$arr_bank = array();
			$obj_result = cls_obj::db()->select("select * from " . cls_config::DB_PRE . "other_bank where bank_state>0");
			while($obj_rs = cls_obj::db()->fetch_array($obj_result)) {
				$arr_bank[] = $obj_rs;
			}
			$this->arr_bank = $arr_bank;
		}
		//当前在线支付方式
		$this->arr_pay = cls_config::get("" , "pay" , array() , "");
		if(!empty($obj_order)) {
			$obj_order['order_total_pay'] = (float)$obj_order['order_total_pay'];
		}
		$arr_state = tab_mall_order::get_perms("state");
		if($obj_order["order_state"]>0) {
			$obj_order["state"] = array_search($obj_order["order_state"] , $arr_state);
		} else {
			$obj_order["state"] = "<font color='#ff0000'>" . array_search($obj_order["order_state"] , $arr_state) . "</font>";
		}
		$this->obj_order = $obj_order;
		return $this->get_view();
	}
	//注册页
	function act_reg() {
		$jump_url = fun_get::get("jump_url");    //获取跳转地址
		if( empty($jump_url) && isset($_SERVER["HTTP_REFERER"]) ) $jump_url=$_SERVER["HTTP_REFERER"];
		if(stristr($jump_url,"app_act=reg") || stristr($jump_url,"app_act=login")) {
			$jump_url = '/';
		}
		$this->jump_fromurl = $jump_url;
		$this->reg_switch = cls_config::get("reg_switch" , "user");
		$this->reg_switch_info = cls_config::get("reg_switch_info" , "user");
		//取注册协议
		$this->reg_content = tab_article::get_bykey("regargreement");
		return $this->get_view(); //显示页面
	}

	//帮助
	function act_news_view() {
		$id = (int)fun_get::get("id");
		$this->id = $id;
		$thisinfo = $this->get_article($id);
		$thisinfo["article_content"] = fun_format::wap_cont($thisinfo['article_content']);
		$this->thisinfo = $thisinfo;
		return $this->get_view(); //显示页面
	}
	function act_login() {
		$jump_url = fun_get::get("jump_url");    //获取跳转地址
		if( empty($jump_url) && isset($_SERVER["HTTP_REFERER"]) ) $jump_url=$_SERVER["HTTP_REFERER"];
		$this->jump_fromurl = $jump_url;
		$this->verfifycode = cls_obj::get("cls_user")->is_verifycode();
		return $this->get_view(); //显示页面
	}
	//订单支付跳转页
	function act_order_pay() {
		$id = fun_get::get("id");
		$pay_method = fun_get::get("pay_method");
		$obj_order = cls_obj::db()->get_one("select order_pay_method , order_total_pay , order_state , order_id from " . cls_config::DB_PRE . "mall_order where order_id='" . $id . "'");
		if(empty($obj_order)) {
			cls_error::on_error("exit" , "订单不存在");
		}
		if($obj_order['order_state'] != 0) {
			if(!in_array($obj_order['order_pay_method'] , array('paymented' , 'afterpayment') )) {
				cls_error::on_display(0 , "订单已经支付" , array(array( 'time' => 10 , 'target' => '_self' , 'title' => '跳转' , 'url' => '/index.php?app=member&app_act=payok&id=' . $id)) );//显示消息页面
			} else {
				cls_error::on_error("exit" , "该订单不能在线支付");
			}
		}
		$arr = cls_obj::get('cls_com')->pay("on_pay" , array("pay_method"=> $pay_method , "pay_title" => "在线购买" , "pay_about_id" => $obj_order['order_id'] , "pay_val" => $obj_order['order_total_pay'] , 'pay_type' => 1 ,'pay_user_id' => cls_obj::get("cls_user")->uid) );
		if($arr['code'] == 0) {
			echo $arr['html'];exit;
		} else {
			cls_error::on_error("exit" , $arr['msg']);
		}
	}
	//找回密码
	function act_findpwd() {
		return $this->get_view(); //显示页面
	}
	//邮件回调找回密码
	function act_findpwd_email() {
		$key = fun_get::get("key");
		$val = fun_get::get("val");
		//是否为邮件认证
		$arr = array("code"=>500,'msg' => '传递参数有误' ,'uid' =>0);
		if(!empty($key)) {
			$arr = tab_sys_verify::on_verify($val , $key , 1);
			if($arr['code'] == 0) {
				$isverify = cls_obj::get("cls_session")->set('sms_verify' , $arr['uid']);//设置已验证标识
			} else {
				$arr['uid'] = 0;
			}
		}
		$this->info = $arr;
		return $this->get_view(); //显示页面
	}

}