Update.php
38.0 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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use function fast\e;
use function Qiniu\setWithoutEmpty;
/**
* 改版接口
*/
class Update extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = '*';
/**
* 改版接口
* @ApiTitle (token换UserId)
* @ApiSummary (token换UserId)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/TokenToUser)
* @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": 29 用户UserID
})
*/
public function TokenToUser()
{
$UserId = $this->is_token($this->request->header());
$this->success('成功', $UserId);
}
/**
* 改版接口
* @ApiTitle (被邀请页)
* @ApiSummary (被邀请页)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/InviteHtml)
* @ApiParams (name="user_id", type="int", required=true, description="用户UserID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"Nickname": "允安",
"Avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/PiajxSqBRaEKRz8aJsbiaEwSkCamJBVEx05Y9IHhic7qpd5AK7uQJv8fia6QPXnCBaTFpXxF0Epml7u8K1TybnSwVA/132"
}
})
*/
public function InviteHtml()
{
$UserId = input('user_id');
$Info = Db::name('user')->where('id', $UserId)->find();
if (empty($Info)) {
$this->error('网络异常', 0);
}
$this->success('成功', ['Nickname' => $Info['nickname'], 'Avatar' => $Info['avatar']]);
}
/**
* 改版接口
* @ApiTitle (支付后分享内容)
* @ApiSummary (支付后分享内容)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/AfterPayWindow)
* @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": {
"title": "点击领取榴莲味儿的鸡蛋仔送你的免费能量测试及健康礼券",
"image": "http://xm-public.xyslife.com/life2c/20210106/FmpUPCk0MZAmKJ-LHaKzNwvCdhJk.jpg"
}
}
})
*/
public function AfterPayWindow()
{
$UserId = $this->is_token($this->request->header());
$UserInfo = Db::name('user')->where('id', $UserId)->find();
$Info = Db::name('pay_miniappfriends')->find();
$this->success('成功', ['title' => '点击领取' . $UserInfo['nickname'] . '送你的' . $Info['title'], 'image' => cdnurl($Info['image'])]);
}
/**
* 改版接口
* @ApiTitle (氧气泡泡使用规则)
* @ApiSummary (氧气泡泡使用规则)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/WaterOOGroup)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"id": 1,
"content": "<p><span style=\"color: rgb(255, 192, 0);\"><strong>使用条件:</strong></span></p><ol class=\" list-paddingleft-2\" style=\"list-style-type: decimal;\"><li><p>订单金额≥199元</p></li><li><p>氧气泡泡≥100元</p></li></ol><p> 氧气泡泡支付不得超过每笔订单应付金额的20%<br/></p><p><br/></p><p><span style=\"color: rgb(255, 192, 0);\"><strong>使用数量</strong></span></p><p> 1.100氧气泡泡=1元<br/></p><p> 2.可兑换到分位,例如102氧气泡泡=1.02元<br/></p>"
}
}
})
*/
public function WaterOOGroup()
{
$Info = Db::name('warter_content')->find();
$this->success('成功', $Info);
}
/**
* 改版接口
* @ApiTitle (用户通过分享获取一张优惠券)
* @ApiSummary (用户通过分享获取一张优惠券)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/InserUserTick)
* @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':'返回成功',
}
})
*/
public function InserUserTick()
{
$UserId = $this->is_token($this->request->header());
$IsOrder = Db::name('order')->where('user_id', $UserId)->find();
if (empty($IsOrder)) {
$TickInfo = Db::name('tick')->where('status', 2)->find();
$data = [
'user_id' => $UserId,
'tick_id' => $TickInfo['id'],
'exp_time' => time() + $TickInfo['you_time'] * 86400,
'createtime' => time(),
'updatetime' => time(),
'status' => 0,
];
Db::name('user_tick')->insert($data);
}
$this->success('成功', 1);
}
/**
* 改版接口
* @ApiTitle (下单选择优惠券页面)
* @ApiSummary (下单选择优惠券页面)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/ThinkUserTick)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="status", type="int", required=true, description="0=可用优惠券,2=不可用优惠券")
* @ApiParams (name="total", 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':'返回成功',
"data": [
{
"id": 1, //优惠券ID
"title": "好友邀请优惠券",
"door": 100, //门槛金额
"del_price": "30.00", //优惠金额
"exp_time": "2021-02-22 13:35:22—2021-03-24 13:35:22"//有效期
}
]
}
})
*/
public function ThinkUserTick()
{
$UserId = $this->is_token($this->request->header());
$Status = input('status');
$Total = input('total');
// if (($Status == 0 && $Total < 199) || ($Status == 2 && $Total > 198.99)) {
// $this->success('成功', []);
// } else {
$TickArray = Db::name('user_tick')->where('user_id', $UserId)->where('status', 0)->select();
// }
$List = [];
if (!empty($TickArray)) {
foreach ($TickArray as $k => $v) {
$data[$k]['id'] = $v['id'];
$data[$k]['title'] = Db::name('tick')->where('id', $v['tick_id'])->value('title');
$data[$k]['door'] = Db::name('tick')->where('id', $v['tick_id'])->value('door');
$data[$k]['del_price'] = Db::name('tick')->where('id', $v['tick_id'])->value('del_price');
$data[$k]['exp_time'] = date('Y-m-d', $v['createtime']) . '—' . date('Y-m-d', $v['exp_time']);
}
foreach ($data as $k=>$v){
if($Status==0){
//查询可用
if($Total>$v['door']||$Total==$v['door']){
$List[$k]=$v;
}
}else{
//查询不可用
if($Total<$v['door']){
$List[$k]=$v;
}
}
}
}
$this->success('成功', array_values($List));
}
/**
* 改版接口
* @ApiTitle (订单页计算)
* @ApiSummary (订单页计算)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/OrderPages)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="address_id", type="int", required=true, description="地址ID")
* @ApiParams (name="total", type="int", required=true, description="总价")
* @ApiParams (name="tick_id", type="int", required=true, description="优惠券id")
* @ApiParams (name="tick", type="int", required=true, description="1=使用优惠,0=不使用优惠")
* @ApiParams (name="water", type="int", required=true, description="1=使用氧气泡泡,0=不适用氧气泡泡")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"Tick": "30.00", //优惠券优惠金额
"WaterNum": 100000, //拥有氧气泡泡
"Total": "200", //商品金额
"YunPrice": "11.00", //运费
"HappyPrice": 70, //优惠
"NewTotal": 141 //实付
}
}
})
*/
public function OrderPages()
{
$UserId = $this->is_token($this->request->header());
$Parmas = $this->request->param();
//检测过期优惠券
$this->ExpTick($UserId);
$Tick = 0;
$TickID = 0;
$Water = 0;
$YunPrice = 0;
if($Parmas['tick_id']!=0){
$UserTickArray = Db::name('user_tick')
->alias('a')
->where('a.id',$Parmas['tick_id'])
->where('user_id', $UserId)
->where('a.status', 0)
->join('tick t', 't.id=a.tick_id')
->field('a.id,t.door,t.del_price')
->find();
$Tick=$UserTickArray['del_price'];
$TickID=$UserTickArray['id'];
}else{
if ($Parmas['tick'] == 1) {
//选择最优 优惠券
//查询用户所有优惠券
$UserTickArray = Db::name('user_tick')
->alias('a')
->where('user_id', $UserId)
->where('a.status', 0)
->join('tick t', 't.id=a.tick_id')
->field('a.id,t.door,t.del_price')
->select();
if (!empty($UserTickArray)) {
$NewUserTickArray = [];
foreach ($UserTickArray as $key => $v) {
$NewUserTickArray[$key]['door'] = $v['door'];
}
array_multisort($NewUserTickArray, SORT_DESC, $UserTickArray);//SORT_DESC为降序,SORT_ASC为升序
foreach ($UserTickArray as $k => $v) {
if ($Parmas['total'] > $v['door'] || $Parmas['total'] == $v['door']) {
$Tick = $v['del_price'];
$TickID=$v['id'];
break;
}
}
}
}
}
$WaterNum = Db::name('user')->where('id', $UserId)->value('num');
if ($Parmas['water'] == 1) {
if ($Parmas['total'] < 199) {
$this->error('订单金额小于199元,无法抵扣');
}
if ($WaterNum < 100) {
$this->error('氧气泡泡不足100,无法抵扣');
}
//计算总价20%
if (($WaterNum / 100 > $Parmas['total'] * 0.2) || ($WaterNum / 100 == $Parmas['total'] * 0.2)) {
//大于或等于
$Water = $Parmas['total'] * 0.2;
} else {
//小于
$Water = $WaterNum / 100;
}
}
//运费
$City = Db::name('address')->where('id', $Parmas['address_id'])->value('city');
if (empty($City)) {
$this->error('获取用户地区失败');
}
$Area = explode('/', $City);
$AreaId = Db::name('area')->where('name', $Area[0])->value('id');
$map[] = ['exp', Db::raw("FIND_IN_SET($AreaId,area_ids)")];
$YunArray = Db::name('freight_model')->find();
$YunModel = Db::name('freight_model')->where($map)->find();
if (!empty($YunModel)) {
$YunPrice = $YunArray['price'];
}
$NewTotal = round($Parmas['total'], 2) - round($Tick, 2) - round($Water, 2) + round($YunPrice, 2);
$this->success('成功', [
//优惠券ID
'TickID' => $TickID,
//优惠券优惠金额
'Tick' => $Tick,
//拥有氧气泡泡
'WaterNum' => $WaterNum,
//商品金额
'Total' => $Parmas['total'],
//运费
'YunPrice' => $YunPrice == 0 ? '免运费' : $YunPrice,
//优惠
'HappyPrice' => floatval(sprintf("%.2f", round($Tick + $Water, 2))),
//实付
'NewTotal' => floatval(sprintf("%.2f", round($NewTotal, 2)))
]);
}
/**
* 改版接口
* @ApiTitle (商城购物车优惠计算)
* @ApiSummary (商城购物车优惠计算)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/ShopPages)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="total", 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':'返回成功',
"data": {
"Tick": "30.00", //优惠券优惠金额
"WaterNum": 100000, //拥有氧气泡泡
"Total": "200", //商品金额
"YunPrice": "11.00", //运费
"HappyPrice": 70, //优惠
"NewTotal": 141 //实付
}
}
})
*/
public function ShopPages()
{
$UserId = $this->is_token($this->request->header());
$Parmas = $this->request->param();
//检测过期优惠券
$this->ExpTick($UserId);
$Tick = 0;
//选择最优 优惠券
//查询用户所有优惠券
$UserTickArray = Db::name('user_tick')
->alias('a')
->where('user_id', $UserId)
->where('a.status', 0)
->join('tick t', 't.id=a.tick_id')
->field('a.id,t.door,t.del_price')
->select();
if (!empty($UserTickArray)) {
$NewUserTickArray = [];
foreach ($UserTickArray as $key => $v) {
$NewUserTickArray[$key]['door'] = $v['door'];
}
array_multisort($NewUserTickArray, SORT_DESC, $UserTickArray);//SORT_DESC为降序,SORT_ASC为升序
foreach ($UserTickArray as $k => $v) {
if ($Parmas['total'] > $v['door'] || $Parmas['total'] == $v['door']) {
$Tick = $v['del_price'];
break;
}
}
}
$NewTotal = $Parmas['total'] - $Tick;
$this->success('成功', [
//优惠券优惠金额
'Tick' => $Tick,
//商品金额
'Total' => $Parmas['total'],
//实付
'NewTotal' => $NewTotal
]);
}
/**
* 改版接口
* @ApiTitle (历史档案)
* @ApiSummary (历史档案)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/HistoryPages)
* @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": [
{
"id": 131, //报告id
"current_innate": "火+水能主导", //能量
"createtime": "2021-01-26", //时间
"goods_num": 6, //推荐产品数量
"nickname": "允安" //用户昵称
}
]
}
})
*/
public function HistoryPages()
{
$UserId = $this->is_token($this->request->header());
$NickName = Db::name('user')->where('id', $UserId)->value('nickname');
$Info = Db::name('sleep')
->where('user_id', $UserId)
->where('type', 1)
->order('id desc')
->field('id,current_innate,createtime,goods_num')
->select();
$List = [];
if (!empty($Info)) {
foreach ($Info as $k => $v) {
$List[$k]['id'] = $v['id'];
$List[$k]['current_innate'] = $v['current_innate'];
$List[$k]['createtime'] = date('Y-m-d', $v['createtime']);
$List[$k]['goods_num'] = $v['goods_num'];
$List[$k]['nickname'] = $NickName;
}
}
$this->success('成功', $List);
}
/**
* 改版接口
* @ApiTitle (用户积分)
* @ApiSummary (用户积分)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/UserNum)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="pages", type="int", required=true, description="pages")
* @ApiParams (name="rows", type="int", required=true, description="rows")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"Count": 7, //数据总数
"UserNum": 2300, //用户可用积分
"List": [
{
"id": 53, //id
"status": 0, //类型:0=减少,1=增加
"type": 3, //分类:1=首次测试奖励,2=邀请好友奖励,3=分销佣金扣除,4=自购返现扣除,5=首单奖励,6=升级奖励,7=关注奖励,8=绑定奖励,9=好友下单奖励,10=下单奖励,11=下单抵扣
"num": 0, 积分明细
"up_num": 2300, //剩余积分
"createtime": "2021-01-18" //发生时间
}
]
}
}
})
*/
public function UserNum()
{
$UserId = $this->is_token($this->request->header());
$Params = $this->request->param();
$Info = Db::name('num')->where('user_id', $UserId)->order('id desc')->select();
$UserNum = Db::name('user')->where('id', $UserId)->value('num');
$List = [
'Count' => count($Info),
'UserNum' => $UserNum,
'List' => []
];
if (!empty($Info)) {
foreach ($Info as $k => $v) {
$List['List'][$k]['id'] = $v['id'];
$List['List'][$k]['status'] = $v['status'];
$List['List'][$k]['type'] = $v['type'];
$List['List'][$k]['num'] = $v['num'];
$List['List'][$k]['up_num'] = $v['up_num'];
$List['List'][$k]['createtime'] = date('Y-m-d', $v['createtime']);
}
$List['List'] = $this->page_array($Params['rows'], $Params['pages'], $List['List'], 0);
}
$this->success('成功', $List);
}
/**
* 改版接口
* @ApiTitle (会员规则页小程序跳转page)
* @ApiSummary (用户积分)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/VipContentPage)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": "page/index"
})
*/
public function VipContentPage()
{
$Page = Db::name('vip_content_page')->value('page');
$this->success('成功', $Page);
}
/**
* 改版接口
* @ApiTitle (个人中心优惠券)
* @ApiSummary (个人中心优惠券)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/CenterTickNum)
* @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": [
{
"id": 2,
"title": "全员优惠",
"door": 1000, //门槛
"del_price": "10.00", //优惠金额
"exp_time": "2021-02-22 19:25:04—2021-03-24 19:25:04"
}
]
})
*/
public function CenterTickNum()
{
$UserId = $this->is_token($this->request->header());
$Info = Db::name('user_tick')->where('user_id', $UserId)->where('status', 0)->order('id desc')->select();
$List = [];
if (!empty($Info)) {
foreach ($Info as $k => $v) {
$List[$k]['id'] = $v['id'];
$List[$k]['title'] = Db::name('tick')->where('id', $v['tick_id'])->value('title');
$List[$k]['door'] = Db::name('tick')->where('id', $v['tick_id'])->value('door');
$List[$k]['del_price'] = Db::name('tick')->where('id', $v['tick_id'])->value('del_price');
$List[$k]['exp_time'] = date('Y-m-d H:i:s', $v['createtime']) . '—' . date('Y-m-d H:i:s', $v['exp_time']);
}
}
$this->success('成功', $List);
}
/**
* 改版接口
* @ApiTitle (提现页面)
* @ApiSummary (提现页面)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/TixianHtml)
* @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": "0.40", //可提现
"Recorded": 0.1, //待入账
"CountMoney": 0.1, //总收益
"MonthMyMoney": 0, //自购返现
"MonthDobueMoney": 0 //分佣收入
}
})
*/
public function TixianHtml()
{
$UserId = $this->is_token($this->request->header());
//本月起止时间戳
$start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
$end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
//累计总收入计算 $CountMoney
$CountMoney = $this->CountMoney($UserId, [], []);
//本月自购返现 $MonthMyMoney
$MonthMyMoneyMap['createtime'] = ['between', [$start_time, $end_time]];
$MonthMyMoneyType['type'] = ['EQ', 1];
$MonthMyMoney = $this->CountMoney($UserId, $MonthMyMoneyType, $MonthMyMoneyMap);
//本月分佣收入 $MonthDobueMoney
$MonthDobueMoneyMap['createtime'] = ['between', [$start_time, $end_time]];
$MonthDobueMoneyType['type'] = ['EQ', 2];
$MonthDobueMoney = $this->CountMoney($UserId, $MonthDobueMoneyType, $MonthDobueMoneyMap);
//待入账收入 $Recorded
$RecordedArray = Db::name('money')->where('status', 0)->select();
if (empty($RecordedArray)) {
$Recorded = 0;
} else {
foreach ($RecordedArray as $k => $v) {
$RecordedKong[] = $v['money'];
}
$Recorded = array_sum($RecordedKong);
}
//可提现余额 $Money
$Money = Db::name('user')->where('id', $UserId)->value('money');
$data = [
'Money' => $Money,
'Recorded' => $Recorded,
'CountMoney' => $CountMoney,
'MonthMyMoney' => $MonthMyMoney,
'MonthDobueMoney' => $MonthDobueMoney
];
$this->success('成功', $data);
}
/**
* 改版接口
* @ApiTitle (收益明细)
* @ApiSummary (收益明细)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/ShouyiCon)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="status", type="int", required=true, description="0=全部,1=自购返现,2=分销佣金")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": [
{
"id": 1, //id
"type": 2, //收入类型:1=自购返现,2=分销佣金
"money": "0.10", //收益
"createtime": "2021-01-18" //发生时间
}
]
})
*/
public function ShouyiCon()
{
$UserId = $this->is_token($this->request->header());
$Status = input('status');
$Map = [];
if ($Status != 0) {
$Map['type'] = ['EQ', $Status];
}
$List = [];
$Info = Db::name('money')->where('user_id', $UserId)->where($Map)->order('id desc')->select();
if (!empty($Info)) {
foreach ($Info as $k => $v) {
$List[$k]['id'] = $v['id'];
$List[$k]['type'] = $v['type'];
$List[$k]['money'] = $v['money'];
$List[$k]['createtime'] = date('Y-m-d', $v['createtime']);
}
}
$this->success('成功', $List);
}
/**
* 改版接口
* @ApiTitle (检测报告是否解锁)
* @ApiSummary (检测报告是否解锁)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/IsUserClock)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="sleep_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':1=已解锁,0=未解锁
})
*/
public function IsUserClock()
{
$UserId = $this->is_token($this->request->header());
$SleepId = input('sleep_id');
$Is = 0;
$Clock = Db::name('clock')->where('user_id', $UserId)->where('sleep_id', $SleepId)->find();
if (!empty($Clock)) {
$Is++;
}
$EXP = 0;
$IsClock = Db::name('clock_user')->where('user_id', $UserId)->where('sleep_id', $SleepId)->find();
if (empty($IsClock)) {
$EXP = 1;
} else {
if ($IsClock['exp_time'] > time()) {
$EXP = 1;
}
}
$this->success('成功', ['Is' => $Is, 'EXP' => $EXP]);
}
/**
* 改版接口
* @ApiTitle (创建解锁报告活动)
* @ApiSummary (创建解锁报告活动)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/CreateUserClock)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="sleep_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':1 // 活动ID 用于分享 拼接
})
*/
public function CreateUserClock()
{
$UserId = $this->is_token($this->request->header());
$SleepId = input('sleep_id');
$YesClock = Db::name('clock')->where('user_id', $UserId)->where('sleep_id', $SleepId)->find();
if (!empty($YesClock)) {
$this->error('已经解锁报告', 0);
}
$Clock = Db::name('clock_user')->where('user_id', $UserId)->where('sleep_id', $SleepId)->find();
if (!empty($Clock)) {
$this->error('不能重复创建助力', 0);
}
$data = [
'user_id' => $UserId,
'sleep_id' => $SleepId,
//初始化助力人数0
'num'=>0,
'exp_time' => time() + 60 * 60 * 2,
'createtime' => time()
];
Db::name('clock_user')->insert($data);
$ID = Db::name('clock_user')->where('user_id', $UserId)->where('sleep_id', $SleepId)->value('id');
$this->success('成功', $ID);
}
/**
* 改版接口
* @ApiTitle (助力解锁)
* @ApiSummary (助力解锁)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/HelpClock)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="clock_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':'返回成功',
})
*/
public function HelpClock()
{
$UserId = $this->is_token($this->request->header());
$ClockId = input('clock_id');
$ClockInfo = Db::name('clock_help')->where('clock_id', $ClockId)->where('user_id', $UserId)->find();
if (!empty($ClockInfo)) {
$this->error('禁止重复助力', 0);
}
$Clock = Db::name('clock_user')->where('id', $ClockId)->find();
if ($Clock['user_id'] == $UserId) {
$this->error('自己不可助力', 0);
}
$data = [
'user_id' => $UserId,
'clock_id' => $ClockId,
//初始化状态
'status'=>0,
'createtime' => time()
];
$Res = Db::name('clock_help')->insert($data);
//修改助力活动表 +1
Db::name('clock_user')->where('id', $ClockId)->update(['num'=>$Clock['num']+1]);
// $InserClock = Db::name('clock_help')->where('clock_id', $ClockId)->select();
if ($Clock['num']+1 == 3) {
$data = [
'user_id' => $Clock['user_id'],
'sleep_id' => $Clock['sleep_id'],
'createtime' => time()
];
Db::name('clock')->insert($data);
}
$this->Res($Res);
}
/**
* 改版接口
* @ApiTitle (解锁活动页面)
* @ApiSummary (解锁活动页面)
* @ApiMethod (POST)
* @ApiRoute (/api/Update/ClockHtml)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="clock_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": {
"IsCreateClockUser": 1, //访问页面人身份1=活动创建人 0=其他用户
"Avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLRMmfuE0lQj6HJ8Eq3wxJQeyNo71YkdLmlgfkPqwL2cA5ibr1ALURGib6VyDFt2EY4djI1Z7qnRwvA/132", //header 头像
"ExpTime": 7107, //剩余时间秒
"Long": "1/3", //助力进度
"HelpAvatar": [ //已助力 用户 头像 数组
{
"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/hewgZ0D8L4r91FRDhicuyWzLj5WZjeyhPNKAiathz3R9041OTqmxLBDrF3aP4fx5NQKt8iaKaWf0UYFRHW0yP26hQ/132"
}
]
}
//其他用户访问时
"data": {
"IsCreateClockUser": 0, //访问页面人身份1=活动创建人 0=其他用户
"OtherClock": 1, //当前用户对比这次助力活动 主力状态 1=已助力过,0=未助力过
"NickNameArray": [ //随机姓名
"舒",
"嘟嘟米",
"Yangwm",
"Bellaོ",
"Zeal fol You",
"Stella?",
"oyhm",
"行 Gou",
"小忙",
"在也不来",
"服软.",
"Mi Manchi",
"!!!!",
"好名字",
"允安"
]
}
})
*/
public function ClockHtml()
{
$UserId = $this->is_token($this->request->header());
$ClockId = input('clock_id');
$ClockInfo = Db::name('clock_user')->where('id', $ClockId)->find();
if (empty($ClockInfo)) {
$this->error('助力活动不存在', 0);
}
if ($ClockInfo['exp_time'] < time()) {
$this->error('助力活动已过期', 0);
}
//1=活动创建人 0=其他用户
$IsCreateClockUser = 0;
if ($UserId == $ClockInfo['user_id']) {
//活动创建人
$IsCreateClockUser++;
$HelpUserAvatar = Db::name('clock_help')->alias('a')->where('clock_id', $ClockId)->where(['status'=>0])->join('user u', 'u.id=a.user_id')->field('u.avatar,u.nickname')->select();
$data = [
'IsCreateClockUser' => $IsCreateClockUser,
'Avatar' => Db::name('user')->where('id', $UserId)->value('avatar'),
'ExpTime' => $ClockInfo['exp_time'] - time(),
'Long' => count($HelpUserAvatar) . '/' . '3',
'HelpAvatar' => $HelpUserAvatar,
];
} else {
//其他用户
$OtherClockUser = Db::name('clock_help')->where('user_id', $UserId)->where('clock_id', $ClockId)->find();
if (empty($OtherClockUser)) {
//没主力
$OtherClock = 0;
} else {
//助力
$OtherClock = 1;
}
$UserArray = Db::name('user')->field('nickname')->order('id desc')->page(1, 50)->select();
$NickNameArray = array_column($UserArray, 'nickname');
if(count($NickNameArray)<30){
$rand_list = array_rand($NickNameArray, count($NickNameArray));
}else{
$rand_list = array_rand($NickNameArray, 30);
}
foreach ($rand_list as $key) {
$RankArray[] = $NickNameArray[$key];
}
$data = [
'IsCreateClockUser' => $IsCreateClockUser,
'OtherClock' => $OtherClock, //1=已助力过,0=未助力过
'NickNameArray' => $RankArray
];
}
$this->success('成功', $data);
}
/**
* 订单接口
* @ApiTitle (创建解锁报告支付)
* @ApiSummary (创建解锁报告支付)
* @ApiMethod (POST)
* @ApiRoute (/api/Pay/ClockWechat)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="sleep_id", type="integer", 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':'返回成功'
})
*/
public function ClockWechat()
{
$UserId = $this->is_token($this->request->header());
$SleepId = input('sleep_id');
$Openid = Db::name('user')->where('id', $UserId)->value('openid');
//生成支付订单号
$PayOrder = $this->PayOrder();
//生成支付订单
$YesClock = Db::name('clock')->where('user_id', $UserId)->where('sleep_id', $SleepId)->find();
if (!empty($YesClock)) {
$this->error('已经解锁报告', 0);
}
$data = [
'PayOrder' => $PayOrder,
'status' => 0,
'user_id' => $UserId,
'money' => 19.9,
'createtime' => time(),
'updatetime' => time(),
'sleep_id' => $SleepId
];
$InsertPayOrder = Db::name('clock_pay')->insert($data);
if (!$InsertPayOrder) {
$this->error('支付订单生成失败', 0);
die;
}
$domain = $this->request->domain();
$data = [
'amount' => 19.9,
'orderid' => $PayOrder,
'type' => "wechat",
'title' => "会员开通",
'notifyurl' => $domain . "/api/Update/ClockWechatNotify/paytype/wechat",
'returnurl' => $domain . "/api/pay/baidu",
'method' => "miniapp",
'openid' => $Openid
];
$return = \addons\epay\library\Service::submitOrder($data);
echo $return;
}
/**
* 订单接口
* @ApiTitle (创建解锁报告支付回调)
* @ApiSummary (创建解锁报告支付回调)
* @ApiMethod (POST)
* @ApiRoute (/api/Pay/ClockWechatNotify)
* @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 ClockWechatNotify()
{
$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('clock_pay')->where('PayOrder', $data['out_trade_no'])->update(
[
'status' => 1,
'updatetime' => time(),
'WeChatOrder' => $data['transaction_id'],
'pay_time' => time()
]
);
$PayOrderInfo = Db::name('clock_pay')->where('PayOrder', $data['out_trade_no'])->find();
$data = [
'user_id' => $PayOrderInfo['user_id'],
'sleep_id' => $PayOrderInfo['sleep_id'],
'createtime' => time()
];
Db::name('clock')->insert($data);
} catch (Exception $e) {
}
echo $pay->success('支付成功');
}
}