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

选择参加的考试

... ... @@ -6,21 +6,12 @@ use think\Db;
use think\Exception;
use think\exception\PDOException;
use app\common\controller\Api;
use app\common\library\Sms as Smslib;
use app\mobile\controller\Sms;
use app\mobile\model\CompanyUser;
use app\mobile\model\Exam;
use app\mobile\model\CourseOrder;
use app\mobile\model\CourseAppraise;
use app\mobile\model\SecretOrder;
use app\mobile\model\ScoreSpec;
use app\mobile\model\ScoreOrder;
use app\mobile\model\QuestionCollect;
use app\mobile\model\CourseCollect;
use app\mobile\model\QuestionNote;
use app\mobile\model\Message;
use app\mobile\model\Feedback;
use app\mobile\model\Problem;
use app\mobile\model\Package;
use app\mobile\model\PackageOrder;
use addons\epay\library\Service;
/**
... ... @@ -47,7 +38,7 @@ class Company extends Api
}
/**
* @ApiWeigh (67)
* @ApiWeigh (99)
* @ApiTitle (我的密卷)
* @ApiSummary (我的密卷)
* @ApiMethod (POST)
... ... @@ -94,7 +85,7 @@ class Company extends Api
}
/**
* @ApiWeigh (65)
* @ApiWeigh (97)
* @ApiTitle (我的课程)
* @ApiSummary (我的课程)
* @ApiMethod (POST)
... ... @@ -147,7 +138,7 @@ class Company extends Api
}
/**
* @ApiWeigh (99)
* @ApiWeigh (95)
* @ApiTitle (企业成员管理)
* @ApiSummary (企业成员管理)
* @ApiMethod (POST)
... ... @@ -189,7 +180,7 @@ class Company extends Api
}
/**
* @ApiWeigh (99)
* @ApiWeigh (93)
* @ApiTitle (企业成员管理-同意加入)
* @ApiSummary (企业成员管理-同意加入)
* @ApiMethod (POST)
... ... @@ -215,7 +206,7 @@ class Company extends Api
}
/**
* @ApiWeigh (99)
* @ApiWeigh (91)
* @ApiTitle (企业成员管理-拒绝加入)
* @ApiSummary (企业成员管理-拒绝加入)
* @ApiMethod (POST)
... ... @@ -241,7 +232,7 @@ class Company extends Api
}
/**
* @ApiWeigh (99)
* @ApiWeigh (89)
* @ApiTitle (企业成员管理-移出团队)
* @ApiSummary (企业成员管理-移出团队)
* @ApiMethod (POST)
... ... @@ -267,7 +258,7 @@ class Company extends Api
}
/**
* @ApiWeigh (99)
* @ApiWeigh (87)
* @ApiTitle (企业成员管理-企业邀请码)
* @ApiSummary (企业成员管理-企业邀请码)
* @ApiMethod (POST)
... ... @@ -290,7 +281,7 @@ class Company extends Api
}
/**
* @ApiWeigh (99)
* @ApiWeigh (85)
* @ApiTitle (企业成员管理-更新企业邀请码)
* @ApiSummary (企业成员管理-更新企业邀请码)
* @ApiMethod (POST)
... ... @@ -311,4 +302,83 @@ class Company extends Api
$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);
}
}
\ No newline at end of file
... ...
... ... @@ -5,6 +5,7 @@ use app\common\controller\Api;
use app\mobile\model\IndexBanner;
use app\mobile\model\News;
use app\mobile\model\Exam;
use app\mobile\model\UserExam;
/**
* 首页接口
... ... @@ -12,7 +13,7 @@ use app\mobile\model\Exam;
*/
class Index extends Api
{
protected $noNeedLogin = ['index','newsList','newsInfo'];
protected $noNeedLogin = ['index','examList','newsList','newsInfo'];
protected $noNeedRight = ['*'];
public function _initialize()
... ... @@ -25,7 +26,7 @@ class Index extends Api
* @ApiSummary (首页)
* @ApiMethod (POST)
*
* @ApiParams (name="exam_id", type="int", required=true, description="考试ID")
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
*
* @ApiReturn({
"code": 1,
... ... @@ -34,7 +35,9 @@ class Index extends Api
"data": {
"exam_list": [{ //二级考试列表
"id": 3, //ID
"nickname": "" //昵称
"name": "", //考试名称
"nickname": "", //昵称
"countdown": 26 //考试倒计时
}],
"banner_list": [{ //轮播图列表
"id": 1, //ID
... ... @@ -54,15 +57,25 @@ class Index extends Api
*/
public function index()
{
$exam_id = $this->request->param('exam_id');
empty($exam_id) && $this->error('缺少必要参数');
// 所有二级分类
$exam_list = Exam::where('pid','>',0)->field('id,nickname')->select();
$user_id = $this->auth->id;
$exam_id_arr = UserExam::where('user_id',$user_id)->column('exam_id');
if($user_id > 0 && !empty($exam_id_arr)){
$exam_list = Exam::where('id','in',$exam_id_arr)
->field('id,name,nickname,exam_time')
->order('exam_time asc')
->select();
foreach ($exam_list as &$v) {
$v['countdown'] = ceil(($v['exam_time']-time())/86400);
}
$exam = $exam_list[0];
}else{
$exam_list = [];
$exam = Exam::order('exam_time asc')->find();
}
// 轮播图
$banner_list = IndexBanner::order('createtime desc')->field('id,image,url')->select();
// 距离考试倒计时天数
$exam_time = Exam::where('id',$exam_id)->value('exam_time');
$countdown = ceil(($exam_time-time())/86400);
$countdown = ceil(($exam['exam_time']-time())/86400);
// 报考资讯
$news_list = News::order('createtime desc')->select();
foreach ($news_list as $value) {
... ... @@ -72,6 +85,68 @@ class Index extends Api
}
/**
* @ApiWeigh (87)
* @ApiTitle (选择参加的考试)
* @ApiSummary (选择参加的考试)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599018234",
"data": [{
"id": 1, //一级ID
"pid": 0,
"name": "建筑工程", //一级名称
"nickname": "", //一级昵称
"children": [{ //二级
"id": 3, //二级ID
"pid": 1, //父ID
"name": "一级建造师", //二级名称
"nickname": "" //二级昵称
}]
}]
})
*/
public function examList()
{
$list = Exam::where('pid',0)->field('id,pid,name,nickname')->select();
foreach($list as &$v){
$v['children'] = Exam::where('pid',$v['id'])->field('id,pid,name,nickname')->select();
}
$this->success('成功', $list);
}
/**
* @ApiTitle (选择考试)
* @ApiSummary (选择考试)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="exam_ids", type="string", required=true, description="考试ID,多个用英文逗号隔开")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599026313",
"data": null
})
*/
public function selectExam()
{
$user_id = $this->auth->id;
$exam_ids = $this->request->param('exam_ids');
empty($exam_ids) && $this->error('请选择考试');
UserExam::where('user_id',$user_id)->delete();
$add_data = [];
foreach (explode(',', $exam_ids) as $exam_id) {
$add_data[] = ['user_id'=>$user_id,'exam_id'=>$exam_id];
}
(new UserExam)->saveAll($add_data);
$this->success('选择考试成功');
}
/**
* @ApiTitle (报考资讯)
* @ApiSummary (报考资讯)
* @ApiMethod (POST)
... ...
... ... @@ -248,39 +248,6 @@ class User extends Api
}
/**
* @ApiWeigh (87)
* @ApiTitle (选择参加的考试)
* @ApiSummary (选择参加的考试)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599018234",
"data": [{
"id": 1, //一级ID
"pid": 0,
"name": "建筑工程", //一级名称
"nickname": "", //一级昵称
"children": [{ //二级
"id": 3, //二级ID
"pid": 1, //父ID
"name": "一级建造师", //二级名称
"nickname": "" //二级昵称
}]
}]
})
*/
public function exam()
{
$list = Exam::where('pid',0)->field('id,pid,name,nickname')->select();
foreach($list as &$v){
$v['children'] = Exam::where('pid',$v['id'])->field('id,pid,name,nickname')->select();
}
$this->success('成功', $list);
}
/**
* @ApiWeigh (85)
* @ApiTitle (暂不登录提示)
* @ApiSummary (暂不登录提示)
... ... @@ -1247,6 +1214,39 @@ class User extends Api
}
/**
* @ApiWeigh (33)
* @ApiTitle (我的求职)
* @ApiSummary (我的求职)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="problem_id", type="inter", required=true, description="问题ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600167441",
"data": {
"id": 7, //消息ID
"user_id": 16, //用户ID
"title": "这是个消息", //消息标题
"content": "这个消息还不错Q", //消息内容
"is_read": "1", //是否已读:0=否,1=是
"createtime": 1599914736,
"updatetime": 1600167441
}
})
*/
public function userJob()
{
$problem_id = $this->request->param('problem_id');
empty($problem_id) && $this->error('缺少必需参数');
$info = Problem::get($problem_id);
empty($info) && $this->error('问题不存在');
$this->success('成功', $info);
}
/**
* @ApiWeigh (10)
* @ApiTitle (常见问题)
* @ApiSummary (常见问题)
... ...
<?php
namespace app\mobile\model;
use think\Model;
class Package extends Model
{
// 表名
protected $name = 'mobile_package';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 密卷列表
public function getSecretListAttr($value,$data){
if(empty($data['secret_ids'])){
return [];
}
return Secret::where('id','in',$data['secret_ids'])->select();
}
// 课程列表
public function getCourseListAttr($value,$data){
if(empty($data['course_ids'])){
return [];
}
return Secret::where('id','in',$data['course_ids'])->select();
}
}
\ No newline at end of file
... ...
<?php
namespace app\mobile\model;
use think\Model;
use think\Db;
class PackageOrder extends Model
{
// 表名
protected $name = 'mobile_package_order';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 课程信息
public function course(){
return $this->belongsTo('Course');
}
/**
* 新增订单
*/
public function add($user, $order, $pay_type)
{
// 记录订单信息
$this->save([
'user_id' => $user['id'],
'company_id' => Company::where('user_id',$user['id'])->value('id'),
'package_id' => $order['package_info']['id'],
'order_sn' => get_order_sn(),
'pay_price' => $order['pay_price'],
'pay_type' => $pay_type,
'package_price' => $order['package_price'],
'people_num' => $order['spec_info']['people_num'],
'course_spec_id' => $order['spec_info']['id'],
'is_top' => $order['spec_info']['is_top']
]);
return true;
}
}
\ No newline at end of file
... ...
<?php
namespace app\mobile\model;
use think\Model;
class UserExam extends Model
{
// 表名
protected $name = 'mobile_user_exam';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
}
\ No newline at end of file
... ...
此 diff 太大无法显示。