Company.php
13.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
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
<?php
namespace app\mobile\controller;
use think\Validate;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use app\common\controller\Api;
use app\mobile\model\CompanyUser;
use app\mobile\model\CourseOrder;
use app\mobile\model\CourseAppraise;
use app\mobile\model\SecretOrder;
use app\mobile\model\Package;
use app\mobile\model\PackageOrder;
use addons\epay\library\Service;
/**
* 我的(企业)接口
* @ApiWeigh (65)
*/
class Company extends Api
{
protected $noNeedLogin = [''];
protected $noNeedRight = ['*'];
protected $company_id = 0;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\mobile\model\Company;
if(!$this->company_id){
$user = $this->auth->getUser();
if($user['group_id'] == 0){
$this->error('您还不是企业管理员');
}
$this->company_id = $this->model->where('user_id',$user['id'])->value('id');
}
}
/**
* @ApiWeigh (99)
* @ApiTitle (我的密卷)
* @ApiSummary (我的密卷)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600499807",
"data": [
{
"id": 10, //密卷订单ID
"pay_price": "500.00", //实际支付金额
"people_num": 20, //密卷规格人数(斜杠后数字)
"is_top": "1", //是否顶配:0=否,1=是
"secret": {
"id": 1, //密卷ID
"title": "测试密卷",
"do_num": 20
},
"user_count": 3 //当前企业下员工含管理员数量(斜杠前数字)
}
]
})
*/
public function mySecret(){
// 查找所有密卷
$list = SecretOrder::with(['secret'])
->where('company_id',$this->company_id)
->where('user_id',$this->auth->id)
->where('pay_status','1')
->select();
$user_count = CompanyUser::where('company_id',$this->company_id)
->where('status','1')
->count();
foreach ($list as $v) {
// 当前企业下员工含管理员人数
$v['user_count'] = $user_count + 1;
$v->visible(['id','pay_price','people_num','is_top','secret'])->append(['user_count']);
$v->getRelation('secret')->visible(['id','title']);
}
$this->success('成功',$list);
}
/**
* @ApiWeigh (97)
* @ApiTitle (我的课程)
* @ApiSummary (我的课程)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600081718",
"data": [{
"id": 9, //课程订单ID
"pay_price": "50.00", //实际支付金额
"people_num": 20, //限制人数(斜杠后数字)
"is_top": "0", //是否顶配:0=否,1=是
"course": { //课程信息
"id": 1, //课程ID
"title": "测试课程", //课程标题
"cover": "" //课程封面图
},
"user_count": 0 //当前企业下员工含管理员数量(斜杠前数字)
"is_have_appraise": 0 //是否已评价:0=否,1=是
}]
})
*/
public function myCourse(){
// 查找所有密卷
$list = CourseOrder::with(['course'])
->where('company_id',$this->company_id)
->where('user_id',$this->auth->id)
->where('pay_status','1')
->select();
$user_count = CompanyUser::where('company_id',$this->company_id)
->where('status','1')
->count();
foreach ($list as $v) {
// 当前企业下员工含管理员人数
$v['user_count'] = $user_count + 1;
// 是否已评价
$have_appraise = CourseAppraise::where('user_id',$this->auth->id)
->where('course_id',$v['course_id'])
->where('course_order_id',$v['id'])
->field('id')
->find();
$v['is_have_appraise'] = !empty($have_appraise) ? 1 : 0;
$v->visible(['id','pay_price','people_num','is_top','course'])->append(['user_count','is_have_appraise']);
$v->getRelation('course')->visible(['id','cover','title']);
}
$this->success('成功',$list);
}
/**
* @ApiWeigh (95)
* @ApiTitle (企业成员管理)
* @ApiSummary (企业成员管理)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="status", type="string", required=false, description="0=未审核,1=已通过")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600511589",
"data": {
"total": 2, //数据总数
"list": [
{
"id": 1, //申请ID
"name": "何先生", //申请人名称
"createtime": "2020.09.12" //申请时间
}
]
}
})
*/
public function companyUser()
{
$status = $this->request->param('status','0');
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
$data = CompanyUser::where('company_id',$this->company_id)
->where('status',$status)
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v['createtime'] = date('Y.m.d',$v['createtime']);
$v->visible(['id','name','createtime']);
})->toArray();
$this->success('成功',['total'=>$data['total'],'list'=>$data['data']]);
}
/**
* @ApiWeigh (93)
* @ApiTitle (企业成员管理-同意加入)
* @ApiSummary (企业成员管理-同意加入)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="company_user_id", type="string", required=false, description="申请ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600167441",
"data": null
})
*/
public function companyUserAgree()
{
$company_user_id = $this->request->param('company_user_id');
empty($company_user_id) && $this->error('缺少必需参数');
$info = CompanyUser::get($company_user_id);
empty($info) && $this->error('申请信息不存在');
$info->save(['status'=>'1']);
$this->success('同意加入成功');
}
/**
* @ApiWeigh (91)
* @ApiTitle (企业成员管理-拒绝加入)
* @ApiSummary (企业成员管理-拒绝加入)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="company_user_id", type="string", required=false, description="申请ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600167441",
"data": null
})
*/
public function companyUserRefuse()
{
$company_user_id = $this->request->param('company_user_id');
empty($company_user_id) && $this->error('缺少必需参数');
$info = CompanyUser::get($company_user_id);
empty($info) && $this->error('申请信息不存在');
$info->save(['status'=>'2']);
$this->success('拒绝成功');
}
/**
* @ApiWeigh (89)
* @ApiTitle (企业成员管理-移出团队)
* @ApiSummary (企业成员管理-移出团队)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="company_user_id", type="string", required=false, description="申请ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600167441",
"data": null
})
*/
public function companyUserRemove()
{
$company_user_id = $this->request->param('company_user_id');
empty($company_user_id) && $this->error('缺少必需参数');
$info = CompanyUser::get($company_user_id);
empty($info) && $this->error('申请信息不存在');
$info->delete();
$this->success('移出成功');
}
/**
* @ApiWeigh (87)
* @ApiTitle (企业成员管理-企业邀请码)
* @ApiSummary (企业成员管理-企业邀请码)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600167441",
"data": {
"invite_code": 376581, //企业邀请码
}
})
*/
public function inviteCode()
{
$invite_code = $this->model->where('id',$this->company_id)->value('invite_code');
$this->success('成功',compact('invite_code'));
}
/**
* @ApiWeigh (85)
* @ApiTitle (企业成员管理-更新企业邀请码)
* @ApiSummary (企业成员管理-更新企业邀请码)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600167441",
"data": {
"invite_code": 376581, //企业邀请码
}
})
*/
public function setInviteCode()
{
$invite_code = (new User)->setInviteCode($this->company_id);
$this->success('更新邀请码成功',compact('invite_code'));
}
/**
* @ApiWeigh (83)
* @ApiTitle (企业套餐)
* @ApiSummary (企业套餐)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="is_buy", type="inter", required=false, description="0=未购买,1=已购买")
* @ApiParams (name="order", type="inter", required=false, description="排序方式:0=最新,1=购买最多,2=价格最低,3=优惠最大")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600167441",
"data": {
"invite_code": 376581, //企业邀请码
}
})
*/
public function package()
{
$user_id = $this->auth->id;
$is_buy = $this->request->param('is_buy',0);
$order = $this->request->param('order',0);
switch ($order) {
case 0:
$order = ['p.createtime' => 'desc'];
break;
case 1:
$order = ['buy_num' => 'desc'];
break;
case 2:
$order = ['p.current_price' => 'asc'];
break;
case 3:
$order = ['preferential_price' => 'asc'];
break;
}
$package_order = Db::name('mobile_package_order')
->where('pay_status','1')
->field('id,package_id,people_num')
->order(['is_top'=>'desc','people_num'=>'desc'])
->limit(1)
->buildSql();
$list = Package::alias('p')
->join(['select id,package_id,people_num from mobile_package_order where pay_status = 1 and user_id = '.$user_id.'and pay_status = 1 order by is_top,people_num desc limit 1'=>'po'],'p.id = po.package_id','left')
->join('mobile_package_cart pc','pc.package_id = p.id and pc.user_id='.$user_id,'left')
->field("
p.*,
if(po.id > 0,1,0) is_buy,
if(pc.id > 0,1,0) is_add_cart,
IFNULL((select SUM(current_price) from fa_mobile_secret where id in (p.secret_ids)),0) +
IFNULL((select SUM(current_price) from fa_mobile_course where id in (p.course_ids)),0) original_price,
p.buy_num_virtual + p.buy_num_real buy_num,
IFNULL((select SUM(current_price) from fa_mobile_secret where id in (p.secret_ids)),0) +
IFNULL((select SUM(current_price) from fa_mobile_course where id in (p.course_ids)),0) - p.current_price preferential_price
")
->order($order)
->having("is_buy = {$is_buy}")
->select();
// halt(Package::getLastSql());
foreach ($list as $v) {
$v->visible([
'id',
'title',
'current_price',
])->append([
'is_buy',
'is_add_cart',
'original_price',
'buy_num',
'preferential_price',
'secret_list',
'course_list',
]);
}
$this->success('成功',$list);
}
}