Business.php
9.2 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
<?php
namespace app\api\controller\v1;
use app\common\controller\Api;
use think\Db;
use think\Exception;
/**
* 商家端接口
*/
class Business extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
protected $postParam;
protected $store_id;
protected $staff;
protected $staff_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;
$staff = Db::name("verification_staff")->where("verification_store_id", $this->store_id)->find();
if (empty($staff)) {
$this->error("暂无权限!");
}
$this->staff = $staff;
$this->staff_id = $staff['id'];
}
/**
* 1、商家首页 获取商家人员信息
*/
public function getstaff(){
$this->success('活动获取成功', $this->staff);
}
/**
* 2、核销
*/
public function checkconsumption(){
$receive_no=$this->postParam['receive_no'];
//先查询到领卷记录
$where["receive_no"] = ["=", $receive_no];
$where["verification_store_id"] = ["=", $this->store_id];
$receive=Db::name('verification_receive')->where($where)->find();
if(empty($receive)){
$this->error('无效卡卷');
}
if($receive['type']==1){
$this->error('该卡卷已使用');
}
if($receive['type']==2){
$this->error('该卡卷已过期');
}
$time=time();
if($receive['closetime']<$time){
$this->error('该卡卷已过期');
}
Db::startTrans();
try {
$iswhere["id"] = ["=", $receive['id']];
$isdata=[
'usetime'=>$time,
'type'=>1
];
//先把领卷记录修改了
$isreceive=Db::name('verification_receive')->where($iswhere)->update($isdata);
//添加核销记录
$canceldata=[
'verification_store_id'=>$this->store_id,
'verification_staff_id'=>$this->staff_id,
'verification_receive_id'=>$receive['id'],
'createtime'=>$time,
];
$cancel=Db::name('verification_cancel')->insertGetId($canceldata);
Db::commit();
}catch (Exception $e){
Db::rollback();
$this->error($e->getMessage());
}
if($cancel){
$this->success('核销成功');
}else{
$this->error('核销失败');
}
//核销data
}
/**
*3、核销页面的核销记录 单条
*/
public function getverification_cancel(){
$where["verification_store_id"] = ["=", $this->store_id];
$where["verification_staff_id"] = ["=", $this->staff_id];
$cancel=Db::name('verification_cancel')->where($where)->find();
$this->success('查询成功',$cancel);
}
/**
*4、核销记录
*/
public function selectverification_cancel(){
$keyfield=$this->postParam['keyfield'];
$where= " url like %{$keyfield}% or content like %{$keyfield}%";
$cancel=Db::name('admin_log')->where($where)->fetchSql()->count();
$this->success('查询成功',$cancel);
$page = $this->request->post('page', 1);
$total = $this->request->post('total', 10);
$where["a.verification_store_id"] = ["=", $this->store_id];
if($keyfield){
$where["c.receive_no"] = ["LIKE", "%{$keyfield}%"];
}
$field = "a.id,a.createtime,b.name,d.name as coupon_name,c.type";
$cancel=Db::name('verification_cancel')
->alias('a')
->join('verification_staff b','a.verification_staff_id=b.id')
->join('verification_receive c','a.verification_receive_id=c.id')
->join('verification_coupon d','c.verification_coupon_id=d.id')
->where($where)
->paginate($total, false, ['page' => $page])
->toArray();
$this->success('查询成功',$cancel);
}
/**
* 5、个人业绩
*/
public function performance(){
$where["verification_store_id"] = ["=", $this->store_id];
$activity=Db::name('verification_activity')->where($where)->order('id DESC')->find();
//先查询活动
$this->success('查询成功',$activity);
}
/**
* 6、订单查询
*/
public function selectorder(){
$page = $this->request->post('page', 1);
$total = $this->request->post('total', 10);
$where["a.verification_store_id"] = ["=", $this->store_id];
$field = "a.id,a.order_no,a.name,a.phone,a.type,b.title";
$order=Db::name('verification_order')
->alias('a')
->join('verification_activity b','a.verification_activity_id=b.id')
->where($where)
->field($field)
->paginate($total, false, ['page' => $page])
->toArray();
$this->success('查询成功',$order);
}
/**
* 7、订单详情
*/
public function orderinfo(){
$id = $this->request->post('id' );
$where["a.id"] = ["=", $id];
$field = "a.id,a.order_no,a.name,a.phone,a.type,b.title";
$order=Db::name('verification_order')
->alias('a')
->join('verification_activity b','a.verification_activity_id=b.id')
->where($where)
->field($field)
->find();
//查询具体卡卷
$receivewhere['verification_order_id']=['=',$order['id']];
$receive=Db::name("cv_verification_receive")->where($receivewhere)->select();
$order['receive']=$receive;
$this->success('查询成功',$order);
}
/**
* 8、手动核销订单中的某个卡卷
*/
public function ordercheckconsumption(){
$id=$this->postParam['id'];
//先查询到领卷记录
$where["id"] = ["=", $id];
$where["verification_store_id"] = ["=", $this->store_id];
$receive=Db::name('verification_receive')->where($where)->find();
if(empty($receive)){
$this->error('无效卡卷');
}
if($receive['type']==1){
$this->error('该卡卷已使用');
}
if($receive['type']==2){
$this->error('该卡卷已过期');
}
$time=time();
if($receive['closetime']<$time){
$this->error('该卡卷已过期');
}
Db::startTrans();
try {
$iswhere["id"] = ["=", $receive['id']];
$isdata=[
'usetime'=>$time,
'type'=>1
];
//先把领卷记录修改了
$isreceive=Db::name('verification_receive')->where($iswhere)->update($isdata);
//添加核销记录
$canceldata=[
'verification_store_id'=>$this->store_id,
'verification_staff_id'=>$this->staff_id,
'verification_receive_id'=>$receive['id'],
'createtime'=>$time,
];
$cancel=Db::name('verification_cancel')->insertGetId($canceldata);
Db::commit();
}catch (Exception $e){
Db::rollback();
$this->error($e->getMessage());
}
if($cancel){
$this->success('核销成功');
}else{
$this->error('核销失败');
}
//核销data
}
/**
* 9、用户员工管理
*/
public function userstaff(){
$store_id=$this->store_id;
//查询员工
$page = $this->request->post('page', 1);
$total = $this->request->post('total', 10);
$where["a.verification_store_id"] = ["=", $this->store_id];
$staff=Db::name('verification_staff')
->where($where)
->paginate($total, false, ['page' => $page])
->toArray();
$this->success("查询成功",$staff);
}
/**
*10、修改员工职务
*/
public function updatestaff(){
$id=$this->postParam['id'];
$type=$this->postParam['type'];
$res=Db::name('verification_staff')
->where('id',$id)
->update([
'type'=>$type
]);
if($res){
$this->success("修改成功");
}else{
$this->error("修改异常");
}
}
/**
* 11、邀请代理二维码
*/
public function inviteagent(){
$image=$this->store['agent_image'];
$this->success("查询成功",$image);
}
/**
* 12、业绩查询
*/
public function selectPerformance(){
$store_id=$this->store_id;
$row='';
$this->success("查询成功",$row);
}
}