Thank.php
4.4 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
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
<?php
namespace app\api\controller;
use addons\epay\library\Service;
use app\api\model\Order;
use app\api\model\Price;
use app\api\model\Third;
use app\api\model\VipConfig;
use app\common\controller\Api;
/**
* 答谢
*/
class Thank extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['getPriceList', 'pay'];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
/**
* 支付下单
* @ApiTitle (支付下单)
* @ApiSummary (支付下单)
* @ApiMethod (POST)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="money", type="integer", required=true, description="价格")
* @ApiParams (name="userb_id", type="integer", required=true, description="学长ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ()
*/
public function pay()
{
$userId = $this->auth->id;
$money = $this->request->param('money', 0, 'int');
if(!$money || $money <= 0 || (!is_float($money) && !is_numeric($money))) {
$this->error('您的操作有误');
}
$userbId = $this->request->param('userb_id', 0, 'int');
if(!$userbId) {
$this->error('您的操作有误');
}
//open_id
$third = new Third();
$thirdInfo = $third->getOneByUserId($userId);
if(!$thirdInfo) {
$this->error('您提交的内容有误');
}
$openid = $thirdInfo['openid'];
$amount = $money;
$amount = 0.01;
$order = new Order();
$out_trade_no = date("YmdHis", time()) . mt_rand(100000, 999999);
$insertData = [
'createtime' => time(),
'updatetime' => time(),
'order_id' => $out_trade_no,
'money' => $amount,
'type' => 1,
'status' => 1,
'other' => json_encode(['user_id' => $userbId, 'money' => $amount]),
'user_id' => $userId
];
$res = $order->addOne($insertData);
if(!$res) {
$this->error('订单提交错误');
}
//订单标题
$title = 'FastAdmin测试订单';
//其他
$type = 'wechat';
$method = 'miniapp';
//回调链接
$notifyurl = 'http://school.t.brotop.cn/api/Common/payNotify';
$returnurl = $this->request->root(true) . '/addons/epay/index/returnx/paytype/' . $type . '/out_trade_no/' . $out_trade_no;
//订单号
$params = [
'amount' => $amount,
'orderid' => $out_trade_no,
'type' => $type,
'title' => $title,
'notifyurl' => $notifyurl,
'returnurl' => $returnurl,
'method' => $method,
'openid' => $openid,
'auth_code' => uniqid()
];
$this->success('申请支付', json_decode(Service::submitOrder($params), true));
}
/**
* 获取价目表
* @ApiTitle (获取价目表)
* @ApiSummary (获取价目表)
* @ApiMethod (POST)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取价目表成功",
"time": "1586398313",
"data": [
{
"id": 1,
"price": 1,
"weigh": 0,
"createtime": 0,
"updatetime": 0,
"deletetime": null,
"show_switch": 1
}
]
})
*/
public function getPriceList()
{
$price = new Price();
$priceList = $price->listAll();
$this->success('获取价目表成功', $priceList);
}
}