作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

选择参加的考试

@@ -6,21 +6,12 @@ use think\Db; @@ -6,21 +6,12 @@ use think\Db;
6 use think\Exception; 6 use think\Exception;
7 use think\exception\PDOException; 7 use think\exception\PDOException;
8 use app\common\controller\Api; 8 use app\common\controller\Api;
9 -use app\common\library\Sms as Smslib;  
10 -use app\mobile\controller\Sms;  
11 use app\mobile\model\CompanyUser; 9 use app\mobile\model\CompanyUser;
12 -use app\mobile\model\Exam;  
13 use app\mobile\model\CourseOrder; 10 use app\mobile\model\CourseOrder;
14 use app\mobile\model\CourseAppraise; 11 use app\mobile\model\CourseAppraise;
15 use app\mobile\model\SecretOrder; 12 use app\mobile\model\SecretOrder;
16 -use app\mobile\model\ScoreSpec;  
17 -use app\mobile\model\ScoreOrder;  
18 -use app\mobile\model\QuestionCollect;  
19 -use app\mobile\model\CourseCollect;  
20 -use app\mobile\model\QuestionNote;  
21 -use app\mobile\model\Message;  
22 -use app\mobile\model\Feedback;  
23 -use app\mobile\model\Problem; 13 +use app\mobile\model\Package;
  14 +use app\mobile\model\PackageOrder;
24 use addons\epay\library\Service; 15 use addons\epay\library\Service;
25 16
26 /** 17 /**
@@ -47,7 +38,7 @@ class Company extends Api @@ -47,7 +38,7 @@ class Company extends Api
47 } 38 }
48 39
49 /** 40 /**
50 - * @ApiWeigh (67) 41 + * @ApiWeigh (99)
51 * @ApiTitle (我的密卷) 42 * @ApiTitle (我的密卷)
52 * @ApiSummary (我的密卷) 43 * @ApiSummary (我的密卷)
53 * @ApiMethod (POST) 44 * @ApiMethod (POST)
@@ -94,7 +85,7 @@ class Company extends Api @@ -94,7 +85,7 @@ class Company extends Api
94 } 85 }
95 86
96 /** 87 /**
97 - * @ApiWeigh (65) 88 + * @ApiWeigh (97)
98 * @ApiTitle (我的课程) 89 * @ApiTitle (我的课程)
99 * @ApiSummary (我的课程) 90 * @ApiSummary (我的课程)
100 * @ApiMethod (POST) 91 * @ApiMethod (POST)
@@ -147,7 +138,7 @@ class Company extends Api @@ -147,7 +138,7 @@ class Company extends Api
147 } 138 }
148 139
149 /** 140 /**
150 - * @ApiWeigh (99) 141 + * @ApiWeigh (95)
151 * @ApiTitle (企业成员管理) 142 * @ApiTitle (企业成员管理)
152 * @ApiSummary (企业成员管理) 143 * @ApiSummary (企业成员管理)
153 * @ApiMethod (POST) 144 * @ApiMethod (POST)
@@ -189,7 +180,7 @@ class Company extends Api @@ -189,7 +180,7 @@ class Company extends Api
189 } 180 }
190 181
191 /** 182 /**
192 - * @ApiWeigh (99) 183 + * @ApiWeigh (93)
193 * @ApiTitle (企业成员管理-同意加入) 184 * @ApiTitle (企业成员管理-同意加入)
194 * @ApiSummary (企业成员管理-同意加入) 185 * @ApiSummary (企业成员管理-同意加入)
195 * @ApiMethod (POST) 186 * @ApiMethod (POST)
@@ -215,7 +206,7 @@ class Company extends Api @@ -215,7 +206,7 @@ class Company extends Api
215 } 206 }
216 207
217 /** 208 /**
218 - * @ApiWeigh (99) 209 + * @ApiWeigh (91)
219 * @ApiTitle (企业成员管理-拒绝加入) 210 * @ApiTitle (企业成员管理-拒绝加入)
220 * @ApiSummary (企业成员管理-拒绝加入) 211 * @ApiSummary (企业成员管理-拒绝加入)
221 * @ApiMethod (POST) 212 * @ApiMethod (POST)
@@ -241,7 +232,7 @@ class Company extends Api @@ -241,7 +232,7 @@ class Company extends Api
241 } 232 }
242 233
243 /** 234 /**
244 - * @ApiWeigh (99) 235 + * @ApiWeigh (89)
245 * @ApiTitle (企业成员管理-移出团队) 236 * @ApiTitle (企业成员管理-移出团队)
246 * @ApiSummary (企业成员管理-移出团队) 237 * @ApiSummary (企业成员管理-移出团队)
247 * @ApiMethod (POST) 238 * @ApiMethod (POST)
@@ -267,7 +258,7 @@ class Company extends Api @@ -267,7 +258,7 @@ class Company extends Api
267 } 258 }
268 259
269 /** 260 /**
270 - * @ApiWeigh (99) 261 + * @ApiWeigh (87)
271 * @ApiTitle (企业成员管理-企业邀请码) 262 * @ApiTitle (企业成员管理-企业邀请码)
272 * @ApiSummary (企业成员管理-企业邀请码) 263 * @ApiSummary (企业成员管理-企业邀请码)
273 * @ApiMethod (POST) 264 * @ApiMethod (POST)
@@ -290,7 +281,7 @@ class Company extends Api @@ -290,7 +281,7 @@ class Company extends Api
290 } 281 }
291 282
292 /** 283 /**
293 - * @ApiWeigh (99) 284 + * @ApiWeigh (85)
294 * @ApiTitle (企业成员管理-更新企业邀请码) 285 * @ApiTitle (企业成员管理-更新企业邀请码)
295 * @ApiSummary (企业成员管理-更新企业邀请码) 286 * @ApiSummary (企业成员管理-更新企业邀请码)
296 * @ApiMethod (POST) 287 * @ApiMethod (POST)
@@ -311,4 +302,83 @@ class Company extends Api @@ -311,4 +302,83 @@ class Company extends Api
311 $invite_code = (new User)->setInviteCode($this->company_id); 302 $invite_code = (new User)->setInviteCode($this->company_id);
312 $this->success('更新邀请码成功',compact('invite_code')); 303 $this->success('更新邀请码成功',compact('invite_code'));
313 } 304 }
  305 +
  306 + /**
  307 + * @ApiWeigh (83)
  308 + * @ApiTitle (企业套餐)
  309 + * @ApiSummary (企业套餐)
  310 + * @ApiMethod (POST)
  311 + *
  312 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  313 + * @ApiParams (name="is_buy", type="inter", required=false, description="0=未购买,1=已购买")
  314 + * @ApiParams (name="order", type="inter", required=false, description="排序方式:0=最新,1=购买最多,2=价格最低,3=优惠最大")
  315 + *
  316 + * @ApiReturn({
  317 + "code": 1,
  318 + "msg": "成功",
  319 + "time": "1600167441",
  320 + "data": {
  321 + "invite_code": 376581, //企业邀请码
  322 + }
  323 + })
  324 + */
  325 + public function package()
  326 + {
  327 + $user_id = $this->auth->id;
  328 + $is_buy = $this->request->param('is_buy',0);
  329 + $order = $this->request->param('order',0);
  330 + switch ($order) {
  331 + case 0:
  332 + $order = ['p.createtime' => 'desc'];
  333 + break;
  334 + case 1:
  335 + $order = ['buy_num' => 'desc'];
  336 + break;
  337 + case 2:
  338 + $order = ['p.current_price' => 'asc'];
  339 + break;
  340 + case 3:
  341 + $order = ['preferential_price' => 'asc'];
  342 + break;
  343 + }
  344 + $package_order = Db::name('mobile_package_order')
  345 + ->where('pay_status','1')
  346 + ->field('id,package_id,people_num')
  347 + ->order(['is_top'=>'desc','people_num'=>'desc'])
  348 + ->limit(1)
  349 + ->buildSql();
  350 + $list = Package::alias('p')
  351 + ->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')
  352 + ->join('mobile_package_cart pc','pc.package_id = p.id and pc.user_id='.$user_id,'left')
  353 + ->field("
  354 + p.*,
  355 + if(po.id > 0,1,0) is_buy,
  356 + if(pc.id > 0,1,0) is_add_cart,
  357 + IFNULL((select SUM(current_price) from fa_mobile_secret where id in (p.secret_ids)),0) +
  358 + IFNULL((select SUM(current_price) from fa_mobile_course where id in (p.course_ids)),0) original_price,
  359 + p.buy_num_virtual + p.buy_num_real buy_num,
  360 + IFNULL((select SUM(current_price) from fa_mobile_secret where id in (p.secret_ids)),0) +
  361 + IFNULL((select SUM(current_price) from fa_mobile_course where id in (p.course_ids)),0) - p.current_price preferential_price
  362 + ")
  363 + ->order($order)
  364 + ->having("is_buy = {$is_buy}")
  365 + ->select();
  366 + // halt(Package::getLastSql());
  367 + foreach ($list as $v) {
  368 + $v->visible([
  369 + 'id',
  370 + 'title',
  371 + 'current_price',
  372 + ])->append([
  373 + 'is_buy',
  374 + 'is_add_cart',
  375 + 'original_price',
  376 + 'buy_num',
  377 + 'preferential_price',
  378 + 'secret_list',
  379 + 'course_list',
  380 + ]);
  381 + }
  382 + $this->success('成功',$list);
  383 + }
314 } 384 }
@@ -5,6 +5,7 @@ use app\common\controller\Api; @@ -5,6 +5,7 @@ use app\common\controller\Api;
5 use app\mobile\model\IndexBanner; 5 use app\mobile\model\IndexBanner;
6 use app\mobile\model\News; 6 use app\mobile\model\News;
7 use app\mobile\model\Exam; 7 use app\mobile\model\Exam;
  8 +use app\mobile\model\UserExam;
8 9
9 /** 10 /**
10 * 首页接口 11 * 首页接口
@@ -12,7 +13,7 @@ use app\mobile\model\Exam; @@ -12,7 +13,7 @@ use app\mobile\model\Exam;
12 */ 13 */
13 class Index extends Api 14 class Index extends Api
14 { 15 {
15 - protected $noNeedLogin = ['index','newsList','newsInfo']; 16 + protected $noNeedLogin = ['index','examList','newsList','newsInfo'];
16 protected $noNeedRight = ['*']; 17 protected $noNeedRight = ['*'];
17 18
18 public function _initialize() 19 public function _initialize()
@@ -25,7 +26,7 @@ class Index extends Api @@ -25,7 +26,7 @@ class Index extends Api
25 * @ApiSummary (首页) 26 * @ApiSummary (首页)
26 * @ApiMethod (POST) 27 * @ApiMethod (POST)
27 * 28 *
28 - * @ApiParams (name="exam_id", type="int", required=true, description="考试ID") 29 + * @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
29 * 30 *
30 * @ApiReturn({ 31 * @ApiReturn({
31 "code": 1, 32 "code": 1,
@@ -34,7 +35,9 @@ class Index extends Api @@ -34,7 +35,9 @@ class Index extends Api
34 "data": { 35 "data": {
35 "exam_list": [{ //二级考试列表 36 "exam_list": [{ //二级考试列表
36 "id": 3, //ID 37 "id": 3, //ID
37 - "nickname": "" //昵称 38 + "name": "", //考试名称
  39 + "nickname": "", //昵称
  40 + "countdown": 26 //考试倒计时
38 }], 41 }],
39 "banner_list": [{ //轮播图列表 42 "banner_list": [{ //轮播图列表
40 "id": 1, //ID 43 "id": 1, //ID
@@ -54,15 +57,25 @@ class Index extends Api @@ -54,15 +57,25 @@ class Index extends Api
54 */ 57 */
55 public function index() 58 public function index()
56 { 59 {
57 - $exam_id = $this->request->param('exam_id');  
58 - empty($exam_id) && $this->error('缺少必要参数');  
59 - // 所有二级分类  
60 - $exam_list = Exam::where('pid','>',0)->field('id,nickname')->select(); 60 + $user_id = $this->auth->id;
  61 + $exam_id_arr = UserExam::where('user_id',$user_id)->column('exam_id');
  62 + if($user_id > 0 && !empty($exam_id_arr)){
  63 + $exam_list = Exam::where('id','in',$exam_id_arr)
  64 + ->field('id,name,nickname,exam_time')
  65 + ->order('exam_time asc')
  66 + ->select();
  67 + foreach ($exam_list as &$v) {
  68 + $v['countdown'] = ceil(($v['exam_time']-time())/86400);
  69 + }
  70 + $exam = $exam_list[0];
  71 + }else{
  72 + $exam_list = [];
  73 + $exam = Exam::order('exam_time asc')->find();
  74 + }
61 // 轮播图 75 // 轮播图
62 $banner_list = IndexBanner::order('createtime desc')->field('id,image,url')->select(); 76 $banner_list = IndexBanner::order('createtime desc')->field('id,image,url')->select();
63 // 距离考试倒计时天数 77 // 距离考试倒计时天数
64 - $exam_time = Exam::where('id',$exam_id)->value('exam_time');  
65 - $countdown = ceil(($exam_time-time())/86400); 78 + $countdown = ceil(($exam['exam_time']-time())/86400);
66 // 报考资讯 79 // 报考资讯
67 $news_list = News::order('createtime desc')->select(); 80 $news_list = News::order('createtime desc')->select();
68 foreach ($news_list as $value) { 81 foreach ($news_list as $value) {
@@ -72,6 +85,68 @@ class Index extends Api @@ -72,6 +85,68 @@ class Index extends Api
72 } 85 }
73 86
74 /** 87 /**
  88 + * @ApiWeigh (87)
  89 + * @ApiTitle (选择参加的考试)
  90 + * @ApiSummary (选择参加的考试)
  91 + * @ApiMethod (POST)
  92 + *
  93 + * @ApiReturn({
  94 + "code": 1,
  95 + "msg": "成功",
  96 + "time": "1599018234",
  97 + "data": [{
  98 + "id": 1, //一级ID
  99 + "pid": 0,
  100 + "name": "建筑工程", //一级名称
  101 + "nickname": "", //一级昵称
  102 + "children": [{ //二级
  103 + "id": 3, //二级ID
  104 + "pid": 1, //父ID
  105 + "name": "一级建造师", //二级名称
  106 + "nickname": "" //二级昵称
  107 + }]
  108 + }]
  109 + })
  110 + */
  111 + public function examList()
  112 + {
  113 + $list = Exam::where('pid',0)->field('id,pid,name,nickname')->select();
  114 + foreach($list as &$v){
  115 + $v['children'] = Exam::where('pid',$v['id'])->field('id,pid,name,nickname')->select();
  116 + }
  117 + $this->success('成功', $list);
  118 + }
  119 +
  120 + /**
  121 + * @ApiTitle (选择考试)
  122 + * @ApiSummary (选择考试)
  123 + * @ApiMethod (POST)
  124 + *
  125 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  126 + * @ApiParams (name="exam_ids", type="string", required=true, description="考试ID,多个用英文逗号隔开")
  127 + *
  128 + * @ApiReturn({
  129 + "code": 1,
  130 + "msg": "成功",
  131 + "time": "1599026313",
  132 + "data": null
  133 + })
  134 + */
  135 + public function selectExam()
  136 + {
  137 + $user_id = $this->auth->id;
  138 + $exam_ids = $this->request->param('exam_ids');
  139 + empty($exam_ids) && $this->error('请选择考试');
  140 + UserExam::where('user_id',$user_id)->delete();
  141 + $add_data = [];
  142 + foreach (explode(',', $exam_ids) as $exam_id) {
  143 + $add_data[] = ['user_id'=>$user_id,'exam_id'=>$exam_id];
  144 + }
  145 + (new UserExam)->saveAll($add_data);
  146 + $this->success('选择考试成功');
  147 + }
  148 +
  149 + /**
75 * @ApiTitle (报考资讯) 150 * @ApiTitle (报考资讯)
76 * @ApiSummary (报考资讯) 151 * @ApiSummary (报考资讯)
77 * @ApiMethod (POST) 152 * @ApiMethod (POST)
@@ -248,39 +248,6 @@ class User extends Api @@ -248,39 +248,6 @@ class User extends Api
248 } 248 }
249 249
250 /** 250 /**
251 - * @ApiWeigh (87)  
252 - * @ApiTitle (选择参加的考试)  
253 - * @ApiSummary (选择参加的考试)  
254 - * @ApiMethod (POST)  
255 - *  
256 - * @ApiReturn({  
257 - "code": 1,  
258 - "msg": "成功",  
259 - "time": "1599018234",  
260 - "data": [{  
261 - "id": 1, //一级ID  
262 - "pid": 0,  
263 - "name": "建筑工程", //一级名称  
264 - "nickname": "", //一级昵称  
265 - "children": [{ //二级  
266 - "id": 3, //二级ID  
267 - "pid": 1, //父ID  
268 - "name": "一级建造师", //二级名称  
269 - "nickname": "" //二级昵称  
270 - }]  
271 - }]  
272 - })  
273 - */  
274 - public function exam()  
275 - {  
276 - $list = Exam::where('pid',0)->field('id,pid,name,nickname')->select();  
277 - foreach($list as &$v){  
278 - $v['children'] = Exam::where('pid',$v['id'])->field('id,pid,name,nickname')->select();  
279 - }  
280 - $this->success('成功', $list);  
281 - }  
282 -  
283 - /**  
284 * @ApiWeigh (85) 251 * @ApiWeigh (85)
285 * @ApiTitle (暂不登录提示) 252 * @ApiTitle (暂不登录提示)
286 * @ApiSummary (暂不登录提示) 253 * @ApiSummary (暂不登录提示)
@@ -1247,6 +1214,39 @@ class User extends Api @@ -1247,6 +1214,39 @@ class User extends Api
1247 } 1214 }
1248 1215
1249 /** 1216 /**
  1217 + * @ApiWeigh (33)
  1218 + * @ApiTitle (我的求职)
  1219 + * @ApiSummary (我的求职)
  1220 + * @ApiMethod (POST)
  1221 + *
  1222 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  1223 + * @ApiParams (name="problem_id", type="inter", required=true, description="问题ID")
  1224 + *
  1225 + * @ApiReturn({
  1226 + "code": 1,
  1227 + "msg": "成功",
  1228 + "time": "1600167441",
  1229 + "data": {
  1230 + "id": 7, //消息ID
  1231 + "user_id": 16, //用户ID
  1232 + "title": "这是个消息", //消息标题
  1233 + "content": "这个消息还不错Q", //消息内容
  1234 + "is_read": "1", //是否已读:0=否,1=是
  1235 + "createtime": 1599914736,
  1236 + "updatetime": 1600167441
  1237 + }
  1238 + })
  1239 + */
  1240 + public function userJob()
  1241 + {
  1242 + $problem_id = $this->request->param('problem_id');
  1243 + empty($problem_id) && $this->error('缺少必需参数');
  1244 + $info = Problem::get($problem_id);
  1245 + empty($info) && $this->error('问题不存在');
  1246 + $this->success('成功', $info);
  1247 + }
  1248 +
  1249 + /**
1250 * @ApiWeigh (10) 1250 * @ApiWeigh (10)
1251 * @ApiTitle (常见问题) 1251 * @ApiTitle (常见问题)
1252 * @ApiSummary (常见问题) 1252 * @ApiSummary (常见问题)
  1 +<?php
  2 +namespace app\mobile\model;
  3 +
  4 +use think\Model;
  5 +
  6 +class Package extends Model
  7 +{
  8 + // 表名
  9 + protected $name = 'mobile_package';
  10 + // 开启自动写入时间戳字段
  11 + protected $autoWriteTimestamp = 'int';
  12 + // 定义时间戳字段名
  13 + protected $createTime = 'createtime';
  14 + protected $updateTime = 'updatetime';
  15 +
  16 + // 密卷列表
  17 + public function getSecretListAttr($value,$data){
  18 + if(empty($data['secret_ids'])){
  19 + return [];
  20 + }
  21 + return Secret::where('id','in',$data['secret_ids'])->select();
  22 + }
  23 +
  24 + // 课程列表
  25 + public function getCourseListAttr($value,$data){
  26 + if(empty($data['course_ids'])){
  27 + return [];
  28 + }
  29 + return Secret::where('id','in',$data['course_ids'])->select();
  30 + }
  31 +}
  1 +<?php
  2 +namespace app\mobile\model;
  3 +
  4 +use think\Model;
  5 +use think\Db;
  6 +
  7 +class PackageOrder extends Model
  8 +{
  9 + // 表名
  10 + protected $name = 'mobile_package_order';
  11 + // 开启自动写入时间戳字段
  12 + protected $autoWriteTimestamp = 'int';
  13 + // 定义时间戳字段名
  14 + protected $createTime = 'createtime';
  15 + protected $updateTime = 'updatetime';
  16 +
  17 + // 课程信息
  18 + public function course(){
  19 + return $this->belongsTo('Course');
  20 + }
  21 +
  22 + /**
  23 + * 新增订单
  24 + */
  25 + public function add($user, $order, $pay_type)
  26 + {
  27 + // 记录订单信息
  28 + $this->save([
  29 + 'user_id' => $user['id'],
  30 + 'company_id' => Company::where('user_id',$user['id'])->value('id'),
  31 + 'package_id' => $order['package_info']['id'],
  32 + 'order_sn' => get_order_sn(),
  33 + 'pay_price' => $order['pay_price'],
  34 + 'pay_type' => $pay_type,
  35 + 'package_price' => $order['package_price'],
  36 + 'people_num' => $order['spec_info']['people_num'],
  37 + 'course_spec_id' => $order['spec_info']['id'],
  38 + 'is_top' => $order['spec_info']['is_top']
  39 + ]);
  40 + return true;
  41 + }
  42 +}
  1 +<?php
  2 +namespace app\mobile\model;
  3 +
  4 +use think\Model;
  5 +
  6 +class UserExam extends Model
  7 +{
  8 + // 表名
  9 + protected $name = 'mobile_user_exam';
  10 + // 开启自动写入时间戳字段
  11 + protected $autoWriteTimestamp = 'int';
  12 + // 定义时间戳字段名
  13 + protected $createTime = 'createtime';
  14 + protected $updateTime = 'updatetime';
  15 +}
此 diff 太大无法显示。