forked from Blokura/Epay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
168 lines (159 loc) · 6.21 KB
/
api.php
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
$nosession = true;
require './includes/common.php';
$act=isset($_GET['act'])?daddslashes($_GET['act']):null;
$url=daddslashes($_GET['url']);
$authcode=daddslashes($_GET['authcode']);
if($act=='apply')
{
$pid=intval($_GET['pid']);
$key=daddslashes($_GET['key']);
$row=$DB->getRow("SELECT * FROM pre_user WHERE uid='{$pid}' limit 1");
if($row && $row['status']==1 && $row['apply']==1){
$type=0;
$key = random(32);
$sds=$DB->exec("INSERT INTO `pre_user` (`key`, `url`, `addtime`, `pay`, `settle`, `status`, `upuid`) VALUES ('{$key}', '{$url}', '{$date}', '1', '1', '1', '{$row['uid']}')");
$pid=$DB->lastInsertId();
if($sds){
$result=array("code"=>1,"msg"=>"添加支付商户成功!","pid"=>$pid,"key"=>$key,"type"=>$type);
}else{
$result=array("code"=>-1,"msg"=>"添加支付商户失败!");
}
}else{
$result=array("code"=>-1,"msg"=>"当前商户没有权限");
}
}
elseif($act=='query')
{
$pid=intval($_GET['pid']);
$key=daddslashes($_GET['key']);
$row=$DB->getRow("SELECT * FROM pre_user WHERE uid='{$pid}' limit 1");
if($row){
if($key==$row['key']){
$orders=$DB->getColumn("SELECT count(*) from pre_order WHERE uid={$pid}");
$lastday=date("Y-m-d",strtotime("-1 day")).' 00:00:00';
$today=date("Y-m-d").' 00:00:00';
$order_today=$DB->query("SELECT sum(money) from pre_order where uid={$pid} and status=1 and endtime>='$today'")->fetchColumn();
$order_lastday=$DB->query("SELECT sum(money) from pre_order where uid={$pid} and status=1 and endtime>='$lastday' and endtime<'$today'")->fetchColumn();
//$settle_money=$DB->query("SELECT sum(money) from pre_settle where uid={$pid} and status=1")->fetchColumn();
$result=array("code"=>1,"pid"=>$pid,"key"=>$key,"type"=>$row['settle_id'],"active"=>$row['status'],"money"=>$row['money'],"account"=>$row['account'],"username"=>$row['username'],"settle_money"=>$conf['settle_money'],"settle_fee"=>$conf['settle_fee'],"money_rate"=>$conf['money_rate'],"orders"=>$orders,"order_today"=>$order_today,"order_lastday"=>$order_lastday);
}else{
$result=array("code"=>-2,"msg"=>"KEY校验失败");
}
}else{
$result=array("code"=>-3,"msg"=>"PID不存在");
}
}
elseif($act=='change')
{
$pid=intval($_GET['pid']);
$key=daddslashes($_GET['key']);
$stype=daddslashes($_GET['type']);
$account=daddslashes($_GET['account']);
$username=daddslashes($_GET['username']);
$row=$DB->query("SELECT * FROM pre_user WHERE uid='{$pid}' limit 1")->fetch();
if($row){
if($key==$row['key']){
if($account==null || $username==null){
$result=array("code"=>-1,"msg"=>"保存错误,请确保每项都不为空!");
}elseif($row['settle']!=2 && !empty($row['account']) && !empty($row['username']) && $row['account']!=$account){
$result=array("code"=>-1,"msg"=>"为保障您的资金安全,暂不支持直接修改结算账号信息,如需修改请进入商户中心".$siteurl);
}else{
$sds=$DB->exec("update `pre_user` set `account`='{$account}',`username`='{$username}',`settle_id`='{$stype}',`url`='{$url}' where uid='{$pid}' limit 1");
if($sds>=0){
$result=array("code"=>1,"msg"=>"修改收款账号成功!","pid"=>$pid,"key"=>$key,"type"=>$type);
}else{
$result=array("code"=>-1,"msg"=>"修改收款账号失败!");
}
}
}else{
$result=array("code"=>-2,"msg"=>"KEY校验失败");
}
}else{
$result=array("code"=>-3,"msg"=>"PID不存在");
}
}
elseif($act=='settle')
{
$pid=intval($_GET['pid']);
$key=daddslashes($_GET['key']);
$limit=$_GET['limit']?intval($_GET['limit']):10;
if($limit>50)$limit=50;
$row=$DB->query("SELECT * FROM pre_user WHERE uid='{$pid}' limit 1")->fetch();
if($row){
if($key==$row['key']){
$rs=$DB->query("SELECT * FROM pre_settle WHERE uid='{$pid}' order by id desc limit {$limit}");
while($row=$rs->fetch()){
$data[]=$row;
}
if($rs){
$result=array("code"=>1,"msg"=>"查询结算记录成功!","pid"=>$pid,"key"=>$key,"type"=>$type,"data"=>$data);
}else{
$result=array("code"=>-1,"msg"=>"查询结算记录失败!");
}
}else{
$result=array("code"=>-2,"msg"=>"KEY校验失败");
}
}else{
$result=array("code"=>-3,"msg"=>"PID不存在");
}
}
elseif($act=='order')
{
$pid=intval($_GET['pid']);
$key=daddslashes($_GET['key']);
$row=$DB->query("SELECT * FROM pre_user WHERE uid='{$pid}' limit 1")->fetch();
if($row){
if($key==$row['key']){
if(isset($_GET['trade_no'])){
$trade_no=daddslashes($_GET['trade_no']);
$row=$DB->query("SELECT * FROM pre_order WHERE uid='{$pid}' and trade_no='{$trade_no}' limit 1")->fetch();
}elseif(isset($_GET['out_trade_no'])){
$out_trade_no=daddslashes($_GET['out_trade_no']);
$row=$DB->query("SELECT * FROM pre_order WHERE uid='{$pid}' and out_trade_no='{$out_trade_no}' limit 1")->fetch();
}else{
exit('{"code":-4,"msg":"参数不完整"}');
}
if($row){
$result=array("code"=>1,"msg"=>"查询订单号成功!","trade_no"=>$row['trade_no'],"out_trade_no"=>$row['out_trade_no'],"type"=>$row['type'],"pid"=>$row['pid'],"addtime"=>$row['addtime'],"endtime"=>$row['endtime'],"name"=>$row['name'],"money"=>$row['money'],"status"=>$row['status']);
}else{
$result=array("code"=>-1,"msg"=>"订单号不存在");
}
}else{
$result=array("code"=>-2,"msg"=>"KEY校验失败");
}
}else{
$result=array("code"=>-3,"msg"=>"PID不存在");
}
}
elseif($act=='orders')
{
$pid=intval($_GET['pid']);
$key=daddslashes($_GET['key']);
$limit=$_GET['limit']?intval($_GET['limit']):10;
if($limit>50)$limit=50;
$row=$DB->query("SELECT * FROM pre_user WHERE uid='{$pid}' limit 1")->fetch();
if($row){
if($key==$row['key']){
$rs=$DB->query("SELECT * FROM pre_order WHERE uid='{$pid}' order by trade_no desc limit {$limit}");
while($row=$rs->fetch()){
$data[]=$row;
}
if($rs){
$result=array("code"=>1,"msg"=>"查询订单记录成功!","data"=>$data);
}else{
$result=array("code"=>-1,"msg"=>"查询订单记录失败!");
}
}else{
$result=array("code"=>-2,"msg"=>"KEY校验失败");
}
}else{
$result=array("code"=>-3,"msg"=>"PID不存在");
}
}
else
{
$result=array("code"=>-5,"msg"=>"No Act!");
}
echo json_encode($result);
?>