-
Notifications
You must be signed in to change notification settings - Fork 14
/
api.php
160 lines (153 loc) · 5.9 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
<?php
require './oreo/Oreo.Cron.php';
$act=isset($_GET['act'])?daddslashes($_GET['act']):null;
$url=daddslashes($_GET['url']);
$authcode=daddslashes($_GET['authcode']);
if($act=='add')
{
exit('{"code":-4,"msg":"当前接口仅作为备用接口使用"}');
$type=1;
$key = random(32);
$sds=$DB->exec("INSERT INTO `oreo_user` (`key`, `url`, `addtime`, `type`, `active`) VALUES ('{$key}', '{$url}', '{$date}', '{$type}', '1')");
$pid=$DB->lastInsertId();
if($sds){
$result=array("code"=>1,"msg"=>"添加支付商户成功!","pid"=>$pid,"key"=>$key,"type"=>$type);
}else{
$result=array("code"=>-1,"msg"=>"添加支付商户失败!");
}
}
elseif($act=='apply')
{
$token=daddslashes($_GET['token']);
$row=$DB->query("SELECT * FROM oreo_panuser WHERE token='{$token}' limit 1")->fetch();
if($row && $row['active']==1){
$type=0;
$key = random(32);
$sds=$DB->exec("INSERT INTO `oreo_user` (`key`, `url`, `addtime`, `type`, `active`, `uid`) VALUES ('{$key}', '{$url}', '{$date}', '{$type}', '1', '{$row['id']}')");
$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"=>"TOKEN ERROR");
}
}
elseif($act=='query')
{
$pid=intval($_GET['pid']);
$key=daddslashes($_GET['key']);
$row=$DB->query("SELECT * FROM oreo_user WHERE id='{$pid}' limit 1")->fetch();
if($row){
if($key==$row['key']){
$orders=$DB->query("SELECT count(*) from oreo_order WHERE pid={$pid}")->fetchColumn();
$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 oreo_order where pid={$pid} and status=1 and endtime>='$today'")->fetchColumn();
$order_lastday=$DB->query("SELECT sum(money) from oreo_order where pid={$pid} and status=1 and endtime>='$lastday' and endtime<'$today'")->fetchColumn();
$settle_money=$DB->query("SELECT sum(money) from oreo_settle where pid={$pid} and status=1")->fetchColumn();
$result=array("code"=>1,"pid"=>$pid,"key"=>$key,"type"=>$row['settle_id'],"active"=>$row['active'],"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,"settle_money"=>$settle_money);
}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 oreo_user WHERE id='{$pid}' limit 1")->fetch();
if($row){
if($key==$row['key']){
if($account==null || $username==null){
$result=array("code"=>-1,"msg"=>"保存错误,请确保每项都不为空!");
}elseif($row['type']!=2 && !empty($row['account']) && !empty($row['username']) && $row['account']!=$account){
$result=array("code"=>-1,"msg"=>"为保障您的资金安全,暂不支持直接修改结算账号信息,如需修改请联系QQ".$conf['web_qq']);
}else{
$type=1;
$sds=$DB->exec("update `oreo_user` set `account`='{$account}',`username`='{$username}',`type`='{$type}',`settle_id`='{$stype}',`url`='{$url}' where id='{$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 oreo_user WHERE id='{$pid}' limit 1")->fetch();
if($row){
if($key==$row['key']){
$rs=$DB->query("SELECT * FROM oreo_settle WHERE pid='{$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')
{
$out_trade_no=daddslashes($_GET['out_trade_no']);
$row=$DB->query("SELECT * FROM oreo_order WHERE out_trade_no='{$out_trade_no}' limit 1")->fetch();
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"=>"订单号不存在");
}
}
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 oreo_user WHERE id='{$pid}' limit 1")->fetch();
if($row){
if($key==$row['key']){
$rs=$DB->query("SELECT * FROM oreo_order WHERE pid='{$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);
?>