Integral.php
50.7 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
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
<?php
/**
* tpshop
* ============================================================================
* 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* Author: IT宇宙人
* Date: 2015-09-09
*/
namespace app\mobile\controller;
use app\home\logic\UsersLogic;
use think\Cookie;
use Think\Db;
class integral extends MobileBase {
public $user_id = 0;
public $user = array();
public function __construct()
{
parent::__construct();
$this->cartLogic = new \app\home\logic\CartLogic();
if (session('?user')) {
$user = session('user');
$user = M('users')->where("user_id", $user['user_id'])->find();
session('user', $user); //覆盖session 中的 user
$this->user = $user;
$this->user_id = $user['user_id'];
$this->assign('user', $user); //存储用户信息
// 给用户计算会员价 登录前后不一样
if ($user) {
$user[discount] = (empty($user[discount])) ? 1 : $user[discount];
DB::execute("update `__PREFIX__cart` set member_goods_price = goods_price * {$user[discount]} where (user_id ={$user[user_id]} or session_id = '{$this->session_id}') and prom_type = 0");
}
}
//APP
$getylpres = getylapp_res(getMobileStoId(), '3');
if ($getylpres) {
$this->assign('ylpres', $getylpres);
}
/*--
$nologin = array(
'ajaxhtml', 'index', 'vip_qd', 'vip_bqd', 'updateoffintegral', 'coupon', 'send_coupon',
'integral_info', 'submit', 'find_pwd','coupon_pro','integral_sale',
);--*/
$nologin = array(
'integral_info', 'buy_points', 'goodsInfo',
);
if (!$this->user_id && !in_array(ACTION_NAME, $nologin)) {
$this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId())));
exit;
}
if (!in_array(ACTION_NAME, $nologin)) {
if (($this->pm_erpid && (!$user || !$user['erpvipid'])) || (empty($this->pm_erpid) && !$user || !$user['mobile'])) {
$this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId())));
exit;
}
}
}
//加载页面
public function ajaxhtml()
{
$user_id = $this->user_id;//会员ID
$qdlist = M('qd_config')->where(array('store_id' => getMobileStoId(), 'is_show' => 1))->find();//
if (empty($qdlist)) {
$this->assign('none', 1);
}
//后三条签到记录
$qdrecord1 = Db::query("select * from wxd_qd_record where store_id=" . getMobileStoId() . " and user_id=" . $user_id . " and DATEDIFF(FROM_UNIXTIME(billdate),CURDATE())<>0 order by billdate desc,id desc limit 2");
//判断今天有否签到
$today = M('qd_record')->where(" user_id=" . $user_id . " and store_id=" . getMobileStoId() . " and DATEDIFF(FROM_UNIXTIME(billdate),CURDATE())=0")->count();
$sday1 = date("m.d", strtotime("-2 day"));
$cday1 = 0;//上次获取积分
$sday2 = date("m.d", strtotime("-1 day"));
$sday3 = date("m.d", time());
if (!empty($qdrecord1)) {
$cday1 = $qdrecord1[0]['daynum'];
if (count($qdrecord1) == 2) {
$sday2 = date("m.d", $qdrecord1[0]['billdate']);
$sday1 = date("m.d", $qdrecord1[1]['billdate']);
} else {
$sday2 = date("m.d", $qdrecord1[0]['billdate']);
$sday1 = date("m.d", $qdrecord1[0]['billdate'] - 86400);
}
}
//当月签到记录
//$month=M('qd_record')->where(" user_id=".$user_id." and store_id=".getMobileStoId()." and date_format(FROM_UNIXTIME(billdate),'%Y-%m')=date_format(now(),'%Y-%m') ")->field("date_format(FROM_UNIXTIME(billdate),'%d') as day")->select();
$month = Db::query("SELECT GROUP_CONCAT(date_format(FROM_UNIXTIME(billdate),'%d') separator ',') as day FROM wxd_qd_record where user_id=" . $user_id . " and store_id=" . getMobileStoId() . " and date_format(FROM_UNIXTIME(billdate),'%Y-%m')=date_format(now(),'%Y-%m') ");
$month_1 = Db::query("SELECT GROUP_CONCAT(date_format(FROM_UNIXTIME(billdate),'%d') separator ',') as day FROM wxd_qd_record where user_id=" . $user_id . " and store_id=" . getMobileStoId() . " and date_format(FROM_UNIXTIME(billdate),'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m') ");
if (!empty($month)) {
$month = $month[0]['day'];
}
if (!empty($month_1)) {
$month_1 = $month_1[0]['day'];
}
//设置
$getcurnum = "0";
$getnextnum = "0";
$getqdnum = "0";
$getqdday = "0";
$daynum = 0;//获得积分
$ljnum = 0;
$lxnum = 0;
$lxnum1 = 0;
$getlxnum = 0;
$day = 1;
$getBQNum = 0;//补签
$max_bqday = 0;//多少天漏可补
$getbqnum = 0;//补签次数
$getybqnum = 0;//已补签次数
$getkbqnum = 0;//可补签次数
$getkbqnum1 = 0;//可补签次数
$getBQIntegral = 0;//当前补签积分
$getcurbqnum = 0;//当前补签取次数
$getBQIntegral1 = 0;//补签后积分
$list_score = 0; //页面第一排积分
$list_date = 0; //页面第一排日期
$list_score1 = 0; //签到成功排积分
$list_date1 = 0; //签到成功排日期
$qdintro = '';//签到成功说明
$curbqdaynum = '';//当前需补签天数
//明天起5天积分
$tdayc1 = 0;
$tdayc2 = 0;
$tdayc3 = 0;
$tdayc4 = 0;
$tdayc5 = 0;
$tdayc6 = 0;
$bqbutton = array(
'getbqintegral' => '',
'getbqnum2' => '',
'getbqintegral1' => '',
);
switch ($qdlist['typeid']) {
case "1":
$daynum = $qdlist['integralnum1'];
$qdintro = '恭喜您获得' . $daynum . '个积分';
$tdayc1 = $tdayc2 = $tdayc3 = $tdayc4 = $tdayc5 = $tdayc6 = $daynum;
break;
case "2":
$max_bqday = $qdlist['bqday']; //多少天后可补签
$getlxnum = $qdlist['daynum2']; //连续签到设置天数
$getbqnum = $qdlist['bqnum']; //补签次数,最高可设置3次
//date_sub(curdate(),interval 1 day)
$qdrecord = Db::query("select *,DATEDIFF(curdate(),FROM_UNIXTIME(billdate)) as xcday from wxd_qd_record where store_id=" . getMobileStoId() . " and user_id=" . $user_id . " order by billdate desc,id desc limit 1"); //获取最新一次签到记录
if ($qdrecord) {
$day = $qdrecord[0]['xcday']; //跟当天相差天数
$lxnum = $qdrecord[0]['lxnum']; //连续签到
$getkbqnum = $qdrecord[0]['bqnum']; //剩余补签次数
$getkbqnum1 = $getkbqnum;
$lxnum1 = $lxnum;
}
$score = ''; //往后5天各自对应积分(前台显示)
$star = $qdrecord[0]['lxnum'] == 0 ? $qdrecord[0]['lxnum'] + 1 : $qdrecord[0]['lxnum'];
//var_dump($star);
$k = 0;
for ($i = 1; $i < 6; $i++) {
if ($today == 1) //今天已签到
{
$k = ($qdrecord[0]['lxnum'] + $i) % $getlxnum;
} else {
$k = ($i + 1) % $getlxnum;
}
$k = $k == 0 ? $getlxnum : $k;
if ($i > 1) {
$score .= ',';
}
$score .= $qdlist['dayintegral' . $k];
}
if ($score) {
$arr = explode(",", $score);
$tdayc1 = $arr[0];
$tdayc2 = $arr[1];
$tdayc3 = $arr[2];
$tdayc4 = $arr[3];
$tdayc5 = $arr[4];
}
//当前时间和上一次签到相隔为1的话
if ($day == 1) {
if ($lxnum1 == $getlxnum) {
$lxnum = 1; //今天处于连续签到的第几天,为1表示今天是连续签到的第一天
} else {
$lxnum += 1;
}
} else {
if ($lxnum1 == $getlxnum) {
$lxnum = 1;
} else {
if ($day-1 <= $max_bqday) //前天签到昨天漏签,$day值为2
{
///可补签,$lxnum值为上一次签到的连续天数,补签天数=在此基础上加1
} else {
$lxnum = 1;
}
}
}
//可补签等于0次的话,重新计算
if ($day > 1 && $getkbqnum == 0) {
$lxnum = 1;
}
if ($day > 1 && $getbqnum > 0 && $getkbqnum > 0) {
$getcurbqnum = $getbqnum - $getkbqnum + 1;// 当前补签处于第几次补签
if ($getcurbqnum <= 0) {
$getcurbqnum = 1;
}
$getBQIntegral = $qdlist['bqintegral' . $getcurbqnum];//补签需扣的积分
$getBQIntegral1 = $qdlist['dayintegral' . ($lxnum + 1)];//补签后积分
}
//
if ($lxnum == 0) {
$lxnum = 1;
}
//今天未签到情况下,显示下面内容
$daynum = $qdlist['dayintegral' . $lxnum];
$qdintro = '恭喜您获得' . $daynum . '个积分';
if ($day == 1 || $day - 1 > $max_bqday || $getkbqnum < $day - 1) {
//不能补签(没有漏签、漏签天数超过最长补签天数、剩余补签次数小于需补签天数)
} else {
if ($day > 1) {
$getbqnum2 = $getkbqnum1 - 1;
$bqbutton = array(
'getbqintegral' => $getBQIntegral,
'getbqnum2' => $getbqnum2,
'getbqintegral1' => $getBQIntegral1,
);
for ($t = 1; $t < $day; $t++) {
if ($t > 1) {
$curbqdaynum .= ',';
}
$curbqdaynum .= date("d", strtotime("-" . $t . " day")); //需补签的日期号
}
}
//dump($curbqdaynum);
}
break;
case "3":
$ljnum = M('qd_record')->where(array('user_id' => $user_id, 'store_id' => getMobileStoId()))->order('billdate desc,id desc')->field('ljnum')->limit(1)->find();
$daynum = $qdlist['integralnum3'];
if (empty($ljnum)) {
$ljnum = 1;
} else {
$ljnum = $ljnum['ljnum'] + 1;
}
if ($ljnum == $qdlist['daynum3']) {
$ljnum = 0;
}
$qdintro = '累积签到' . $qdlist['daynum3'] . '天可获得' . $daynum . '个积分';
$tdayc1 = $tdayc2 = $tdayc3 = $tdayc4 = $tdayc5 = $tdayc6 = $daynum;
break;
}
//计算当前月份日期
$curday = date("t"); //当前月天数
$xingqi = Date("w", strtotime(Date("Y-n-1"))); //当月第一天周几 0123456——日一二……
$dayhtml = '<li>';
for ($k = $xingqi; $k > 0; $k--) //上个月记录
{
$kk = date("d", strtotime(date('Y-m-01', time())) - 3600 * 24 * $k);
if (strpos($month_1, (String)$kk) !== false) {
$dayhtml .= '<span style="color:#e3e3e3" class="true">' . $kk . '</span>';
} else if (strpos($curbqdaynum, (String)$kk) !== false && date('d') < 10) {
$dayhtml .= '<span style="color:#e3e3e3" class="false">' . $kk . '</span>';
} else {
$dayhtml .= '<span style="color:#e3e3e3">' . $kk . '</span>';
}
//$dayhtml.='<span style="color:#e3e3e3">'.$kk.'</span>';
}
for ($i = 1; $i <= $curday; $i++) //本月记录
{
if (strpos($month, ($i < 10 ? '0' . $i : (String)$i)) !== false) {
$dayhtml .= '<span class="true">' . $i . '</span>';
} else if (strpos($curbqdaynum, ($i < 10 ? '0' . $i : (String)$i)) !== false && $i < date('d')) {
$dayhtml .= '<span class="false">' . $i . '</span>';
} else {
$dayhtml .= '<span ';
if ($today == 0 && date('d') == $i) $dayhtml .= ' class="curr"';
$dayhtml .= '>' . $i . '</span>';
}
if (($i + $xingqi) % 7 == 0) {
$dayhtml .= '</li><li>';
}
}
$getcurnum = $daynum; //可获得积分
$result = array(
'getcurnum' => $getcurnum,
'getnextnum' => $getnextnum,
'getqdnum' => $getqdnum,
'getqdday' => $getqdday,
'daynum' => $daynum,
'ljnum' => $ljnum,
'lxnum' => $lxnum,
'lxnum1' => $lxnum1,
'getlxnum' => $getlxnum,
'day' => $day,
'getBQNum' => $getBQNum,
'max_bqday' => $max_bqday,
'getbqnum' => $getbqnum,
'getybqnum' => $getybqnum,
'getkbqnum' => $getkbqnum,
'getkbqnum1' => $getkbqnum1,
'getBQIntegral' => $getBQIntegral,
'getcurbqnum' => $getcurbqnum,
'getBQIntegral' => $getBQIntegral1,
'today' => $today,
'qdintro' => $qdintro,
'sday1' => $sday1,
'sday2' => $sday2,
'sday3' => $sday3,
'cday1' => $cday1,
'tdayc1' => $tdayc1,
'tdayc2' => $tdayc2,
'tdayc3' => $tdayc3,
'tdayc4' => $tdayc4,
'tdayc5' => $tdayc5,
'tdayc6' => $tdayc6,
'score' => $score,
'curbqdaynum' => $curbqdaynum,
);
//dump($bqbutton);
$this->assign('bqbutton', $bqbutton);
$this->assign('dayhtml', $dayhtml);
$this->assign('info', $qdlist);
$this->assign('result', $result);
upload_ylp_log('签到页面');
return $this->fetch('', getMobileStoId());
}
//积分签到
public function index()
{
//dump(mktime(0, 0, 0, date('m'), date('d')-2, date('Y'))); //前一天时间戳
return $this->fetch('', getMobileStoId());
}
//签到
public function vip_qd()
{
upload_ylp_log('会员签到');
$user_id = $this->user_id;//会员ID
$store_id = getMobileStoId();
$qdlist = M('qd_config')->where(array('store_id' => $store_id, 'is_show' => 1))->find();
$daynum = 0;//获得积分
$tomdaynum = 0;//明天签到积分
$ljnum = 0;
$lxnum = 0;
$getlxnum = 0;
$getbqnum = 0;
$getconfigsm = "";//配置说明
switch ($qdlist['typeid']) {
case "1": //每日
$daynum = $qdlist['integralnum1'];
$tomdaynum = $qdlist['integralnum1'];
$getconfigsm = "签到送积分(每日签到)";
break;
case "2": //连续
$getconfigsm = "签到送积分(连续签到)";
$getlxnum = $qdlist['daynum2'];
$getbqnum = $qdlist['bqnum'];
$day = 0;
$dts_date = Db::query("select *,DATEDIFF(CURDATE(),FROM_UNIXTIME(billdate))as xcday from wxd_qd_record where store_id=" . $store_id . " and user_id=" . $user_id . " order by billdate desc,id desc limit 1");
if (!empty($dts_date)) {
$timediff = time() - $dts_date[0]['billdate'];
//$days = intval($timediff/86400);
$day = $dts_date[0]['xcday'];
$getbqnum = $dts_date[0]['bqnum'];
$lxnum = $dts_date[0]['lxnum'];
}
if ($day == 1) {
if ($lxnum >= $getlxnum) {
$lxnum = 1;
$getbqnum = $qdlist['bqnum'];
} else {
$lxnum += 1;
}
} else {
$lxnum = 1;
$getbqnum = $qdlist['bqnum'];
}
if ($lxnum == 0) {
$lxnum = 1;
$getbqnum = $qdlist['bqnum'];
}
//return day + "," + getlxnum + "," + lxnum;
//
$daynum = $qdlist['dayintegral' . $lxnum];
if ($lxnum == $getlxnum) //当前签到天数已是连续最后一天,明天重新计算
{
$tomdaynum = $qdlist['dayintegral1'];
} else if ($lxnum < $getlxnum) {
$tomdaynum = $qdlist['dayintegral' . ($lxnum + 1)];
}
break;
case "3": //累积
$getconfigsm = "签到送积分(累积签到)";
$ljnum = M('qd_record')->where(array('user_id' => $user_id, 'store_id' => getMobileStoId()))->order('billdate desc,id desc')->field('ljnum')->limit(1)->find();
if (empty($ljnum)) {
$ljnum = 1;
} else {
$ljnum = $ljnum['ljnum'] + 1;
}
if ($ljnum >= $qdlist['daynum3']) {
$getconfigsm = "签到送积分(累积签到" . $ljnum . "天)";
$ljnum = 0;
$daynum = $qdlist['integralnum3'];
}
break;
}
try {
//判断今天有否签到
$today = M('qd_record')->where(" user_id=" . $user_id . " and store_id=" . $store_id . " and DATEDIFF(FROM_UNIXTIME(billdate),CURDATE())=0")->find();
if ($today) {
return json(['status' => 2, 'msg' => '今天已经签到']); //今天已签到
} else {
$strno = "qd" . date('Ymd'). $user_id.rand(100000, 999999); //"qd".date('YmdHis').rand(100000, 999999);
mlog("签到编号:" . $strno . "当前签到积分:" . $daynum . "类型:" . $qdlist['typeid'] . "配置:" . $getconfigsm, "qdgame/" . getMobileStoId());
$data = array(
"qdbh" => $strno,
"store_id" => getMobileStoId(),
"user_id" => $user_id,
"user_nickname" =>'' ,
"user_headimg" =>'',
"daynum" => $daynum,
"ljnum" => $ljnum,
"lxnum" => $lxnum,
"bqnum" => $getbqnum,
"qd_type" => $qdlist['typeid'],
"billdate" => time(),
);
$resultint = M('qd_record')->add($data);
/*--避免重复插入-*/
//$sql= one_insert("wxd_qd_record",$data,"user_id=" . $user_id . " and store_id=" . $store_id . " and DATEDIFF(FROM_UNIXTIME(billdate),CURDATE())=0");
//$resultint=Db::execute($sql);
if ($resultint) {
//线下加积分
if ($daynum) {
$result = $this->updateoffintegral($user_id, $daynum, $getconfigsm, $strno);
if ($result == 1) {
M('qd_record')->where("id=$resultint")->save(array('integerstate' => 1));
return json(['status' => 1, 'msg' => '签到成功']);
}
} else {
return json(['status' => 1, 'msg' => '签到成功']);
}
} else {
//M("qd_record")->where("id", $resultint)->delete();
return json(['status' => -1, 'msg' => '签到失败']);
}
}
} catch (HttpResponseException $exception) {
//return json(["code" => "-1", "msg" => "生成签名错误"]);
return json(['status' => 2, 'msg' => $exception->getResponse()]);
}
}
//补签到
public function vip_bqd()
{
// upload_ylp_log('会员补签');
$user_id = $this->user_id;//会员ID
$store_id = getMobileStoId();
$daynum = I('getbqintegral1');
$curbqnum = I('getbqnum2');
$bqintegral = I('getbqintegral');
$qdlist = M('qd_config')->where(array('store_id' => $store_id, 'is_show' => 1))->find();
$ljnum = 0;
$lxnum = 0;
$getlxnum = 0;
$lastrecord = Db::query("select * from wxd_qd_record where store_id=" . $store_id . " and user_id=" . $user_id . " and billdate<".time()." order by billdate desc,id desc limit 1");
if (!empty($lastrecord)) {
$lxnum = $lastrecord[0]['lxnum'] + 1;
$strno = "qd" . date('YmdHis') . rand(100000, 999999);
$data = array(
'qdbh' => $strno,
'store_id' => getMobileStoId(),
'user_id' => $user_id,
'user_nickname' => '',
'user_headimg' => '',
'daynum' => $daynum,
'ljnum' => $ljnum,
'lxnum' => $lxnum,
'billdate' => $lastrecord[0]["billdate"] + 86400,
'isbq' => 1,
'bqnum' => $curbqnum,
'qd_type' => $qdlist['typeid'],
);
$resultint = M('qd_record')->add($data);
$strno1 = "qd" . date('YmdHis') . rand(100000, 999999);
$data = array(
'qdbh' => $strno,
'store_id' => getMobileStoId(),
'user_id' => $user_id,
'user_nickname' => '',
'user_headimg' => '',
'daynum' => -$bqintegral,
'ljnum' => $ljnum,
'lxnum' => $lxnum,
'billdate' => $lastrecord[0]["billdate"]+ 86400,
'isbq' => 1,
'bqnum' => $curbqnum,
'qd_type' => $qdlist['typeid'],
);
$resultint1 = M('qd_record')->add($data);
if ($resultint && $resultint1) {
//补签扣积分
$result = $this->updateoffintegral($user_id, '-' . $bqintegral, '补签扣积分', $strno1);
//补签加积分
if ($result == 1) {
M('qd_record')->where(array("id"=>$resultint1))->save(array('integerstate' => 1));
$result = $this->updateoffintegral($user_id, $daynum, '补签加积分', $strno);
if ($result==1) {
M('qd_record')->where(array("id" => $resultint))->save(array('integerstate' => 1));
}
return json(['status' => 1, 'msg' => '补签成功']);
} else {
//M('qd_record')->where(array("id"=>$resultint1))->delete();
return json(['status' => -1, 'msg' => '补签失败1']);
}
} else {
//M('qd_record')->where(array("id"=>$resultint1))->delete();
return json(['status' => -1, 'msg' => '补签失败']);
}
}
}
//线下增减积分
public function updateoffintegral($user_id,$bqintegral,$remark,$strno)
{
$user=$this->user;
if ($this->pm_erpid)//有账套
{
/*--
$user['api_token'] = tpCache('shop_info.api_token', $user['store_id']);
$data = ['Id' => $user['erpvipid'],
'Integral' => $bqintegral,
'Remark' => $remark,
'Number' => $strno,
];
$res = getApiData("wxd.vip.addreduce", $user['api_token'], array($data,));--*/
$res=com_update_integral($this->pm_erpid,$user,$bqintegral,$remark,$module="integral/updateoffintegral",$strno);
if(!$res){
return -1;
}
return 1;//线下已执行(预防第一次插入线下返回错误即json_encode($res)=null,二次插入失败)
}else
{
accountLog($user["user_id"],0,$bqintegral,$remark,0,$user['store_id'],$user["pay_points"]);//线上表
return 1;
}
}
//优惠券
public function coupon()
{
$user_id = $this->user_id;//会员ID
$where1="type = 1 and store_id = " . getMobileStoId() . " and (sum_num=0 or (sum_num>0 and sum_num>use_sumnum)) and unix_timestamp(now()) >= send_start_time and send_end_time >= unix_timestamp(now())";
$coupon = M('coupon')->where($where1)->order('add_time desc')->select();
$coupon_count = M('coupon')->where($where1)->count();
$list = array();
if ($coupon) {
$i = 1;
foreach ($coupon as $val) {
if ($i % $coupon_count == 1) {
$val['color'] = "red";
} else if ($i % $coupon_count == 2) {
$val['color'] = "blue";
} else {
$val['color'] = "purple";
}
$list[] = $val;
$i += 1;
}
}
$this->assign('coupon', $list);
upload_ylp_log('优惠券列表');
return $this->fetch('', getMobileStoId());
}
public function send_coupon()
{
upload_ylp_log('领取优惠券');
$cid = I("post.cid");
$user_id = $this->user_id;//会员ID
if ($this->user_id == 0) {
$this->ajaxReturn(array('status' => -1, 'msg' => '未登录 !'));
}
$getstoid = getMobileStoId();
$coupon = M("coupon")->where(array('store_id' => $getstoid, 'id' => $cid))->find();
if (empty($coupon)) {
$this->ajaxReturn(array('status' => -1, 'msg' => '领取失败,优惠券不存在!'));
}
//判断是否大于0,控制总数量
if ($coupon['sum_num']) {
$use_sumcount = M('coupon_list')->where(array('store_id' => $getstoid, 'type' => 5, 'cid' => $cid))->count();
if ($use_sumcount >= $coupon['sum_num']) {
$this->ajaxReturn(array('status' => -1, 'msg' => '领取失败,该优惠券数量已领完!'));
}
}
if ($coupon["send_end_time"] < time()) {
$this->ajaxReturn(array('status' => -1, 'msg' => '领取失败,该优惠券已过期 !'));
}
$clres = M('coupon_list')->where(array('store_id' => $getstoid, 'type' => 5, 'cid' => $cid, 'uid' => $user_id))
->order('id desc')
->select();
//经验的开关
//$check = 0;
if ($clres) {
if (count($clres) >= $coupon['everyone_num'] && $coupon['everyone_num']) {
$this->ajaxReturn(array('status' => -1, 'msg' => '您已领完该券 !'));
}
//---时间间隔---
$interval_time = $coupon['interval_time'];
if ($interval_time) {
$time1 = strtotime("+" . $interval_time . " day", $clres[0]['send_time']);
if (time() < $time1)
$this->ajaxReturn(array('status' => -1,
'msg' => '您已领取过了,请过后在领 !'));
}
if ($coupon['everyone_num']) {
// 乐观锁机制,避免手机端,和pc端同时点击,造成冲突
$rs = M("coupon_list")->where("id", $clres[0]['id'])
->where(array('type' => 5, 'cid' => $cid, 'uid' => $user_id))
->where('get_num<' . ($coupon['everyone_num'] - 1))->setInc('get_num');
if (empty($rs)) {
$this->ajaxReturn(array('status' => -1, 'msg' => '您已领完该券 !'));
}
}
}
$userinfo = $this->user;
$CashRepNo = "1005" . date("ymdHis") . get_total_millisecond();
//更新总数
$update_coupon = M('coupon')->where(" store_id=".$getstoid." and id=".$cid." and ((sum_num>0 and sum_num>use_sumnum) or (sum_num=0))")->setInc('use_sumnum');
if (empty($update_coupon))
{
$this->ajaxReturn(array('status' => -1, 'msg' => '领取失败,该优惠券数量已领完!'));
}
//有账套 end
//插入线上优惠券领取表
$coupon_list['cid'] = $cid;
$coupon_list['type'] = 5;
$coupon_list['uid'] = $user_id;
$coupon_list['send_time'] = time();
$coupon_list['code'] = $CashRepNo;
$coupon_list['store_id'] = $getstoid;
//如果是按照有效期的运算
if ($coupon["endtype"] == 1) {
$coupon_list['begintime'] = time();
if ($coupon['days']) {
$days = $coupon['days'];
$time1 = strtotime("+" . $days . " day", time());
$coupon_list['validtime'] = strtotime(date('Y-m-d 23:59:59', $time1));
} else {
$coupon_list['validtime'] = 0;
}
} else {
$coupon_list['begintime'] = $coupon["use_start_time"];
$coupon_list['validtime'] = strtotime(date('Y-m-d 23:59:59', $coupon["use_end_time"]));
}
$coupon_list['sum'] = $coupon["money"];
$coupon_list['buysum'] = $coupon["condition"];
$coupon_list['remark'] = "免费发放";
$add_couponinfo = add_coupon($coupon_list, $userinfo, $getstoid);
$add_couponinfo = json_decode($add_couponinfo, true);
if ($add_couponinfo['code'] == 0) {
$this->ajaxReturn(array('status' => -1, 'msg' => '领取失败!'));
}
//有账套
if ($this->pm_erpid) {
$tk = tpCache("shop_info", getMobileStoId());
$data = array(
'CashRepNo' => $CashRepNo,//券号
'VIPId' => $userinfo["erpvipid"],//会员id
'Sum' => $coupon["money"],//金额
'SendMan' => '免费发放',//发放类型
'Operator' => '微信商城',//来源
'BuySum' => $coupon["condition"],//满多少才能使用
'Remark' => $coupon["name"] . '【消费满' . $coupon["condition"] . '元可用】',
);
if ($coupon['useobjecttype']) {
$data['UseObjectType'] = $coupon['useobjecttype'];
$data['UseObjectID'] = $coupon['useobjectid'];
$data['UseObjectNo'] = $coupon['useobjectno'];
$data['UseObjectName'] = $coupon['useobjectname'];
}
//如果是按照有效期的运算
if ($coupon["endtype"] == 1) {
$data['BeginDate'] = date('Y-m-d', time());//使用开始日期
if ($coupon['days']) {
$days = $coupon['days'];
$time1 = strtotime("+" . $days . " day", time());
$data['ValidDate'] = date('Y-m-d', $time1);
}
} else {
if ($coupon["use_start_time"] != "") {
$data['BeginDate'] = date('Y-m-d', $coupon["use_start_time"]);//使用开始日期
}
if ($coupon["use_end_time"] != "") {
$data['ValidDate'] = date('Y-m-d', $coupon["use_end_time"]);//使用结束日期
}
}
mlog(json_encode($data), "send_coupon/" . getMobileStoId());
$erp = tpCache("shop_info.ERPId", getMobileStoId());
$re1 = getApiData_java_p("/api/erp/vip/cash/insert", $erp, $data, null, null, null, "POST");
$add_rs = [$re1, "ok"];
if (!$add_rs[0]) {
$this->ajaxReturn(array('status' => -1, 'msg' => '服务器繁忙, 请联系管理员 !'));
}
$add_qlist = json_decode(urldecode($add_rs[0]), true);
if ($add_qlist['code'] != 0) {
$this->ajaxReturn(array('status' => -1, 'msg' => '领取失败!'));
}
}
$this->ajaxReturn(array('status' => 1, 'msg' => '领取成功!'));
}
//积分购
public function buy_points(){
$id=I("stoid");
$stype =I('type/d',1);
$dwup=I("dwup/d",0); //0降 1升
if($dwup) $dwup="asc";
else $dwup="desc";
//积分兑换广告
$getopgg=M('ad')->where(array('store_id'=>$id,'pid'=>501,'enabled'=>1,'start_time'=>array('elt',time()),'end_time'=>array('egt',time())))->order('orderby asc')->find();
if ($getopgg)
{
$getopgg_img=QCLOUD_IMGURL.$getopgg['ad_code'];
$this->assign('getopgg_img',$getopgg_img);
}
if(I('ispage'))
{
$now_time = time(); //当前时间
$where="";
$where=" and f.start_time<=".$now_time;
$count = M('integral_buy')
->alias('f')
->join('goods g','g.goods_id = f.goods_id','left')
->where("g.on_time<".$now_time." and (g.down_time>".$now_time." or g.down_time=0 or g.down_time='' or g.down_time is null)")
->where(" g.store_id=".$id." and g.is_on_sale=1 and f.is_show=1 and f.is_end=0 and f.end_time>".$now_time.$where)->count();
$p=I("p/d",1);
$pagesize = 10;//C('PAGESIZE'); //每页显示数
$first = $p*$pagesize;
switch ($stype)
{
case "1":$order="f.id ".$dwup;
break;
case "2":$order="f.addmoney ".$dwup;
break;
case "3":$order="f.order_num ".$dwup;
break;
case "4":$order="f.integral ".$dwup;
break;
}
$list =M('integral_buy')
->alias('f')
->join('goods g','g.goods_id = f.goods_id','left')
->where("g.on_time<".$now_time." and (g.down_time>".$now_time." or g.down_time=0 or g.down_time='' or g.down_time is null)")
->where(" g.store_id=".$id." and g.is_on_sale=1 and f.is_show=1 and f.is_end=0 and f.end_time>".$now_time.$where)
->order($order)
->limit($first.','.$pagesize)
->select();
$list1='';
if (empty($list))
{
$jsonlist['state']="0";
$jsonlist['msg']='无数据';
}
else
{
foreach ($list as $item) {
$item["original_img"]=getimg($item['original_img'],NOIMG,0,1);
$list1[]=$item;
}
$jsonlist['state']="1";
$jsonlist['msg']='成功';
}
$jsonlist['item']=$list1;
return json($jsonlist);
}
upload_ylp_log('积分购列表');
return $this->fetch('',getMobileStoId());
}
//积分购商品详情
public function integral_fun(){
$stoid=I('stoid/d',1);
C('TOKEN_ON', true);
// $user_id=cookie('user_id');
$goodsLogic = new \app\home\logic\GoodsLogic();
$goods_id = I("get.id");
$now0=time();
$where0 = [
'end_time' => ['>=', $now0],
'start_time' => ['<=', $now0],
'goods_id' => $goods_id,
'is_end'=>0,
'is_show'=>1
];
$rs0=M('integral_buy')->where($where0)->find();
if(empty($rs0)){
$this->redirect(U('Mobile/integral/buy_points', array('id' => $goods_id, 'stoid' => getMobileStoId())));
}
$this->assign('integral_buy',$rs0);
/*--商品--*/
$goods = M('Goods')->where("goods_id", $goods_id)->where('is_on_sale', 1)
->where("on_time<".$now0." and (down_time>".$now0." or down_time=0 or down_time='' or down_time is null)")
->field('goods_id,store_id,goods_name,brand_id,nation_id,cat_id,prom_type,market_price,store_count,shop_price,sales_sum,sku,prom_id,original_img,goods_sn,goods_spec,goods_color,on_time,REPLACE(REPLACE(goods_remark, CHAR(10),""), CHAR(13),"") as goods_remark,distr_type')->find();
if (empty($goods)) {
$this->error('此商品不存在或者已下架');
}
$this->buy_page_assign($goods['distr_type']);
$is_chat=tpCache("basic.is_chat",$stoid);
$rs_server=M('storage_recharge_detail')
->where('store_id',$stoid) ->where('admin_id<>0')
->where('end_time>'.$now0)
->find();
$this->assign('is_chat', $is_chat && $rs_server);
$this->assign('stoid', $stoid);
if ($goods['brand_id']) {
$brnad = M('brand')->where("id", $goods['brand_id'])->find();
$goods['brand_name'] = $brnad['name'];
}
if ($goods['nation_id']) {
$nation = M('nation')->where("id", $goods['nation_id'])->find();
$goods['nation_name'] = $nation['name'];
}
if ($goods['cat_id']) {
$cat = M('goods_category')->where("id", $goods['cat_id'])->find();
$goods['cat_name'] = $cat['name'];
}
//$goods_images_list = M('goods_images')->where("goods_id", $goods_id)->select(); // 商品 图册
$goods_images_list = M('GoodsImages')->where("goods_id", $goods_id)->order('ismain desc')->select(); // 商品 图册
$goods_videos = M('goods_videos')->where("goods_id", $goods_id)
->order('video_sort asc')->select(); // 视频
if($goods_videos[0])
$this->assign("goods_videos", $goods_videos);
/*------商品规格--------*/
$sp1 = $goods["goods_spec"];
$cn1 = $goods["goods_color"];
$guige1="规格";
$gorder1=1;$tgg1="";
if ($sp1 == "" && $cn1 == "") {
$tgg1 = $guige1.$gorder1;
$gorder1++;
} else if ($sp1 != "" && $cn1 == "") {
$tgg1 = $sp1;
} else if ($sp1 == "" && $cn1 != "") {
$tgg1 = $cn1;
} else {
$tgg1 = $sp1."/".$cn1;
}
$goods['guige']=$tgg1;
// $spec_goods_price = M('spec_goods_price')->where("goods_id", $goods_id)->getField("key,price,store_count"); // 规格 对应 价格 库存表
M('Goods')->where("goods_id=$goods_id")->save(array('click_count' => $goods['click_count'] + 1)); //统计点击数
$commentStatistics = $goodsLogic->commentStatistics($goods_id);// 获取某个商品的评论统计
// $this->assign('spec_goods_price', json_encode($spec_goods_price,true)); // 规格 对应 价格 库存表
$goods['sales_sum'] =$rs0['buy_num'];
/*------商品规格
$sp1 = $goods["goods_spec"];
$cn1 = $goods["goods_color"];
$guige1="规格";
if ($sp1 == "" && $cn1 == "") {
$tgg1 ="" ;
} else if ($sp1 != "" && $cn1 == "") {
$tgg2 = $sp1;
} else if ($sp1 == "" && $cn1 != "") {
$tgg1 = $cn1;
} else {
$tgg1 = $sp1."/".$cn1;
}--------*/
/*----选择门店-----*/
// $res1=M("storage_category")->where('store_id',$stoid)->cache("storage_category_".$stoid,TPSHOP_CACHE_TIME)->select();
// foreach ($res1 as $k1=>$v1){
// $result=M("pick_up")->where("category_id",$v1['cat_id'])->where('store_id',$stoid)
// ->where('isstop<>1')->select();
// $pkarray=get_arr_column($result,'pickup_id');
// if(empty($result)){
// unset($res1[$k1]);
// }else {
// $res1[$k1]['list'] =$result;
// }
// }
/*--当前价格--*/
// $curpirce= $ary['curprice'];
//商品限时抢购,商品特惠,团购
if($goods['prom_type'] >0) {
//所有活动判断
//$prom=$goods['flash_sale'] = get_goods_promotion($goods['goods_id'],$this->user_id);
$prom=$goods['flash_sale'] = get_goods_promotion1($goods,$rs0,$this->user_id);
if($goods['flash_sale']['is_end']!=1 && $goods['flash_sale']['is_end']!=4) {
//当前价格
$integral = $goods['flash_sale']['integral'];
$integral_name = $goods['flash_sale']['name'];
$addmoney = $goods['flash_sale']['addmoney'];
$limitvipqty=$goods['flash_sale']['buy_limit'];
$showlimte=$goods['flash_sale']['showlimit'];
$prom_goods = M('prom_goods')->where(['id' => $goods['prom_id'], 'is_close' => 0])->find();
$this->assign('prom_goods', $prom_goods);// 商品促销
$flash_sale = M('flash_sale')->where("id", $goods['prom_id'])->find();
$this->assign('flash_sale', $flash_sale);// 抢购
$goods['discount'] = round($goods['flash_sale']['price'] / $goods['shop_price'], 2) * 10;
$this->assign('onlybuy',$goods['flash_sale']['onlybuy']); //活动商品还可以买多少件
}else{
$goods['discount'] = round($goods['shop_price'] / $goods['market_price'], 2) * 10;
$goods['prom_type']=0;
}
}else{
$goods['discount'] = round($goods['shop_price'] / $goods['market_price'], 2) * 10;
}
//获取积分
$integ=get_userpoints($this->user,getMobileStoId(),$this->pm_erpid);
if ($integ)
{
$this->assign("integ",$integ);
if($rs0['integral']<=$integ || $rs0['integral']==0 ){
$this->assign("isinteg",1);
}
}else{
if($rs0['integral']==0 ){
$this->assign("isinteg",1);
}else{
$this->assign("integ",0);
$this->assign("integerr","获取积分失败");
}
}
//当前用户收藏
$user_id = $this->user_id;
$collect = M('goods_collect')->where(array("goods_id" => $goods_id, "user_id" => $user_id))->count();
$goods_collect_count = M('goods_collect')->where(array("goods_id" => $goods_id))->count(); //商品收藏数
$this->assign('collect', $collect);
$this->assign('commentStatistics', $commentStatistics);//评论概览
$this->assign('goods_images_list', $goods_images_list);//商品缩略图
$this->assign('goods', $goods);
$this->assign('goods_collect_count', $goods_collect_count); //商品收藏人数
$this->assign('collect', $collect); //是否收藏
$this->assign('integral',$integral);
$this->assign('integral_name',$integral_name);
$this->assign('addmoney',$addmoney);
$this->assign('limitvipqty',$limitvipqty);
$this->assign('showlimte',$showlimte);
$t=time();
$prom_order= M("prom_order")
->where("store_id",getMobileStoId())
->where("start_time<=".$t)
->where("end_time>=".$t)
->where("is_close=0")
->where('is_end',0)
->order(" id desc")->limit(1)->select();
$this->assign('prom_order', $prom_order);
//商品图片
$imgurl = getImg($goods['original_img'],curHostURL().NOIMG);
$msg = $this->img_curl_url($imgurl, 2);
$shareimg = $msg['data'];
$this->assign('shareimg',$shareimg);
//二维码也用64位
$shareurl=curHostURL().'/index.php/mobile/goods/goodsInfo/stoid/'.$stoid.'/id/'.$goods_id."/first_leader/".$this->user_id;
$this->assign('shareurl',$shareurl);
$qc = new \app\home\controller\Index();
$shareurl=$qc->qr_code_64($shareurl);
$this->assign('shareurlimg',$shareurl);
}
public function integral_info(){
$this->integral_fun();
return $this->fetch('', getMobileStoId());
}
//积分提交订单
public function submit(){
return $this->fetch('', getMobileStoId());
}
//优惠券详情
public function coupon_pro()
{
$user_id = $this->user_id;//会员ID
$id = I('id', 0);
$stoid=getMobileStoId();
$coupon = M('coupon')->where("type = 1 and store_id = " . getMobileStoId() . " and (sum_num=0 or (sum_num>0 and sum_num>use_sumnum)) and unix_timestamp(now()) > send_start_time and send_end_time > unix_timestamp(now()) and id=" . $id)->select(); //and id not in (select cid from wxd_coupon_list where type = 5 and uid = '.$user_id.' and store_id = ".getMobileStoId().")
/*
$gived=M('coupon_list')
->where("type = 5 and uid = '.$user_id.' and store_id = ".getMobileStoId()." and cid=".$id)
->order('id desc')
->select(); //是否已领取*/
$list = array();
if ($coupon) {
foreach ($coupon as $val) {
if ($val['use_start_time'] && $val['use_start_time'] != "0") {
$val['use_start_time'] = date('Y-m-d', $val['use_start_time']);
} else {
$val['use_start_time'] = "";
}
$list[] = $val;
}
$coupon2=$coupon[0]; $cid=$id; $err_text=null;
$use_sumcount = M('coupon_list')->where(array('store_id' => $stoid, 'type' => 5, 'cid' => $cid))->order('id desc')->select();
if (count($use_sumcount) >= $coupon2['sum_num'] && $coupon2['sum_num']) {
$err_text='该券已领完';
}
if(!$err_text){
//如果有领取过该券的话
$aa = M("coupon_list")->where('uid', $user_id)->where('cid', $cid)->order('id desc')
->field('begintime')
->select();
if ($aa) {
$everyone_num = $coupon2['everyone_num'];
if (count($aa) >= $everyone_num && $everyone_num) $err_text = "您已完该券";
$interval_time = $coupon2['interval_time'];
if ($interval_time && !$err_text) {
$time1 = strtotime("+" . $interval_time . " day", $use_sumcount[0]['send_time']);
if (time() < $time1) {
$err_text = '您已领过该券';
}
}
}
if ($coupon2["send_end_time"] < time() && !$err_text) {
$err_text = '优惠券已过期';
}
}
if($err_text) $this->assign("err_text",$err_text);
//$userinfo = $this->user;
}
//$this->assign('isgive',$gived);
$this->assign('coupon', $list);
return $this->fetch('', getMobileStoId());
}
public function get_quan_err(){
$user_id=$this->user['user_id'];
$cid=I('cid');
$everyone_num=I("everyone_num");
$interval_time=I("interval_time");
$aa=M("coupon_list")->where('uid',$user_id)->where('cid',$cid)->order('id desc')
->field('send_time')
->select();
if(count($aa)>=$everyone_num)
return json(['msg'=>"您优惠券领取数量已达上限!"]);
$time1 = strtotime("+" . $interval_time . " day", $aa[0]['send_time']);
if(time()<$time1) {
$timediff = $time1-time();
$days = intval($timediff/86400);
$remain = $timediff-$days*86400;
$hours = intval($remain/3600);
$remain = $remain-$hours*3600;
$mins = intval($remain/60);
$secs = $remain%60;
return json(['msg'=>"每".$interval_time."天领1次,剩余".($everyone_num-count($aa))."张,于".$days."天".$hours."小时".$mins."分".$secs."秒后再领"]);
}
}
// 网址图片生成BASE64
function img_curl_url($url,$type=0,$timeout=30)
{
$msg = ['code' => 2100, 'status' => 'error', 'msg' => '未知错误!'];
$imgs = ['image/jpeg' => 'jpeg',
'image/jpg' => 'jpg',
'image/gif' => 'gif',
'image/png' => 'png',
'text/html' => 'html',
'text/plain' => 'txt',
'image/pjpeg' => 'jpg',
'image/x-png' => 'png',
'image/x-icon' => 'ico'
];
if (!stristr($url, 'http')) {
$msg['code'] = 2101;
$msg['msg'] = 'url地址不正确!';
return $msg;
}
$dir = pathinfo($url);
//var_dump($dir);
$host = $dir['dirname'];
$refer = $host . '/';
$ch = curl_init($url);
//不验证https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_REFERER, $refer); //伪造来源地址
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//返回变量内容还是直接输出字符串,0输出,1返回内容
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);//在启用CURLOPT_RETURNTRANSFER的时候,返回原生的(Raw)输出
curl_setopt($ch, CURLOPT_HEADER, 0); //是否输出HEADER头信息 0否1是
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); //超时时间
$data = curl_exec($ch);
//$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
//$httpContentType = curl_getinfo($ch,CURLINFO_CONTENT_TYPE);
$info = curl_getinfo($ch);
curl_close($ch);
$httpCode = intval($info['http_code']);
$httpContentType = $info['content_type'];
$httpSizeDownload = intval($info['size_download']);
if ($httpCode != '200') {
$msg['code'] = 2102;
$msg['msg'] = 'url返回内容不正确!';
return $msg;
}
if ($type > 0 && !isset($imgs[$httpContentType])) {
$msg['code'] = 2103;
$msg['msg'] = 'url资源类型未知!';
return $msg;
}
if ($httpSizeDownload < 1) {
$msg['code'] = 2104;
$msg['msg'] = '内容大小不正确!';
return $msg;
}
$msg['code'] = 200;
$msg['status'] = 'success';
$msg['msg'] = '资源获取成功';
if ($type == 0 or $httpContentType == 'text/html') $msg['data'] = $data;
$base_64 = base64_encode($data);
if ($type == 1) $msg['data'] = $base_64;
elseif ($type == 2) $msg['data'] = "data:{$httpContentType};base64,{$base_64}";
elseif ($type == 3) $msg['data'] = "<img src='data:{$httpContentType};base64,{$base_64}' />";
else $msg['msg'] = '未知返回需求!';
unset($info, $data, $base_64);
return $msg;
}
}