<?php
switch ($act) {
	
	//#####################@ 基本信息 @#####################//
	case 'sy':
		$menumark = 'report_sy';
		$_g_atime1 && $sqlwhere .= " and `tj_date` >= '{$_g_atime1}'";
		$_g_ltime && $sqlwhere .= " and `tj_date` <= '{$_g_ltime}'";
		$sqlwhere .= " order by `id` desc";
		$info_list = $db->pe_selectall('sheet', $sqlwhere, '*', array(20, $_g_page));
		$seo = pe_seo('佣金列表', '', '', 'sheet');
		include(pe_tpl('report_sy.html'));
	break;
	//#################=====商品状态更改=====#################//
	case 'state':	
		$info = $db->pe_select('order', array('order_id'=>$_g_id));
		switch ($_g_state) {
			case 'paidsql':
				if ($db->pe_update('order', array('order_id'=>$_g_id), array('order_state'=>'paid', 'order_ptime'=>time()))) {
					//$email['qunfa_name'] = "您的订单已付款成功，我们即将为您发货！";
					//$email['qunfa_text'] .= "<p>产品名称：{$info['order_name']}</p>";
					//$email['qunfa_text'] .= "<p>已付金额：{$info['order_money']}元</p>";
					//$email['qunfa_text'] .= "<p>收货地址：{$info['user_address']}</p>";
					//订单邮件
					pe_lead('hook/order.hook.php');
					$email['qunfa_name'] = orderemail('pay', 'name', $info);
					$email['qunfa_text'] = orderemail('pay', 'text', $info);
		
					$user['user_name'] = $info['user_tname'];
					$user['user_email'] = $info['user_email'];
					pe_lead('hook/qunfa.hook.php');
					qunfa_emailone($email, $user);
					pe_success('订单付款成功!');
				}
				else {
					pe_error('订单付款失败!');
				}
			break;
			case 'send':
				$ini_wllist = array('顺丰快递','申通快递','圆通快递','韵达快递','中通快递','EMS快递');
				$order_type = array('alipay'=>'支付宝', 'cod'=>'货到付款');
				
				$order = $db->pe_select('order', array('order_id'=>$_g_id));
				$product=$db->pe_select('product',array('product_name'=>$order['order_name']));
				if($product['downurl']){
					$action = "user.php?mod=report&act=state&state=sendsql&id={$_g_id}&v=1";
					include(pe_tpl('report_sendv.html'));
				}
				else{
				$action = "user.php?mod=report&act=state&state=sendsql&id={$_g_id}";
				include(pe_tpl('report_send.html'));
				}
			break;
			case 'sendsql':
				$_p_info['order_state'] = 'send';
				$_p_info['order_stime'] = time();//
				$_p_info['order_num'] =date('YmdHis',TIME).rand(1000,999999);//订单编号				
				if ($db->pe_update('order', array('order_id'=>$_g_id), $_p_info)) {
					//订单邮件
					pe_lead('hook/order.hook.php');
					$info['order_wlname'] = $_p_info['order_wlname'];
					$info['order_wlid'] = $_p_info['order_wlid'];
					$p=$db->pe_select('product',array('product_name'=>$info['order_name']));
					if($p['downurl']){
						$info['downurl']='<a href="'.$p['downurl'].'" target="_blank">'.$p['downurl'].'</a>';
						$sd='sendv';
					}
					else $sd='send';
					$email['qunfa_name'] = orderemail($sd, 'name', $info);
					$email['qunfa_text'] = orderemail($sd, 'text', $info);
					$user['user_name'] = $info['user_tname'];
					$user['user_email'] = $info['user_email'];
					pe_lead('hook/qunfa.hook.php');
					qunfa_emailone($email, $user);
					pe_success('商品发货成功!', '', 'dialog');
				}
				else {
					pe_error('商品发货失败!', '', 'dialog');
				}
			break;
			case 'success':
				$_p_info['order_state'] = 'success';
				if ($db->pe_update('order', array('order_id'=>$_g_id), $_p_info)) {
					pe_success('商品收货成功!');
				}
				else {
					pe_error('商品收货失败!');
				}
			break;
		}
	break;
	case 'jy':
	    
		$_g_num && $sqlwhere .= " and `order_num` = '{$_g_num}'"; 
		$_g_name && $sqlwhere .= " and `order_name` = '{$_g_name}'"; 
		$_g_tid && $sqlwhere .= " and `order_tid` = '{$_g_tid}'";	
		$_g_atime && $sqlwhere .= " and `order_atime` >= '".strtotime($_g_atime)."'";
		$_g_stime && $sqlwhere .= " and `order_stime` < '".strtotime($_g_stime)."'+ 86400";
		$_g_state && $sqlwhere .= " and `order_state` = '{$_g_state}'"; 
		$_g_id && $sqlwhere .= " and `order_id` = '{$_g_id}'";
		$sqlwhere .= " order by `order_id` desc";
		$info_list = $db->pe_selectall('order', $sqlwhere, '*', array(20, $_g_page));
		$seo = pe_seo('交易列表', '', '', 'order');
		include(pe_tpl('report_jy.html'));
	break;
	case 'js':
		$menumark = 'report_js';
		$info = $db->pe_select('user', array('user_id'=>$_s_user_id));
		$cashout= $db->pe_selectall('cashout', array('user_id'=>$_s_user_id,'order by'=>'cashout_atime desc'));
		$info_list = $db->pe_selectall('notice', " and `notice_id` in(4,5,6)");
		$tx_day=date('d',time());
		$tx_mon=date('m',time());
		$tx_year=date('Y',time());
		if($tx_day==01){
		$tx_time=date('Y-m-d',time());
		}elseif($tx_day==02){
		$tx_time=date('Y-m-d',time());
		}elseif($tx_day==03){
		$tx_time=date('Y-m-d',time());
		}else{
		$next_mon=date('m',strtotime('+1 month'));
		if($next_mon==12){
		$next_year=date('Y',strtotime('+1 year'));
		}else{
		$next_year=date('Y',time());
		}
		$tx_time="$next_year-$next_mon-01";
		}
		if($user['user_money']>=5.00 && $tx_day==01){
		$cash=1;
		}elseif($user['user_money']>=5.00 && $tx_day==02){
		$cash=2;
		}elseif($user['user_money']>=5.00 && $tx_day==03){
		$cash=3;
		}else{
		$cash=4;
		}
		
		$getdate_1 = date('Y-m-d' , strtotime('-1 day'));
		if($getdate_1){
		$sqlwhere = " and (`tj_uid` = '$_s_user_id') and `tj_date` = '$getdate_1'";
		$sheet = $db->pe_select('sheet', $sqlwhere);
		$now_money_1= $sheet['tj_money'];
		}
		
		
		$sql = "SELECT SUM(order_tjmoney) sum FROM ".dbpre."order where user_tjid='$_s_user_id' and order_state='send' or order_state='success' and order_isbuy='0'";
		$res = mysql_query($sql);
		$row = mysql_fetch_assoc($res);
		$money_sum=$row['sum'];	
		$seo = pe_seo('个人资料');
		include(pe_tpl('report_js.html'));
	break;
	
	case 'ju':
		
	    $info_list = $db->pe_selectall('notice', " and `notice_id` in(4,5,6)");
		$user_list = $db->pe_selectall('user',array('user_name_tj'=>$_s_user_name));
		$seo = pe_seo('用户明细表', '', '', 'order');
		include(pe_tpl('report_ju.html'));
	break;
	
}
pe_result();

?>