Config.php
19.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
<?php
namespace app\api\controller;
use app\common\controller\Api;
use EasyWeChat\Foundation\Application;
use think\Db;
use function fast\e;
/**
* Config接口
*/
class Config extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* Config接口
* @ApiTitle (热门搜索)
* @ApiSummary (热门搜索)
* @ApiMethod (POST)
* @ApiRoute (/api/Config/HotSoConfig)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": [
{
"id": 2,
"title": "华斯无锡点"
}
]
})
*/
public function HotSoConfig()
{
$Array = [];
$Array = Db::name('hot_so')->order('weigh desc')->field('id,title')->select();
$this->success('成功', $Array);
}
/**
* Config接口
* @ApiTitle (平台服务)
* @ApiSummary (平台服务)
* @ApiMethod (POST)
* @ApiRoute (/api/Config/Open)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": "平台服务" //富文本
})
*/
public function Open()
{
$Array = Db::name('open')->where('id', 1)->find();
$this->success('成功', $Array['content']);
}
/**
* Config接口
* @ApiTitle (客服电话)
* @ApiSummary (客服电话)
* @ApiMethod (POST)
* @ApiRoute (/api/Config/KefuConfig)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": "13292442918" //客服电话
})
*/
public function KefuConfig()
{
$Array = Db::name('kefu')->where('id', 1)->find();
$Array['image'] = $this->ImgUrl($Array['image']);
$this->success('成功', $Array);
}
/**
* Config接口
* @ApiTitle (礼物)
* @ApiSummary (礼物)
* @ApiMethod (POST)
* @ApiRoute (/api/Config/Gift)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": [
{
"Id": 2,
"Image": "http://www.obituaries.com/uploads/20201212/eaea75b1acab02914d319e7ba932f5ce.png",
"Title": "金元宝"
},
{
"Id": 1,
"Image": "http://www.obituaries.com/uploads/20201212/eaea75b1acab02914d319e7ba932f5ce.png",
"Title": "鲜花"
}
]
})
*/
public function Gift()
{
$Array = Db::name('gift')->order('weigh desc')->select();
if (empty($Array)) {
$List = [];
} else {
foreach ($Array as $k => $v) {
$List[$k]['Id'] = $v['id'];
$List[$k]['Image'] = $this->ImgUrl($v['image']);
$List[$k]['Title'] = $v['title'];
}
}
$this->success('成功', $List);
}
/**
* Config接口
* @ApiTitle (送礼随机留言)
* @ApiSummary (送礼随机留言)
* @ApiMethod (POST)
* @ApiRoute (/api/Config/RandMessage)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"Content": "liuyan1111111111111111111111"
}
})
*/
public function RandMessage()
{
$Array = Db::name('gift_message')->select();
if (empty($Array)) {
$data = [
'Content' => ''
];
} else {
foreach ($Array as $k => $v) {
$Ids[] = $v['id'];
}
$List = Db::name('gift_message')->where('id', array_rand($Ids) + 1)->find();
$data = [
'Content' => $List['content']
];
}
$this->success('成功', $data);
}
/**
* Config接口
* @ApiTitle (用户转发讣告时调用/商户转发无需)
* @ApiSummary (用户转发讣告时调用/商户转发无需)
* @ApiMethod (POST)
* @ApiRoute (/api/Config/ForOb)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name="ob_id", type="int", required=true, description="讣告ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
}
})
*/
public function ForOb()
{
$UserId = $this->IsToken($this->request->header());
$Params = $this->request->param();
$IsFor = Db::name('for_ob')->where('user_id', $UserId)->where('ob_id', $Params['ob_id'])->find();
if (empty($IsFor)) {
$data = [
'user_id' => $UserId,
'ob_id' => $Params['ob_id'],
'createtime' => time()
];
$Res = Db::name('for_ob')->insert($data);
} else {
$Res = Db::name('for_ob')->where('id', $IsFor['id'])->update([
'createtime' => time()
]);
}
$this->Res($Res);
}
/**
* Config接口
* @ApiTitle (讣告详情送礼)
* @ApiSummary (讣告详情送礼)
* @ApiMethod (POST)
* @ApiRoute (/api/Config/GiveGift)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name="ob_id", type="int", required=true, description="讣告ID")
* @ApiParams (name="gift_id", type="int", required=true, description="礼物ID")
* @ApiParams (name="message", type="string", required=true, description="留言内容")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
}
})
*/
public function GiveGift()
{
$UserId = $this->IsToken($this->request->header());
$Params = $this->request->param();
$IsGive = Db::name('message')->where('user_id', $UserId)->where('ob_id', $Params['ob_id'])->where('type', 2)->find();
$ObInfo = Db::name('ob')->where('id', $Params['ob_id'])->find();
if (!empty($IsGive)) {
$this->error('只能送出一份礼物');
}
if ($ObInfo['user_id'] == '' || $ObInfo['user_id'] == null) {
$this->error('未获取发布讣告人信息');
}
$data = [
'user_id' => $UserId,
'ob_id' => $Params['ob_id'],
'type' => 2,
'touser_id' => $ObInfo['user_id'],
'gift_id' => $Params['gift_id'],
'message' => $Params['message'],
'createtime' => time()
];
$Res = Db::name('message')->insert($data);
$this->Res($Res);
}
/**
* 支付接口
* @ApiTitle (随礼支付)
* @ApiSummary (随礼支付)
* @ApiMethod (POST)
* @ApiRoute (/api/Config/WechaPay)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="money", type="integer", required=true, description="金额")
* @ApiParams (name="ob_id", type="integer", required=true, description="讣告ID")
* @ApiParams (name="name", type="integer", required=true, description="姓名")
* @ApiParams (name="mobile", type="integer", required=true, description="联系方式")
* @ApiParams (name="message", type="integer", required=true, description="备注")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
'data':{
})
*/
public function WechaPay()
{
$UserId = $this->IsToken($this->request->header());
$UserInfo = Db::name('user')->where('id', $UserId)->find();
$Params = $this->request->param();
$PayOrder = $this->PayOrder();
$domain = $this->request->domain();
//生成交易流水
$data = [
'PayOrder' => $PayOrder,
'status' => 0,
'user_id' => $UserId,
'money' => $Params['money'],
'ob_id' => $Params['ob_id'],
'name' => $Params['name'],
'mobile' => $Params['mobile'],
'message' => $Params['message'],
'createtime' => time(),
];
$InsertPayOrder = Db::name('pay_order')->insert($data);
if (!$InsertPayOrder) {
$this->error('支付订单生成失败', 0);
}
$data = [
'amount' => $Params['money'],
'orderid' => $PayOrder,
'type' => "wechat",
'title' => "白事随礼",
'notifyurl' => $domain . "/api/config/AgreementPayNotify/paytype/wechat",
'method' => "mp",
'openid' => $UserInfo['openid']
];
$return = \addons\epay\library\Service::submitOrder($data);
echo $return;
}
/**
* 订单接口
* @ApiTitle (支付回调)
* @ApiSummary (支付回调)
* @ApiMethod (POST)
* @ApiRoute (/api/Pay/Notify)
* @ApiParams (name="paytype", type="string", required=true, description="")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function AgreementPayNotify()
{
$paytype = $this->request->param('paytype');
$pay = \addons\epay\library\Service::checkNotify($paytype);
if (!$pay) {
echo '签名错误';
die;
}
$data = $pay->verify();
try {
$payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
//$data['out_trade_no'] 支付单号
$order_sn = $data['out_trade_no'];
$order = Db::name('pay_order')->where('PayOrder', $order_sn)->find();
if ($order['status'] == 1) {
return $pay->success('支付成功');
die;
}
//在此编写订单逻辑
//修改支付订单状态
$UpdateStatus = Db::name('pay_order')->where('PayOrder', $data['out_trade_no'])->update(
[
'status' => 1,
'pay_time' => time(),
'WeChatOrder' => $data['transaction_id']
]
);
if (!$UpdateStatus) {
echo('修改支付订单状态失败');
die;
}
$PayOrderInfo = Db::name('pay_order')->where('PayOrder', $data['out_trade_no'])->find();
$UserId = Db::name('ob')->where('id', $PayOrderInfo['ob_id'])->value('user_id');
//添加收益记录
$PriceAddData = [
'user_id' => $PayOrderInfo['user_id'],
'touser_id' => $UserId,
'ob_id' => $PayOrderInfo['ob_id'],
'name' => $PayOrderInfo['name'],
'mobile' => $PayOrderInfo['mobile'],
'money' => $PayOrderInfo['money'],
'message' => $PayOrderInfo['message'],
'createtime' => time(),
];
$IsPriceAddData = Db::name('price_list')->insert($PriceAddData);
if (!$IsPriceAddData) {
echo('添加收益记录失败');
die;
}
//增加钱包余额
$UserAddMoney = Db::name('user')->where('id', $UserId)->value('money');
$AddUserMoney = Db::name('user')->where('id', $UserId)->update(
[
'money' => $UserAddMoney + $PayOrderInfo['money']
]
);
if (!$AddUserMoney) {
echo('增加用户钱包余额失败');
die;
}
//增加随礼message
$MessageData = [
'user_id' => $PayOrderInfo['user_id'],
'touser_id' => $UserId,
'type' => 3,
'ob_id' => $PayOrderInfo['ob_id'],
'name' => $PayOrderInfo['name'],
'mobile' => $PayOrderInfo['mobile'],
'money' => $PayOrderInfo['money'],
'content' => $PayOrderInfo['message'],
'createtime' => time(),
];
$AddMessage = Db::name('message')->insert($MessageData);
if (!$AddMessage) {
echo('增加用户钱包余额失败');
die;
}
} catch (Exception $e) {
}
echo $pay->success('支付成功');
}
/**
* 支付接口
* @ApiTitle (我的钱包)
* @ApiSummary (我的钱包)
* @ApiMethod (POST)
* @ApiRoute (/api/Config/MyMoneyBad)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"Money": "111.00", //余额
"Content": "<p>12121212</p>", //提现规则 富文本
"SmallMoney": "1.00" //最小提现
}
})
*/
public function MyMoneyBad()
{
$UserId = $this->IsToken($this->request->header());
$Money = Db::name('user')->where('id', $UserId)->value('money');
$Content = Db::name('tixian_content')->where('id', 1)->value('content');
$SmallMoney = Db::name('tixian_content')->where('id', 1)->value('money');
$data = [
'Money' => $Money,
'Content' => $Content,
'SmallMoney' => $SmallMoney
];
$this->success('成功', $data);
}
/**
* Config接口
* @ApiTitle (绑定讣告)
* @ApiSummary (绑定讣告)
* @ApiMethod (POST)
* @ApiRoute (/api/Config/BindOb)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name="ob_id", type="int", required=true, description="讣告ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
}
})
*/
public function BindOb()
{
$Headers = $this->request->header();
$Params = $this->request->param();
if (!empty($Headers['authorization'])) {
$UserId = Db::name('user')->where('token', $Headers['authorization'])->value('id');
if (!empty($UserId)) {
$ObUser = Db::name('ob')->where('id', $Params['ob_id'])->value('user_id');
if (empty($ObUser) || $ObUser == '' || $ObUser == null) {
$res = Db::name('ob')->where('id', $Params['ob_id'])->update(
[
'user_id' => $UserId,
'round_type' => 1,
'updatetime' => time()
]
);
//添加客户
$ObInfo = Db::name('ob')->where('id', $Params['ob_id'])->find();
$IsBusiness = Db::name('business')->where('seller_id', $ObInfo['seller_id'])->where('user_id', $ObInfo['user_id'])->find();
if (empty($IsBusiness)) {
$DataDusiness = [
'seller_id' => $ObInfo['seller_id'],
'user_id' => $ObInfo['user_id'],
'createtime' => time()
];
Db::name('business')->insert($DataDusiness);
}
if (!$res) {
$this->error('绑定失败', 0);
}
}
}
}
$this->success('成功', 1);
}
/**
* Config接口
* @ApiTitle (发布讣告)
* @ApiSummary (发布讣告)
* @ApiMethod (POST)
* @ApiRoute (/api/Config/SendOb)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name="ob_id", type="int", required=true, description="讣告ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
}
})
*/
public function SendOb()
{
$SellerId = $this->IsTokenSeller($this->request->header());
$Params = $this->request->param();
$res = Db::name('ob')->where('id', $Params['ob_id'])->where('seller_id', $SellerId)->update(
[
'on' => 1,
'updatetime' => time()
]
);
$this->Res($res);
}
/**
* 首页接口
* @ApiTitle (提现)
* @ApiSummary (提现)
* @ApiMethod (POST)
* @ApiRoute (/api/Config/OutMoney)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name="money", type="int", required=true, description="提现金额")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
})
*/
public function OutMoney()
{
$UserId = $this->IsToken($this->request->header());
$SmallMoney = Db::name('tixian_content')->where('id', 1)->value('money');
$Params = $this->request->param();
if ($Params['money'] < $SmallMoney) {
$this->error('提现金额不满足最小提现金额', 0);
}
//更改用户余额
$UserMoney = Db::name('user')->where('id', $UserId)->value('money');
if ($UserMoney < $Params['money']) {
$this->error('余额不足', 0);
}
$res = Db::name('user')->where('id', $UserId)->update(
[
'money' => $UserMoney - $Params['money']
]
);
if (!$res) {
$this->error('余额减少失败', 0);
}
//添加提现记录
$data = [
'user_id' => $UserId,
'money' => $Params['money'],
'status' => 0,
'MoneyBad' => $UserMoney - $Params['money'],
'createtime' => time(),
'updatetime' => time()
];
$Res = Db::name('tixian')->insert($data);
$this->Res($Res);
}
}