<?php 
define('IN_PHPMPS', true);
require_once dirname(__FILE__) . '/include/common.php';

extract($_REQUEST);
$page = empty($page)? 1 : intval($page);
$sql = '';
if($orderid) $sql .= " AND orderid='$orderid' ";
if($userid) $sql .= " AND userid='$userid' ";
if($comid) $sql .= " AND comid='$comid' ";
if($payid) $sql .= " AND payid='".$payid."' ";
if($cardnum) $sql .= " AND cardnum='$cardnum' ";

if($begindate) {
	$begintime = strtotime($begindate.' 00:00:00');
	$sql .= " AND addtime>=$begintime ";
}
if($enddate) {
	$endtime = strtotime($enddate.' 23:59:59');
	$sql .= " AND addtime<=$endtime";
}
if($sql) $sql = " WHERE 1 $sql";
$count = $db->getOne("SELECT count(*) as number FROM {$table}pay_exchange $sql");
$pager = get_pager('exchange.php', array('orderid'=>$orderid,'userid'=>$userid,'comid'=>$comid,'payid'=>$payid), $count, $page,'20');
$units = array('0'=>'扫码', '1'=>'店内');
$exchanges = array();
$result = $db->query("SELECT * FROM {$table}pay_exchange $sql ORDER BY exchangeid DESC LIMIT $pager[start],$pager[size]");
while($r = $db->fetchrow($result)) {
	$r['payid'] = $units[$r['payid']];
	$r['soj'] = $r['soj']!=0 ? "-￥".$r['soj'] : '0';
	$r['lej'] = $r['lej']!=0 ? "-￥".$r['lej'] : '0';
	$r['addtime'] = date('Y-m-d h:i:s', $r['addtime']);
	$r['siso'] = number_format($r['value']-$r['fc'],2);
	$exchanges[] = $r;
}
include tpl('list_exchange');
?>