<?php
/* 快捷商城系统
 * 版本号：2.0
 * 官网：http://www.kjcms.cn
 * 2015-02-16
 */
class ctl_user extends mod_user{
	function act_default() {
		$this->arr_state = tab_mall_order::get_perms("state");
		$this->order_list = $this->get_order_list();
		return $this->get_view();
	}
	function act_main() {
		$this->arr_state = tab_mall_order::get_perms("state");
		return $this->get_view();
	}
	function act_address() {
		$this->arr_info = fun_kj::get_address();
		$this->areainfo = fun_kj::get_area_all();
		return $this->get_view();
	}
	function act_coin() {
		$this->arr_list = $this->get_repayment_list(1);
		$this->repayment = cls_obj::get("cls_user")->get_repayment();
		return $this->get_view();
	}
	function act_score() {
		$this->arr_list = $this->get_action_list(1);
		$this->score = cls_obj::get("cls_user")->get_score();
		return $this->get_view();
	}
	function act_experience() {
		$this->arr_list = $this->get_action_list();
		$this->process = $this->myvip_progress();
		return $this->get_view();
	}
	function act_order_detail() {
		$id = (int)fun_get::get("id");
		$this->order = $this->get_order_detail($id);
		return $this->get_view();
	}
	function act_order_comment() {
		$order_id = fun_get::get("id");
		$this->comment_detail = $this->get_comment_detail($order_id);
		$arr = cls_config::get("goods_comments" , "mall");
		$arr_comments = array();
		foreach($arr as $item=>$key) {
			$arr_comments[$item] = explode("||" , $key);
		}
		$this->arr_comments = $arr_comments;
		return $this->get_view();
	}
	function act_order_comment_save() {
		$arr = $this->order_comment_save();
		return fun_format::json($arr);
	}
	//收货
	function act_order_receive() {
		$id = fun_get::get("id");
		$arr = tab_mall_order::on_receive($id , "order_user_id='" . cls_obj::get("cls_user")->uid . "'");
		return fun_format::json($arr);
	}
	//取消订单
	function act_order_cancel() {
		$id = fun_get::get("id");
		$arr = tab_mall_order::on_cancel($id , "用户取消订单");
		return fun_format::json($arr);
	}

	//浏览记录
	function act_goods_history() {
		$this->goods_list = $this->get_goods_history();
		return $this->get_view();
	}
	//浏览记录
	function act_goods_history_del() {
		$id = (int)fun_get::get("id");
		$arr = cls_obj::get("cls_session")->get("goods.history");
		if(isset($arr['id_' . $id])) unset($arr['id_' . $id]);
		cls_obj::get("cls_session")->set("goods.history" , $arr);
		return fun_format::json( array( "code" => 0 , "msg" => "成功删除" , "id" => $id ) );
	}
	//浏览记录
	function act_goods_collect() {
		$this->collect_list = $this->get_goods_collect();
		return $this->get_view();
	}
	//浏览记录
	function act_goods_collect_del() {
		$id = (int)fun_get::get("id");
		cls_obj::db_w()->on_exe("delete from " . cls_config::DB_PRE . "mall_goods_collect where collect_user_id='" . cls_obj::get("cls_user")->uid . "' and collect_goods_id='" . $id . "'");
		return fun_format::json( array( "code" => 0 , "msg" => "成功删除" , "id" => $id ) );
	}
	//修改密码
	function act_anquan_editpwd() {
		$arr = $this->on_editpwd();
		return fun_format::json($arr);
	}
	//绑定手机
	function act_anquan_verifytel() {
		$arr = $this->on_bind_verifytel();
		return fun_format::json($arr);
	}
	//保存安全密保
	function act_anquan_safeask() {
		$arr = $this->on_save_safeask();
		return fun_format::json($arr);
	}
	//发送验证码
	function act_anquan_send_sms() {
		$obj_user = cls_obj::db()->get_one("select user_mobile from " . cls_config::DB_PRE . "sys_user where user_id='" . cls_obj::get("cls_user")->uid . "'");
		$mobile = '';
		if(isset($obj_user['user_mobile'])) $mobile = $obj_user['user_mobile'];
		fun_get::get("tel",$mobile);
		fun_get::get("type",4);
		$str = cls_app::on_display('common' , '' , "sys" , "send.sms");
		return $str;
	}
	//验证验证码
	function act_anquan_verify_sms() {
		$obj_user = cls_obj::db()->get_one("select user_mobile from " . cls_config::DB_PRE . "sys_user where user_id='" . cls_obj::get("cls_user")->uid . "'");
		$mobile = '';
		if(isset($obj_user['user_mobile'])) $mobile = $obj_user['user_mobile'];
		fun_get::get("tel",$mobile);
		fun_get::get("type",4);
		$str = cls_app::on_display('common' , '' , "sys" , "verify.sms");
		if( stristr($str , '"code":0,' ) ) {
			cls_obj::get("cls_session")->set('anquan.verify' , 1);//设置已验证标识
		}
		return $str;
	}
	//验证密保
	function act_anquan_verify_ask() {
		$arr_question = array();
		$obj_result = cls_obj::db()->select("select safeask_question,safeask_number,safeask_answer from " . cls_config::DB_PRE . "sys_safeask where safeask_user_id='" . cls_obj::get("cls_user")->uid . "'");
		while($obj_rs = cls_obj::db()->fetch_array($obj_result)) {
			$arr_question[] = $obj_rs;
		}
		foreach($arr_question as $item) {
			$answer = fun_get::get('answer_' . $item['safeask_number']);
			if($item['safeask_answer'] != md5($answer)) return fun_format::json( array( "code" => 500 , "msg" => "验证密保答案错误") );
		}
		cls_obj::get("cls_session")->set('anquan.verify' , 1);//设置已验证标识
		return fun_format::json(array('code' => 0 , 'msg' => '验证成功'));
	}
	//
	function act_anquan() {
		$obj_user = cls_obj::db()->get_one("select user_mobile,user_verify_tel from " . cls_config::DB_PRE . "sys_user where user_id='" . cls_obj::get("cls_user")->uid . "'");
		$mobile = '';
		if(isset($obj_user['user_mobile']) && $obj_user['user_verify_tel']) {
			if(strlen($obj_user['user_mobile'])>5) $obj_user['user_mobile'] = str_pad(substr($obj_user['user_mobile'],0,3),strlen($obj_user['user_mobile'])-4,"*") . substr($obj_user['user_mobile'],-4);
			$mobile = $obj_user['user_mobile'];
		}
		$this->mobile = $mobile;
		$arr_question = array();
		$obj_result = cls_obj::db()->select("select safeask_question,safeask_number from " . cls_config::DB_PRE . "sys_safeask where safeask_user_id='" . cls_obj::get("cls_user")->uid . "'");
		while($obj_rs = cls_obj::db()->fetch_array($obj_result)) {
			$arr_question[] = $obj_rs;
		}
		$this->arr_question = $arr_question;
		$this->ask1 = tab_sys_safeask::get_perms('ask1');
		$this->ask2 = tab_sys_safeask::get_perms('ask2');
		return $this->get_view();
	}
}