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

数据库测试配置

... ... @@ -18,7 +18,7 @@ return [
// 服务器地址
'hostname' => Env::get('database.hostname', '1f692e5a3458475ea270448f4d3bfde5in01.internal.cn-east-2.mysql.rds.myhuaweicloud.com'),
// 数据库名
'database' => Env::get('database.database', 'enterprise'),
'database' => Env::get('database.database', 'enterprise_test'),
// 用户名
'username' => Env::get('database.username', 'db136s1ehvo1yn73'),
// 密码
... ...
<?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\common\library\Sms as Smslib;
use app\mobile\controller\Sms;
use app\mobile\model\Company;
use app\mobile\model\CompanyUser;
use app\mobile\model\Agreement;
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 addons\epay\library\Service;
/**
* 我的接口
* @ApiWeigh (66)
*/
class User extends Api
{
protected $noNeedLogin = ['registerUser','agreementUser','registerCompany','agreementCompany','login','resetpwd','exam','noLogin'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
}
/**
* @ApiWeigh (99)
* @ApiTitle (注册-个人)
* @ApiSummary (注册-个人)
* @param string $mobile 手机号
* @param string $code 验证码
* @param string $password 密码
*/
public function registerUser()
{
$mobile = $this->request->param('mobile');
$code = $this->request->param('code');
$password = $this->request->param('password');
empty($mobile) && $this->error('请输入手机号');
empty($code) && $this->error('请输入验证码');
empty($password) && $this->error('请输入密码');
!Validate::regex($mobile, "^1\d{10}$") && $this->error('手机号格式不正确');
$ret = Sms::check($mobile, $code, 'register');
!$ret && $this->error('验证码不正确');
$ret = $this->auth->register($username=$mobile, $password, $email='', $mobile, []);
if ($ret) {
$data = ['userinfo' => $this->auth->getUserinfo()];
$this->success('注册成功', $data);
} else {
$this->error($this->auth->getError());
}
}
/**
* @ApiWeigh (97)
* @ApiTitle (注册协议-个人)
* @ApiSummary (注册协议-个人)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": "用户协议内容" //协议内容
})
*/
public function agreementUser()
{
$content = Db::name('mobile_config')->where('id',1)->value('user_agreement');
$this->success('成功', $content);
}
/**
* @ApiWeigh (95)
* @ApiTitle (注册-公司)
* @ApiSummary (注册-公司)
* @param string $name 公司名称
* @param string $address 公司地址
* @param string $license 公司执照
* @param string $legal_person 法人名称
* @param string $mobile 手机号
* @param string $code 验证码
* @param string $password 密码
*/
public function registerCompany()
{
$name = $this->request->param('name');
$address = $this->request->param('address');
$license = $this->request->param('license');
$legal_person = $this->request->param('legal_person');
$mobile = $this->request->param('mobile');
$code = $this->request->param('code');
$password = $this->request->param('password');
empty($name) && $this->error('请输入公司名称');
empty($address) && $this->error('请输入地址');
empty($license) && $this->error('请上传执照');
empty($legal_person) && $this->error('请输入法人名称');
empty($mobile) && $this->error('请输入手机号');
empty($code) && $this->error('请输入验证码');
empty($password) && $this->error('请输入密码');
!Validate::regex($mobile, "^1\d{10}$") && $this->error('手机号格式不正确');
$ret = Sms::check($mobile, $code, 'register');
!$ret && $this->error('验证码不正确');
Db::startTrans();
try {
$ret = $this->auth->register($username='', $password, $email='', $mobile, ['group_id'=>1]);
if (!$ret) {
$this->error($this->auth->getError());
}
$company = Company::create([
'user_id' => $this->auth->id,
'name' => $name,
'address' => $address,
'license' => $license,
'legal_person' => $legal_person
]);
// 添加企业邀请码
$this->setInviteCode($company['id']);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->auth->logout();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->auth->logout();
$this->error($e->getMessage());
}
$this->success('注册成功', ['userinfo' => $this->auth->getUserinfo()]);
}
/**
* @ApiWeigh (93)
* @ApiTitle (注册协议-公司)
* @ApiSummary (注册协议-公司)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": "用户协议内容" //协议内容
})
*/
public function agreementCompany()
{
$content = Db::name('mobile_config')->where('id',1)->value('company_agreement');
$this->success('成功', $content);
}
/**
* @ApiWeigh (91)
* @ApiTitle (登录)
* @ApiSummary (登录)
* @param string $mobile 手机号
* @param string $password 密码
*/
public function login()
{
$mobile = $this->request->param('mobile');
$password = $this->request->param('password');
empty($mobile) && $this->error('请输入手机号');
empty($password) && $this->error('请输入密码');
!Validate::regex($mobile, "^1\d{10}$") && $this->error('手机号格式不正确');
$ret = $this->auth->login($mobile, $password);
if ($ret) {
$data = ['userinfo' => $this->auth->getUserinfo()];
$this->success('登录成功', $data);
} else {
$this->error($this->auth->getError());
}
}
/**
* @ApiWeigh (89)
* @ApiTitle (忘记密码)
* @ApiSummary (忘记密码)
*
* @param string $mobile 手机号
* @param string $newpassword 新密码
* @param string $code 验证码
*/
public function resetpwd()
{
$mobile = $this->request->request("mobile");
$code = $this->request->request("code");
$newpassword = $this->request->request("newpassword");
empty($mobile) && $this->error('请输入手机号');
empty($newpassword) && $this->error('请输入密码');
!Validate::regex($mobile, "^1\d{10}$") && $this->error('手机号格式不正确');
$user = \app\common\model\User::getByMobile($mobile);
!$user && $this->error('用户不存在');
$ret = Sms::check($mobile, $code, 'resetpwd');
!$ret && $this->error('验证码不正确');
Smslib::flush($mobile, 'resetpwd');
//模拟一次登录
$this->auth->direct($user->id);
$ret = $this->auth->changepwd($newpassword, '', true);
if ($ret) {
$this->success('重置密码成功');
} else {
$this->error($this->auth->getError());
}
}
/**
* @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 (暂不登录提示)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": "暂不登录提示内容" //暂不登录提示内容
})
*/
public function noLogin()
{
$content = Db::name('mobile_config')->where('id',1)->value('no_login');
$this->success('成功', $content);
}
/**
* @ApiWeigh (83)
* @ApiTitle (我的-首页)
* @ApiSummary (我的-首页)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": "暂不登录提示内容" //暂不登录提示内容
})
*/
public function index()
{
$user = $this->auth->getUser();
$this->success('成功', $user);
}
/**
* @ApiWeigh (81)
* @ApiTitle (我的-修改会员个人信息)
* @ApiSummary (我的-修改会员个人信息)
*
* @param string $image 头像地址
* @param string $username 用户名
* @param string $nickname 真实姓名
*/
public function profile()
{
$user = $this->auth->getUser();
$username = $this->request->param('username');
$nickname = $this->request->param('nickname');
$image = $this->request->param('image', '', 'trim,strip_tags,htmlspecialchars');
if($username || $nickname || $image) {
if ($username) {
$user->username = $username;
}
if ($nickname) {
$user->nickname = $nickname;
}
if ($image) {
$user->image = $image;
}
$user->save();
}
$this->success();
}
/**
* @ApiWeigh (79)
* @ApiTitle (修改手机号-第一步)
* @ApiSummary (修改手机号-第一步)
* @param string $code 验证码
*/
public function changemobile1()
{
$user = $this->auth->getUser();
$code = $this->request->param('code');
!$code && $this->error(__('请输入验证码'));
$ret = Sms::check($user['mobile'], $code, 'changemobile1');
!$ret && $this->error('验证码不正确');
Smslib::flush($user['mobile'], 'changemobile1');
$this->success();
}
/**
* @ApiWeigh (77)
* @ApiTitle (修改手机号-第二步)
* @ApiSummary (修改手机号-第二步)
*
* @param string $mobile 新手机号
* @param string $code 验证码
*/
public function changemobile2()
{
$user = $this->auth->getUser();
$mobile = $this->request->param('mobile');
$code = $this->request->param('code');
if (!$mobile || !$code) {
$this->error(__('Invalid parameters'));
}
if (!Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('Mobile is incorrect'));
}
if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
$this->error(__('Mobile already exists'));
}
$result = Sms::check($mobile, $code, 'changemobile2');
if (!$result) {
$this->error(__('Captcha is incorrect'));
}
$verification = $user->verification;
$verification->mobile = 1;
$user->verification = $verification;
$user->mobile = $mobile;
$user->save();
Smslib::flush($mobile, 'changemobile2');
$this->success();
}
/**
* @ApiWeigh (75)
* @ApiTitle (加入企业)
* @ApiSummary (加入企业)
*
* @param string $company_id 企业ID
* @param string $name 姓名
* @param string $mobile 手机号
* @param string $invite_code 验证码
*/
public function joinCompany()
{
$company_id = $this->request->param('company_id');
$name = $this->request->param('name');
$mobile = $this->request->param('mobile');
$invite_code = $this->request->param('invite_code');
// 验证传参
empty($company_id) && $this->error('缺少必需参数');
empty($name) && $this->error('请填写姓名');
empty($mobile) && $this->error('请填写联系方式');
empty($invite_code) && $this->error('请填写邀请码');
!Validate::regex($mobile, "^1\d{10}$") && $this->error(__('Mobile is incorrect'));
// 验证邀请码
$company = Company::where('invite_code',$invite_code)
->where('id',$company_id)
->field('id')
->find();
empty($company) && $this->error('邀请码错误,请输入正确的邀请码');
// 验证申请状态
$company_user = CompanyUser::where('company_id',$company['id'])->field('status')->find();
if($company_user){
if($company_user['status'] == '0'){
$this->error('正在申请中,请勿重复提交申请');
}
if($company_user['status'] == '1'){
$this->error('加入企业成功,请勿重复提交申请');
}
}
CompanyUser::create([
'user_id' => $this->auth->id,
'company_id' => $company_id,
'name' => $name,
'mobile' => $mobile
]);
$this->success('已成功提交,请提醒企业管理员及时审核');
}
/**
* 更新企业邀请码
* @param string $company_id 企业ID
*/
private function setInviteCode($company_id){
$code = mt_rand(100000,999999);
$find = Company::where('invite_code',$code)->field('id')->find();
if(!$find){
Company::where('id',$company_id)->setField('invite_code',$code);
return true;
}else{
$this->setInviteCode($company_id);
}
}
/**
* @ApiWeigh (73)
* @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", //实际支付金额
"course": { //课程信息
"title": "测试课程", //课程标题
"cover": "" //课程封面图
},
"is_have_qi": 0 //是否有企字:0=否,1=是
}]
})
*/
public function myCourse(){
// 我加入的企业购买的课程
$company_course_list = CourseOrder::alias('co')
->join('mobile_company_user cu','cu.company_id = co.company_id')
->where('cu.user_id',$this->auth->id)
->where('cu.status','1')
->field('co.id,co.company_id,co.people_num')
->select();
// 查询我是否可以享受企业课程(按企业审核时间排队,没在队伍里就无法享受企业课程)
$course_id_arr = [];
foreach ($company_course_list as $v) {
$user_id_arr = CompanyUser::where('company_id',$v['company_id'])
->where('status','1')
->order('updatetime asc')
->limit($v['people_num'])
->column('user_id');
if(in_array($this->auth->id,$user_id_arr)){
$course_id_arr[] = $v['id'];
}
}
// 查找所有课程
$list = CourseOrder::with(['course'])
->where(function($query)use($course_id_arr){
$query->where('user_id', $this->auth->id)->whereor('id', 'in', $course_id_arr);
})
->where('pay_status','1')
->select();
foreach ($list as $v) {
$v['is_have_qi'] = in_array($v['id'], $course_id_arr) ? 1 : 0;
$v->visible(['id','pay_price','course'])->append(['is_have_qi']);
$v->getRelation('course')->visible(['cover','title']);
}
$this->success('成功',$list);
}
/**
* @ApiWeigh (71)
* @ApiTitle (我的课程-评价页面)
* @ApiSummary (我的课程-评价页面)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="course_order_id", type="int", required=true, description="课程订单ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600084253",
"data": {
"id": 10, //课程订单ID
"pay_price": "50.00", //实际支付金额
"course": { //课程信息
"title": "测试课程", //课程标题
"cover": "" //课程封面图
},
"is_have_qi": 0 //是否有企字:0=否,1=是
}
})
*/
public function appraiseView(){
$course_order_id = $this->request->param('course_order_id');
empty($course_order_id) && $this->error('缺少必需参数');
$info = CourseOrder::get($course_order_id,['course']);
empty($info) && $this->error('课程订单不存在');
$user_id_arr = CompanyUser::where('company_id',$info['company_id'])
->where('status','1')
->order('updatetime asc')
->limit($info['people_num'])
->column('user_id');
$info['is_have_qi'] = in_array($this->auth->id,$user_id_arr) ? 1 : 0;
$info->visible(['id','pay_price','course'])->append(['is_have_qi']);
$info->getRelation('course')->visible(['cover','title']);
$this->success('成功',$info);
}
/**
* @ApiWeigh (69)
* @ApiTitle (我的课程-评价)
* @ApiSummary (我的课程-评价)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="course_order_id", type="int", required=true, description="课程订单ID")
* @ApiParams (name="star", type="int", required=true, description="评价星数")
* @ApiParams (name="content", type="int", required=true, description="评价内容")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600084253",
"data": null
})
*/
public function appraise(){
$course_order_id = $this->request->param('course_order_id');
$star = $this->request->param('star');
$content = $this->request->param('content');
empty($course_order_id) && $this->error('缺少必需参数');
empty($star) && $this->error('请选择星数');
empty($content) && $this->error('请填写评价内容');
$info = CourseOrder::get($course_order_id,['course']);
empty($info) && $this->error('课程订单不存在');
CourseAppraise::create([
'user_id' => $this->auth->id,
'course_id' => $info['course_id'],
'course_order_id' => $info['id'],
'star' => $star,
'content' => $content
]);
$this->success('评价成功');
}
/**
* @ApiWeigh (67)
* @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", //实际支付金额
"secret": { //密卷信息
"title": "测试密卷", //密卷标题
"do_num": "" //做过人数
},
"is_have_qi": 0 //是否有企字:0=否,1=是
}]
})
*/
public function mySecret(){
// 我加入的企业购买的密卷
$company_secret_list = SecretOrder::alias('a')
->join('mobile_company_user b','b.company_id = a.company_id')
->where('b.user_id',$this->auth->id)
->where('b.status','1')
->field('a.id,a.company_id,a.people_num')
->select();
// 查询我是否可以享受企业密卷(按企业审核时间排队,没在队伍里就无法享受企业密卷)
$secret_id_arr = [];
foreach ($company_secret_list as $v) {
$user_id_arr = CompanyUser::where('company_id',$v['company_id'])
->where('status','1')
->order('updatetime asc')
->limit($v['people_num'])
->column('user_id');
if(in_array($this->auth->id,$user_id_arr)){
$secret_id_arr[] = $v['id'];
}
}
// 查找所有密卷
$list = SecretOrder::with(['secret'])
->where(function($query)use($secret_id_arr){
$query->where('user_id', $this->auth->id)->whereor('id', 'in', $secret_id_arr);
})
->where('pay_status','1')
->select();
foreach ($list as $v) {
$v['is_have_qi'] = in_array($v['id'], $secret_id_arr) ? 1 : 0;
$v->visible(['id','pay_price','secret'])->append(['is_have_qi']);
$v->getRelation('secret')->visible(['cover','title']);
}
$this->success('成功',$list);
}
/**
* @ApiWeigh (65)
* @ApiTitle (我的积分)
* @ApiSummary (我的积分)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600135095",
"data": {
"id": 16, //用户ID
"score": 0, //当前积分
"url": "/u/16",
"max_score": 0 //累计积分
}
})
*/
public function myScore(){
$user = $this->auth->getUser();
$user['max_score'] = db('user_score_log')->where('user_id',$user['id'])->max('after');
$user = $user->visible(['id','score'])->append(['max_score'])->toArray();
$this->success('成功',$user);
}
/**
* @ApiWeigh (63)
* @ApiTitle (积分说明)
* @ApiSummary (积分说明)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": "积分说明" //积分说明内容
})
*/
public function scoreIntro()
{
$content = Db::name('mobile_config')->where('id',1)->value('user_score_intro');
$this->success('成功', $content);
}
/**
* @ApiWeigh (61)
* @ApiTitle (积分记录)
* @ApiSummary (积分记录)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": "积分说明" //积分说明内容
})
*/
public function scoreLog()
{
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
$list = \app\common\model\ScoreLog::where('user_id',$this->auth->id)
->order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v['createtime'] = date('Y.m.d H:i',$v['createtime']);
})->toArray();
$this->success('成功', ['total'=>$data['total'],'list'=>$data['data']]);
}
/**
* @ApiWeigh (59)
* @ApiTitle (海报分享)
* @ApiSummary (海报分享)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": "积分说明" //积分说明内容
})
*/
public function share()
{
$content = Db::name('mobile_config')->where('id',1)->value('user_score_intro');
$this->success('成功', $content);
}
/**
* @ApiWeigh (57)
* @ApiTitle (充值积分-套餐)
* @ApiSummary (充值积分-套餐)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": "积分说明" //积分说明内容
})
*/
public function scoreSpec()
{
$list = ScoreSpec::select();
$score_recharge_price = Db::name('mobile_config')->where('id',1)->value('score_recharge_price');
$this->success('成功', compact('list','score_recharge_price'));
}
/**
* @ApiWeigh (55)
* @ApiTitle (积分充值预览)
* @ApiSummary (积分充值预览)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="score_spec_id", type="int", required=false, description="套餐ID")
* @ApiParams (name="score", type="int", required=false, description="自定义积分")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599046220",
"data": {
"id": 1, //试卷ID
"title": "测试试卷", //试卷标题
"year": 2015, //年费(单位:年)
"time": 100, //答题时间(单位:分)
"pass_score": 80, //合格分数
"description": "这个还行", //试卷描述
"do_num": 10, //回答人数
"full_score": 100 //试卷分数(单位:分)
}
})
*/
public function scoreRechargeView()
{
$param = $this->request->param();
$model = new ScoreOrder;
if(!$order = $model->payView($this->auth->getUser(),$param)){
$this->error($model->getError(),null,$this->model->getCode());
}
$this->success(__('成功'),$order);
}
/**
* @ApiWeigh (53)
* @ApiTitle (充值积分)
* @ApiSummary (充值积分)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="score_spec_id", type="int", required=false, description="积分套餐ID")
* @ApiParams (name="score", type="int", required=false, description="自定义积分")
* @ApiParams (name="pay_type", type="string", required=true, description="支付方式:wechat=微信,alipay=支付宝")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": "积分说明" //积分说明内容
})
*/
public function scoreRecharge()
{
$param = $this->request->param();
$model = new ScoreOrder;
if(!$order = $model->payView($this->auth->getUser(),$param)){
$this->error($model->getError(),null,$this->model->getCode());
}
if (!$param['pay_type'] || !in_array($param['pay_type'], ['alipay', 'wechat'])) {
$this->error("请选择支付方式");
}
// 创建订单
$model->add($this->auth->getUser(), $order, $param['pay_type']);
//回调链接
$notifyurl = $this->request->root(true) . '/mobile/notify/notifyScore/paytype/' . $param['pay_type'];
$payment = Service::submitOrder($model['pay_price'], $model['order_sn'], $param['pay_type'], '积分', $notifyurl, null, 'app');
$this->success('成功',$payment);
}
/**
* @ApiWeigh (51)
* @ApiTitle (我的收藏-题目)
* @ApiSummary (我的收藏-题目)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600162242",
"data": {
"total": 1, // 题目总数
"list": [{
"id": 1,
"user_id": 16, //用户ID
"question_id": 1, //题目ID
"createtime": "2020.09.03 19:25", //收藏时间
"question": { //题目信息
"title": "测定混凝土立方体抗压强度时,标准试件的尺寸是( )㎜。", //题目
"type": "1" //题目类型:1=单选题,2=多选题,3=判断题,4=简答题
}
}]
}
})
*/
public function collectQuestionList()
{
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
$data = QuestionCollect::with(['question'])
->where('user_id',$this->auth->id)
->order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v['createtime'] = date('Y.m.d H:i',$v['createtime']);
$v->getRelation('question')->visible(['title','type']);
})->toArray();
$this->success('成功', ['total'=>$data['total'],'list'=>$data['data']]);
}
/**
* @ApiWeigh (49)
* @ApiTitle (我的收藏-课程)
* @ApiSummary (我的收藏-课程)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600164731",
"data": {
"total": 1, //数据总数
"list": [{
"id": 1,
"user_id": 16, //用户ID
"course_id": 1, //课程ID
"createtime": "2020.09.03 19:25", //收藏时间
"course": { //课程信息
"title": "测试课程", //课程标题
"cover": "", //课程封面图
"current_price": "50.00", //现价
"original_price": "100.00" //原价
}
}]
}
})
*/
public function collectCourseList()
{
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
$data = CourseCollect::with(['course'])
->where('user_id',$this->auth->id)
->order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v['createtime'] = date('Y.m.d H:i',$v['createtime']);
$v->getRelation('course')->visible(['cover','title','current_price','original_price','study_num']);
})->toArray();
$this->success('成功', ['total'=>$data['total'],'list'=>$data['data']]);
}
/**
* @ApiWeigh (47)
* @ApiTitle (我的收藏-笔记)
* @ApiSummary (我的收藏-笔记)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600165190",
"data": {
"total": 1, //数据总数
"list": [{
"id": 3, //笔记ID
"user_id": 16, //用户ID
"question_id": 5, //题目ID
"content": "这就是街舞", //笔记内容
"createtime": "2020.09.10 19:15", //收藏时间
"updatetime": 1599736531,
"question": { //题目信息
"title": "测试多选", //题目标题
"type": "2" //题目类型:1=单选题,2=多选题,3=判断题,4=简答题
}
}]
}
})
*/
public function collectNoteList()
{
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
$data = QuestionNote::with(['question'])
->where('user_id',$this->auth->id)
->order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v['createtime'] = date('Y.m.d H:i',$v['createtime']);
$v->getRelation('question')->visible(['title','type']);
})->toArray();
$this->success('成功', ['total'=>$data['total'],'list'=>$data['data']]);
}
/**
* @ApiWeigh (45)
* @ApiTitle (我的收藏-笔记-删除)
* @ApiSummary (我的收藏-笔记-删除)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="question_note_id", type="inter", required=false, description="当前页(默认1)")
*
* @ApiReturn({
"code": 1,
"msg": "删除成功",
"time": "1600165190",
"data": null
})
*/
public function noteDelete()
{
$question_note_id = $this->request->param('question_note_id');
empty($question_note_id) && $this->error('缺少必需参数');
$info = QuestionNote::get($question_note_id);
empty($info) && $this->error('笔记信息不存在');
$info->delete();
$this->success('删除成功');
}
/**
* @ApiWeigh (43)
* @ApiTitle (消息)
* @ApiSummary (消息)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600167138",
"data": {
"total": 1, //数据总数
"list": [{
"id": 7, //消息ID
"title": "这是个消息", //消息标题
"createtime": "2020.09.12 20:45" //发送时间
}]
}
})
*/
public function messageList()
{
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
$data = Message::where('user_id',$this->auth->id)
->order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v['createtime'] = date('Y.m.d H:i',$v['createtime']);
$v->visible(['id','title','createtime']);
})->toArray();
$this->success('成功', ['total'=>$data['total'],'list'=>$data['data']]);
}
/**
* @ApiWeigh (43)
* @ApiTitle (消息-详情)
* @ApiSummary (消息-详情)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="message_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 messageInfo()
{
$message_id = $this->request->param('message_id');
empty($message_id) && $this->error('缺少必需参数');
$info = Message::get($message_id);
empty($info) && $this->error('消息不存在');
$info->save(['is_read'=>'1']);
$this->success('成功', $info);
}
/**
* @ApiWeigh (41)
* @ApiTitle (意见反馈-错误类型)
* @ApiSummary (意见反馈-错误类型)
* @ApiMethod (POST)
*
* @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 feedbackWrong()
{
$list = Db::name('mobile_feedback_wrong')->field('id,name')->select();
$this->success('成功', $list);
}
/**
* @ApiWeigh (39)
* @ApiTitle (意见反馈)
* @ApiSummary (意见反馈)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="feedback_wrong_id", type="inter", required=true, description="错误类型ID")
* @ApiParams (name="content", type="string", required=true, description="反馈内容")
*
* @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 feedback()
{
$feedback_wrong_id = $this->request->param('feedback_wrong_id');
$content = $this->request->param('content');
empty($feedback_wrong_id) && $this->error('请选择错误类型');
empty($content) && $this->error('请填写反馈内容');
Feedback::create([
'user_id' => $this->auth->id,
'feedback_wrong_id' => $feedback_wrong_id,
'content' => $content
]);
$this->success('反馈成功');
}
/**
* @ApiWeigh (37)
* @ApiTitle (我的帖子)
* @ApiSummary (我的帖子)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="feedback_wrong_id", type="inter", required=true, description="错误类型ID")
* @ApiParams (name="content", type="string", required=true, description="反馈内容")
*
* @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 topicList()
{
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
$data = Topic::with(['user'])
->where('user_id',$this->auth->id)
->order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v->visible(['id','title','content','createtime','agree_num','download_num','user']);
$v->createtime = date('Y.m.d H:i',$v['createtime']);
$v->getRelation('user')->visible(['user_id','avatar','nickname']);
})->toArray();
$this->success('成功', ['total'=>$data['total'],'list'=>$data['data']]);
}
/**
* @ApiWeigh (35)
* @ApiTitle (我的帖子-@我的)
* @ApiSummary (我的帖子-@我的)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @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 topicCueMe()
{
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
$data = Topic::with(['user'])
->where('user_id',$this->auth->id)
->order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v->visible(['id','title','content','createtime','agree_num','download_num','user']);
$v->createtime = date('Y.m.d H:i',$v['createtime']);
$v->getRelation('user')->visible(['user_id','avatar','nickname']);
})->toArray();
$this->success('成功', ['total'=>$data['total'],'list'=>$data['data']]);
}
/**
* @ApiWeigh (10)
* @ApiTitle (常见问题)
* @ApiSummary (常见问题)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1600167138",
"data": {
"total": 1, //数据总数
"list": [{
"id": 7, //消息ID
"title": "这是个消息", //消息标题
"createtime": "2020.09.12 20:45" //发送时间
}]
}
})
*/
public function problemList()
{
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
$data = Problem::where('user_id',$this->auth->id)
->order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v['createtime'] = date('Y.m.d H:i',$v['createtime']);
$v->visible(['id','title','createtime']);
})->toArray();
$this->success('成功', ['total'=>$data['total'],'list'=>$data['data']]);
}
/**
* @ApiWeigh (9)
* @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 problemInfo()
{
$problem_id = $this->request->param('problem_id');
empty($problem_id) && $this->error('缺少必需参数');
$info = Problem::get($problem_id);
empty($info) && $this->error('问题不存在');
$this->success('成功', $info);
}
}
\ No newline at end of file
... ...
... ... @@ -288,4 +288,32 @@ class Topic extends Api
{
$topic_id = $this->request->param('topic_id');
}
/**
* @ApiTitle (评论)
* @ApiSummary (评论)
* @ApiMethod (POST)
*
* @ApiParams (name="topic_id", type="int", required=true, description="话题ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599046220",
"data": {
"id": 1, //试卷ID
"title": "测试试卷", //试卷标题
"year": 2015, //年费(单位:年)
"time": 100, //答题时间(单位:分)
"pass_score": 80, //合格分数
"description": "这个还行", //试卷描述
"do_num": 10, //回答人数
"full_score": 100 //试卷分数(单位:分)
}
})
*/
public function download()
{
$topic_id = $this->request->param('topic_id');
}
}
\ No newline at end of file
... ...