Client.php
5.3 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
<?php
namespace app\api\controller\v1;
use app\common\controller\Api;
use think\Db;
use think\Exception;
/**
* 用户端接口
*/
class Client extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
protected $postParam;
protected $store_id;
protected $store;
public function _initialize()
{
$postParam = $this->request->param();
$this->postParam = $postParam;
parent::_initialize();
$this->auth->id = 1;//测试用
$postParam = $this->request->param();
$this->postParam = $postParam;
if (empty($postParam['code'])) {
$this->error("门店code异常");
}
$this->store_id = $postParam['code'];
$store = Db::name("verification_store")->where("id", $this->store_id)->find();
if (empty($store)) {
$this->error("门店不存在,请退出登录后重试!");
}
$this->store = $store;
if (empty($this->auth->id)) {
$this->error("暂无权限!");
}
}
/**
* 1、获取活动
*/
public function getactivity(){
//根据门店查询活动
$time=time();
$where["closetime"] = [">", $time];
$where["verification_store_id"] = ["=", $this->store_id];
$activity=Db::name('verification_activity')->where($where)->find();
$this->success('活动获取成功', $activity);
}
/**
* 1.1参加活动用户信息
*/
public function participate_activitie(){
$activity_id=$this->postParam['id'];
$page = $this->request->post('page', 1);
$total = $this->request->post('total', 10);
$where['type']=1;
$where['verification_activity_id']=$activity_id;
$user=Db::name("verification_order")
->where('verification_activity_id','=',$activity_id)
->field('name')
->paginate($total, false, ['page' => $page])
->toArray();
if(!empty($user['data'])){
for ($i=0;$i<count($user['data']);$i++){
$sort=$i+1;
$user['data'][$i]['sort']=$sort;
$user['data'][$i]['name']=$this->substr_cut($user['data'][$i]['name']);
}
}
$this->success('查询成功',$user);
}
/**
* 1.1.1名字加*
* @param $user_name
* @return string
*/
function substr_cut($user_name){
$strlen = mb_strlen($user_name, 'utf-8'); //获取字符长度
$firstStr = mb_substr($user_name, 0, 1, 'utf-8'); //查找字符第一个
$str=$firstStr . str_repeat('*', $strlen - 1); //拼接第一个+把字符串 "* " 重复 $strlen - 1 次:
return $str;
}
/**
* 2、举办活动
*/
public function holdactivity(){
$verification_store_id=$this->store_id;
$name=$this->postParam['name'];
$phone=$this->postParam['phone'];
$industry=$this->postParam['industry'];
$address=$this->postParam['address'];
$verification_activity_id=$this->postParam['id'];
$user_id=$this->auth->id;
$data=[
'verification_store_id'=>$verification_store_id,
'name'=>$name,
'phone'=>$phone,
'industry'=>$industry,
'address'=>$address,
'verification_activity_id'=>$verification_activity_id,
'user_id'=>$user_id
];
$res=Db::name('verification_hold_activity')->insertGetId($data);
if($res){
$this->success("提交成功");
}else{
$this->error("提交失败");
}
}
/**
* 3、查询个人订单
*/
public function myorder(){
$id=$this->auth->id;
$type=$this->postParam['type'];
$verification_store_id=$this->store_id;
$where['a.verification_store_id']=$verification_store_id;
$page = $this->request->post('page', 1);
$total = $this->request->post('total', 10);
if($type){
$where['a.type']=$type;
}
$row=Db::name('verification_order')
->alias('a')
->join('verification_store b','a.verification_store_id=b.id')
->where($where)
->paginate($total, false, ['page' => $page])
->toArray();
}
/**
* 4、订单详情
*/
public function orderinfo(){
$order_id=$this->postParam['id'];
$where['id']=$order_id;
$where['user_id']=$this->auth->id;
$order=Db::name('verification_order')->where($where)->find();
if($order){
$receivewhere['verification_order_id']=$order_id;
$receive=Db::name('cv_verification_receive')->where($receivewhere)->select();
$order['receive']=$receive;
$this->success("查询成功",$order);
}else{
$this->error("查询失败");
}
}
/**
* 5、卡卷详情
*/
public function receiveinfo(){
$receive=$this->postParam['id'];
$where['id']=$receive;
$where['user_id']=$this->auth->id;
$field="a.*,b.image,b.name";
$receive=Db::name('cv_verification_receive')
->alias('a')
->join('verification_store b','a.verification_store_id=b.id')
->where($where)
->field($field)
->find();
$this->success("查询成功",$receive);
}
}