groupfinance.inc.php
3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
require_once IA_ROOT . '/addons/zh_cjdianc/inc/class/Order.php';
require_once IA_ROOT . '/addons/zh_cjdianc/inc/class/Finance.php';
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu2();
$storeid = $_COOKIE["storeid"];
$cur_store = $this->getStoreById($storeid);
$type = isset($_GPC['type'])?$_GPC['type']:'today';
$pageindex = max(1, intval($_GPC['page']));
$pagesize = 10;
$orderType = Order::TYPE_GROUP;
$where = " where a.uniacid=:uniacid and a.type={$orderType} and a.store_id=:store_id and a.pay_type in (1,2) and a.state in (2,3,4,5,7,8,9,10)" ;
$data[':uniacid'] = $_W['uniacid'];
$data[':store_id'] = $storeid;
if ($_GPC['time']) {
$start = strtotime($_GPC['time']['start']);
$end = strtotime($_GPC['time']['end']);
$where .= " and UNIX_TIMESTAMP(a.time) >='{$start}' and UNIX_TIMESTAMP(a.time) <= '{$end}'";
$type = 'all';
} else {
if ($type == 'today') {
$time = date("Y-m-d",time());
$where .= " and a.time LIKE '%{$time}%' ";
}
if ($type == 'yesterday') {
$time = date("Y-m-d",strtotime("-1 day"));
$where .= " and a.time LIKE '%{$time}%' ";
}
if ($type == 'week') {
$time = strtotime(date("Y-m-d",strtotime("-7 day")));
$where .= " and UNIX_TIMESTAMP(a.time) > ".$time;
}
if ($type == 'month') {
$time = date("Y-m");
$where .= " and a.time LIKE '%{$time}%' ";
}
}
//总数统计
$statSql = "select sum(ops.pay_price) as 'pay_price', sum(ops.goods_price) as 'goods_price',sum(ops.service_fee) as service_fee,sum(ops.delivery_fee) as delivery_fee, sum(ops.wx_pay_fee) as wx_pay_fee, sum(ops.refund_price) as refund_price, sum(ops.discount_price) as discount_price".
" from ". tablename("cjdc_order") ." as a ".
" left join ".tablename('cjdc_order_price_stat'). " as ops on ops.order_id = a.id".
$where.
' group by ops.order_id';
$statArr = pdo_fetchcolumn($statSql, $data);
$sql = "SELECT {selectedFields} ".
" FROM ".tablename('cjdc_order'). " a".
" left join ".tablename('cjdc_order_price_stat'). " as ops on ops.order_id = a.id".
$where." ORDER BY a.id DESC";
$fields = "a.*,ops.delivery_fee,ops.pay_price, ops.wx_pay_fee, ops.refund_price, ops.service_fee";
$listSql = str_replace("{selectedFields}", $fields, $sql);
$countSql = str_replace("{selectedFields}", "count(*)", $sql);
$total = pdo_fetchcolumn($countSql, $data);
$select_sql = $listSql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
$pager = pagination($total, $pageindex, $pagesize);
$list = pdo_fetchall($select_sql, $data);
//
if(checksubmit('export_submit', true)) {
$sql = "SELECT {selectedFields} ".
" FROM ".tablename('cjdc_order'). " a".
" left join ".tablename('cjdc_order_price_stat'). " as ops on ops.order_id = a.id".
$where." ORDER BY a.id DESC";
$fields = "a.*,ops.delivery_fee,ops.pay_price, ops.wx_pay_fee, ops.refund_price, ops.service_fee";
$listSql = str_replace("{selectedFields}", $fields, $sql);
$list = pdo_fetchall($listSql, $data);
header('Content-Type: application/vnd.ms-excel;charset=utf-8');
header("Content-Disposition:attachment; filename=拼团资金数据.xls");
header('Cache-Control: max-age=0');
$fp = fopen('php://output', 'a');
include $this->template('web/groupfinanceExport');
exit();
}
include $this->template('web/groupfinance');