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

代码修整

... ... @@ -88,7 +88,7 @@ class Company extends Api
// 当前企业下员工含管理员人数
$v['user_count'] = $user_count + 1;
$v->visible(['id','pay_price','people_num','is_top','secret'])->append(['user_count']);
$v->getRelation('secret')->visible(['title']);
$v->getRelation('secret')->visible(['id','title']);
}
$this->success('成功',$list);
}
... ... @@ -132,7 +132,7 @@ class Company extends Api
// 当前企业下员工含管理员人数
$v['user_count'] = $user_count + 1;
$v->visible(['id','pay_price','people_num','is_top','course'])->append(['user_count']);
$v->getRelation('course')->visible(['cover','title']);
$v->getRelation('course')->visible(['id','cover','title']);
}
$this->success('成功',$list);
}
... ...
... ... @@ -4,7 +4,6 @@ namespace app\mobile\controller;
use think\Validate;
use think\Db;
use app\common\controller\Api;
use app\mobile\model\Everyday as EverydayModel;
use app\mobile\model\Question;
use app\mobile\model\QuestionAnswer;
... ... @@ -20,6 +19,7 @@ class Everyday extends Api
public function _initialize()
{
parent::_initialize();
$this->model = model('app\mobile\model\Everyday');
}
/**
... ... @@ -41,7 +41,7 @@ class Everyday extends Api
*/
public function index()
{
$list = EverydayModel::where('uptime','<=',time())
$list = $this->model->where('uptime','<=',time())
->order('uptime desc')
->select();
foreach ($list as &$v) {
... ... @@ -81,7 +81,7 @@ class Everyday extends Api
$user_id = $this->auth->id;
$everyday_id = $this->request->param('everyday_id');
empty($everyday_id) && $this->error('缺少必要参数');
$info = EverydayModel::get($everyday_id);
$info = $this->model::get($everyday_id);
empty($info) && $this->error('每日一练信息不存在');
$list = Question::alias('q')
->join('mobile_question_note qn','q.id = qn.question_id and qn.user_id='.$user_id,'left')
... ... @@ -139,7 +139,7 @@ class Everyday extends Api
$user_id = $this->auth->id;
$everyday_id = $this->request->param('everyday_id');
empty($everyday_id) && $this->error('缺少必要参数');
$info = EverydayModel::get($everyday_id);
$info = $this->model->get($everyday_id);
empty($info) && $this->error('每日一练信息不存在');
$list = Question::alias('q')
->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
... ...
... ... @@ -4,7 +4,6 @@ namespace app\mobile\controller;
use think\Validate;
use think\Db;
use app\common\controller\Api;
use app\mobile\model\Old as OldModel;
use app\mobile\model\Question;
use app\mobile\model\QuestionAnswer;
use app\mobile\model\OldResult;
... ... @@ -21,6 +20,7 @@ class Old extends Api
public function _initialize()
{
parent::_initialize();
$this->model = model('app\mobile\model\Old');
}
/**
... ... @@ -46,7 +46,7 @@ class Old extends Api
{
$banner = Db::name('mobile_config')->where('id',1)->value('old_adver');
$banner = !empty($banner) ? cdnurl($banner,true) : '';
$list = OldModel::order('createtime desc')->select();
$list = $this->model->order('createtime desc')->select();
foreach ($list as $v) {
$v->visible(['id','title','do_num']);
}
... ... @@ -80,7 +80,7 @@ class Old extends Api
{
$old_id = $this->request->param('old_id');
empty($old_id) && $this->error('缺少必要参数');
$info = OldModel::get($old_id);
$info = $this->model->get($old_id);
empty($info) && $this->error('试卷信息不存在');
$info['full_score'] = Question::where('target_id',$old_id)->sum('score');
$info = $info->visible(['id','title','year','time','pass_score','goods_degree','description','do_num'])->append(['full_score']);
... ... @@ -118,7 +118,7 @@ class Old extends Api
$user_id = $this->auth->id;
$old_id = $this->request->param('old_id');
empty($old_id) && $this->error('缺少必要参数');
$info = OldModel::get($old_id);
$info = $this->model->get($old_id);
empty($info) && $this->error('试卷信息不存在');
$time = $info['time'] * 60;
$list = Question::alias('q')
... ... @@ -172,7 +172,7 @@ class Old extends Api
$user_id = $this->auth->id;
$old_id = $this->request->param('old_id');
empty($old_id) && $this->error('缺少必要参数');
$info = OldModel::get($old_id);
$info = $this->model->get($old_id);
empty($info) && $this->error('试卷信息不存在');
$list = Question::alias('q')
->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
... ... @@ -216,7 +216,7 @@ class Old extends Api
$user_id = $this->auth->id;
$old_id = $this->request->param('old_id');
empty($old_id) && $this->error('缺少必要参数');
$info = OldModel::get($old_id);
$info = $this->model->get($old_id);
empty($info) && $this->error('试卷信息不存在');
$list = Question::alias('q')
->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
... ...
... ... @@ -9,6 +9,8 @@ use app\mobile\model\SecretOrder;
use app\mobile\model\Company;
use app\mobile\model\CompanyUser;
use addons\epay\library\Service;
use app\mobile\model\Question;
use app\mobile\model\QuestionAnswer;
/**
* 密卷接口
... ... @@ -243,4 +245,58 @@ class Secret extends Api
$payment = Service::submitOrder($model['pay_price'], $model['order_sn'], $param['pay_type'], '密卷', $notifyurl, null, 'app');
$this->success('成功',$payment);
}
/**
* @ApiTitle (通关密卷-题目详情)
* @ApiSummary (通关密卷-题目详情)
* @ApiMethod (POST)
*
* @ApiParams (name="secret_id", type="int", required=true, description="密卷ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599046220",
"data": {
"total": 1, //题目总数
"list": [{ //题目列表
"id": 1, //题目ID
"title": "测定混凝土立方体抗压强度时,标准试件的尺寸是( )㎜。", //题目
"option": "[{\"name\":\"A\",\"gender\":\"100\\u00d7100\\u00d7100\"},{\"name\":\"B\",\"gender\":\"150\\u00d7150\\u00d7150\"},{\"name\":\"C\",\"gender\":\"200\\u00d7200\\u00d7200\"},{\"name\":\"D\",\"gender\":\"70.7\\u00d770.7\\u00d770.7\"}]", //题目选项
"type": "1", //题目类型:1=单选题,2=多选题,3=判断题,4=简答题
"answer": "A", //答案
"note": "45678910", //笔记
"is_collect": "1" //是否收藏:0=否,1=是
}]
}
})
*/
public function questionList()
{
$user_id = $this->auth->id;
$secret_id = $this->request->param('secret_id');
empty($secret_id) && $this->error('缺少必要参数');
$info = $this->model->get($secret_id);
empty($info) && $this->error('密卷信息不存在');
$list = Question::alias('q')
->join('mobile_question_note qn','q.id = qn.question_id and qn.user_id='.$user_id,'left')
->join('mobile_question_collect qc','q.id = qc.question_id and qn.user_id='.$user_id,'left')
->where('q.target_id',$everyday_id)
->where('q.target_type','5')
->field('
q.id,
q.title,
q.option,
q.type,
q.answer,
qn.content note,
if(qc.id > 0,1,0) is_collect
')->select();
$total = count($list);
// 删除原来的做题记录
QuestionAnswer::where('question_id','in',array_column($list, 'id'))
->where('user_id',$user_id)
->delete();
$this->success('成功',compact('total','list'));
}
}
\ No newline at end of file
... ...
... ... @@ -4,7 +4,6 @@ namespace app\mobile\controller;
use think\Validate;
use think\Db;
use app\common\controller\Api;
use app\mobile\model\Simulation as SimulationModel;
use app\mobile\model\Question;
use app\mobile\model\QuestionAnswer;
use app\mobile\model\SimulationResult;
... ... @@ -21,6 +20,7 @@ class Simulation extends Api
public function _initialize()
{
parent::_initialize();
$this->model = model('app\mobile\model\Simulation');
}
/**
... ... @@ -46,7 +46,7 @@ class Simulation extends Api
{
$banner = Db::name('mobile_config')->where('id',1)->value('simulation_adver');
$banner = !empty($banner) ? cdnurl($banner,true) : '';
$list = SimulationModel::order('createtime desc')->select();
$list = $this->model->order('createtime desc')->select();
foreach ($list as $v) {
$v->visible(['id','title','do_num']);
}
... ... @@ -80,7 +80,7 @@ class Simulation extends Api
{
$simulation_id = $this->request->param('simulation_id');
empty($simulation_id) && $this->error('缺少必要参数');
$info = SimulationModel::get($simulation_id);
$info = $this->model->get($simulation_id);
empty($info) && $this->error('试卷信息不存在');
$info['full_score'] = Question::where('target_id',$simulation_id)->sum('score');
$info = $info->visible(['id','title','year','time','pass_score','goods_degree','description','do_num'])->append(['full_score']);
... ... @@ -118,7 +118,7 @@ class Simulation extends Api
$user_id = $this->auth->id;
$simulation_id = $this->request->param('simulation_id');
empty($simulation_id) && $this->error('缺少必要参数');
$info = SimulationModel::get($simulation_id);
$info = $this->model->get($simulation_id);
empty($info) && $this->error('试卷信息不存在');
$time = $info['time'] * 60;
$list = Question::alias('q')
... ... @@ -172,7 +172,7 @@ class Simulation extends Api
$user_id = $this->auth->id;
$simulation_id = $this->request->param('simulation_id');
empty($simulation_id) && $this->error('缺少必要参数');
$info = SimulationModel::get($simulation_id);
$info = $this->model->get($simulation_id);
empty($info) && $this->error('试卷信息不存在');
$list = Question::alias('q')
->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
... ... @@ -216,7 +216,7 @@ class Simulation extends Api
$user_id = $this->auth->id;
$simulation_id = $this->request->param('simulation_id');
empty($simulation_id) && $this->error('缺少必要参数');
$info = SimulationModel::get($simulation_id);
$info = $this->model->get($simulation_id);
empty($info) && $this->error('试卷信息不存在');
$list = Question::alias('q')
->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
... ...
... ... @@ -4,7 +4,6 @@ namespace app\mobile\controller;
use think\Validate;
use think\Db;
use app\common\controller\Api;
use app\mobile\model\Topic as TopicModel;
use app\mobile\model\TopicCategory;
use app\common\model\Attachment;
... ... @@ -20,6 +19,7 @@ class Topic extends Api
public function _initialize()
{
parent::_initialize();
$this->model = model('app\mobile\model\Topic');
}
/**
... ... @@ -77,7 +77,7 @@ class Topic extends Api
empty($post['topic_category_id']) && $this->error('请选择话题分类');
empty($post['title']) && $this->error('请输入标题');
empty($post['content']) && $this->error('请填写话题内容');
TopicModel::create(array_merge([
$this->model->save(array_merge([
'user_id' => $this->auth->id
],$post),true);
$this->success('发帖成功');
... ... @@ -126,7 +126,8 @@ class Topic extends Api
$order = ['download_num' => 'desc'];
break;
}
$data = TopicModel::with(['user'])
$data = $this->model
->with(['user'])
->where($where)
->order($order)
->paginate($page_num,false,['page'=>$page])
... ... @@ -204,7 +205,8 @@ class Topic extends Api
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
empty($keyword) && $this->error('请输入关键词');
$data = TopicModel::with(['user'])
$data = $this->model
->with(['user'])
->where('title','like','%'.$keyword.'%')
->order(['hot_num'=>'desc'])
->paginate($page_num,false,['page'=>$page])
... ... @@ -243,7 +245,7 @@ class Topic extends Api
{
$topic_id = $this->request->param('topic_id');
empty($topic_id) && $this->error('缺少必要参数');
$info = TopicModel::get($topic_id,['user']);
$info = $this->model->get($topic_id,['user']);
if(!empty($info)){
$info->visible(['id','title','content','createtime','agree_num','download_num','user']);
$info->createtime = date('Y.m.d H:i',$info['createtime']);
... ...