HexiaoController.php
3.1 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
<?php
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
class HexiaoController extends AdminBaseController{
//核销页显示
public function index(){
return $this -> fetch();
}
//核销数据
public function hxCancel(){
$code = input('post.code');
$ma = Db::name('coupons_user') -> where('code',$code) -> find();
if($ma){
$riqi = Db::name('coupons') -> where('id',$ma['cid']) -> find();
$date =strtotime(date('y-m-d'));
$begin = strtotime($riqi['startime']);
$end = strtotime($riqi['endtime']);
if($date >= $begin && $date <= $end ){
//生日核销
/*if ($riqi['type'] == 2) {
$shegri = Db::name('members_user') -> where('id',$ma['uid']) -> find();
$nian = mb_substr($shegri['birthday'],0,4);
$yue = mb_substr($shegri['birthday'],5,2);
$riaa = mb_substr($shegri['birthday'],8,2);
$bir = $yue.$riaa;
if ($bir == date('md')) {
$update = Db::name('coupons_user') -> where('code',$code) -> update(['state' => 1]);
return 1;
}else{
return 5;
}
}else{
}*/
$shijian = time();
$code_zuixin = Db::name('coupons_user') -> where('code',$code) -> find();
if($code_zuixin['state'] != 1){
$update = Db::name('coupons_user') -> where('code',$code) -> update(['state' => 1,'time'=>$shijian]);
if($update){
return 1;
}else{
return 4;
}
}else{
return 4;
}
}else{
return 3;
}
}else{
return 2;
}
}
//已核销页
public function yihexiao(){
if($this ->request -> isPost()){
$where = [
"a.state" => 1
];
if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
$start_time = strtotime($_POST['start_time']);
$end_time = strtotime($_POST['end_time']);
$where['a.time'] = [['>=',$start_time],['<=',$end_time]];
}
$data = Db::name('coupons_user') -> alias('a') -> join('members_user b','a.uid=b.id','LEFT') -> where($where) -> order('a.time desc') -> select() -> toArray();
}else{
$data = Db::name('coupons_user') -> alias('a') -> join('members_user b','a.uid=b.id','LEFT') -> where('a.state=1') -> order('a.time desc') -> select() -> toArray();
}
foreach ($data as $key => $value) {
$quan = Db::name('coupons') -> where('id',$value['cid']) -> find();
$data[$key]['title'] = $quan['title'];
}
$this -> assign('data',$data);
return $this -> fetch();
}
/**
* 使用核销码获取身份证号
*/
public function hexiao_idnum(){
$code = $_POST['code'];
$uid = Db::name('coupons_user') -> where('code',$code) -> find();
$data = Db::name('members_user') -> where('id',$uid['uid']) -> find();
if($data['id_num']){
return $data['id_num'];
}else{
return false;
}
}
}
?>