作者 何书鹏
1 个管道 的构建 失败 耗费 1 秒

1

<?php
namespace app\mobile\controller;
use think\Validate;
use think\Db;
use app\common\controller\Api;
use app\mobile\model\Class as ClassModel;
use app\mobile\model\ClassBanner;
use app\mobile\model\ClassCatalog;
use app\mobile\model\ClassAppraise;
/**
* 课程接口
*/
class Class extends Api
{
protected $noNeedLogin = ['banner','index','info','catalog','appraiseList'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
}
/**
* @ApiTitle (课程-轮播图)
* @ApiSummary (课程-轮播图)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599201246",
"data": [{
"id": 1, //密卷名称
"title": "测试密卷", //密卷标题
"do_num": 20, //做过人数
"current_price": "10.00", //现价
"original_price": "10000.00" //原价
}]
})
*/
public function banner()
{
$list = ClassBanner::order('createtime desc')->field('id,image')->select();
$this->success('成功',$list);
}
/**
* @ApiTitle (论坛-首页)
* @ApiSummary (论坛-首页)
* @ApiMethod (POST)
* @ApiParams (name="forum_category_id", type="inter", required=false, description="话题分类ID")
* @ApiParams (name="order", type="inter", required=false, description="排序方式:0=综合排序,1=按学习人数,2=价格从低到高,3=价格从高到低")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599201246",
"data": [{
"id": 1, //密卷名称
"title": "测试密卷", //密卷标题
"do_num": 20, //做过人数
"current_price": "10.00", //现价
"original_price": "10000.00" //原价
}]
})
*/
public function index()
{
$order = $this->request->param('order',0);
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
switch ($order) {
case 0:
$order = ['is_top' => 'desc','top_time' => 'desc'];
break;
case 1:
$order = ['study_num' => 'desc'];
break;
case 2:
$order = ['current_price' => 'asc'];
break;
case 3:
$order = ['current_price' => 'desc'];
break;
}
$data = ClassModel::where($where)
->field("
id,
title,
cover,
current_price,
original_price,
(study_num_virtua + study_num_real) study_num
")
->order($order)
->paginate($page_num,false,['page'=>$page])
->toArray();
$this->success('成功',['total'=>$data['total'],'list'=>$data['list']]);
}
/**
* @ApiTitle (课程详情)
* @ApiSummary (课程详情)
* @ApiMethod (POST)
*
* @ApiParams (name="class_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 info()
{
$class_id = $this->request->param('class_id');
empty($class_id) && $this->error('缺少必要参数');
$info = ClassModel::get($class_id);
// 课程视频
// 第一节目录
$catalog_parent = ClassCatalog::where('class_id',$class_id)
->where('pid',0)
->order('weigh asc')
->find();
// 第一节目录下的第一课程
$catalog_child = ClassCatalog::where('class_id',$class_id)
->where('pid',$catalog_parent['id'])
->order('weigh asc')
->find();
$video = '';
if(!empty($catalog_parent) && !empty($catalog_child)){
$video = $catalog_child['video'];
}
$info['video'] = $video;
$this->success('成功',);
}
/**
* @ApiTitle (课程详情-目录)
* @ApiSummary (课程详情-目录)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="class_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 catalog()
{
$class_id = $this->request->param('class_id');
empty($class_id) && $this->error('缺少必要参数');
$list = ClassCatalog::where('class_id',$class_id)
->where('pid',0)
->field('id,name')
->order('weigh asc')
->select();
foreach ($list as &$v) {
$childlist = ClassCatalog::where('pid',$v['id'])
->where('class_id',$class_id)
->order('weigh asc')
->select();
foreach ($childlist as $val) {
$val->visible(['id','name','video']);
}
$v['childlist'] = $childlist;
}
$this->success('成功',$list);
}
/**
* @ApiTitle (课程详情-评价)
* @ApiSummary (课程详情-评价)
* @ApiMethod (POST)
*
* @ApiParams (name="class_id", type="int", required=true, description="课程ID")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @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 appraiseList()
{
$class_id = $this->request->param('class_id');
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
empty($class_id) && $this->error('缺少必要参数');
$data = ClassAppraise::with(['user'])
->where('class_id',$class_id)
->order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v->visible(['id','star','content','createtime','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['list']]);
}
/**
* @ApiTitle (下载)
* @ApiSummary (下载)
* @ApiMethod (POST)
*
* @ApiParams (name="forum_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()
{
$forum_id = $this->request->param('forum_id');
}
}
\ No newline at end of file
... ...
... ... @@ -125,17 +125,16 @@ class Forum extends Api
$order = ['download_num' => 'desc'];
break;
}
$list = ForumModel::with(['user'])
$data = ForumModel::with(['user'])
->where($where)
->order($order)
->page($page,$page_num)
->select();
foreach ($list as $v) {
->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']);
}
$this->success('成功',$list);
})->toArray();
$this->success('成功',['total'=>$data['total'],'list'=>$data['list']]);
}
/**
... ... @@ -204,17 +203,16 @@ class Forum extends Api
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
empty($keyword) && $this->error('请输入关键词');
$list = ForumModel::with(['user'])
->where($order)
$data = ForumModel::with(['user'])
->where('title','like','%'.$keyword.'%')
->order(['hot_num'=>'desc'])
->page($page,$page_num)
->select();
foreach ($list as $v) {
->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']);
}
$this->success('成功',$list);
})->toArray();
$this->success('成功',['total'=>$data['total'],'list'=>$data['list']]);
}
/**
... ...
... ... @@ -71,6 +71,39 @@ class Index extends Api
}
/**
* @ApiTitle (报考资讯)
* @ApiSummary (报考资讯)
* @ApiMethod (POST)
*
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599026840",
"data": {
"id": 1, //资讯ID
"title": "关于建造师", //资讯标题
"content": "关于建造师内容", //资讯内容
"createtime": "1970.01.01", //发布时间
"read_num": 120 //阅读量
}
})
*/
public function newsList()
{
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
$data = News::order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v->visible(['id','cover','title','read_num','createtime']);
})->toArray();
$this->success('成功',['total'=>$data['total'],'list'=>$data['data']]);
}
/**
* @ApiTitle (资讯详情)
* @ApiSummary (资讯详情)
* @ApiMethod (POST)
... ...
... ... @@ -19,13 +19,13 @@ class Sms extends Api
* 发送验证码
*
* @param string $mobile 手机号
* @param string $event 事件名称
* @param string $event 事件名称:register=注册,resetpwd=忘记密码,changemobile1=修改手机号第一步,changemobile2=修改手机号第二步,changepwd=修改密码
*/
public function send()
{
$mobile = $this->request->get("mobile");
$event = $this->request->get("event");
$event = $event ? $event : 'changemobile';
$event = $event ? $event : 'register';
if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('手机号不正确'));
}
... ... @@ -39,9 +39,15 @@ class Sms extends Api
}
if ($event) {
$userinfo = User::getByMobile($mobile);
if ($event == 'changemobile' && $userinfo) {
if ($event == 'register' && $userinfo) {
//已被注册
$this->error(__('已被注册'));
} elseif (in_array($event, ['changemobile2']) && $userinfo) {
//被占用
$this->error(__('已被占用'));
} elseif (in_array($event, ['changepwd', 'resetpwd', 'changemobile1']) && !$userinfo) {
//未注册
$this->error(__('未注册'));
}
}
$ret = $this->getCode($mobile, null, $event);
... ...
... ... @@ -65,7 +65,8 @@ class User extends Api
*/
public function agreementUser()
{
$this->success('成功', Agreement::where('id',1)->value('content'));
$content = Db::name('mobile_config')->where('id',1)->value('user_agreement');
$this->success('成功', $content);
}
/**
... ... @@ -129,7 +130,8 @@ class User extends Api
*/
public function agreementCompany()
{
$this->success('成功', Agreement::where('id',2)->value('content'));
$content = Db::name('mobile_config')->where('id',1)->value('company_agreement');
$this->success('成功', $content);
}
/**
... ... @@ -233,6 +235,102 @@ class User extends Api
*/
public function noLogin()
{
$this->success('成功', Agreement::where('id',3)->value('content'));
$content = Db::name('mobile_config')->where('id',1)->value('no_login');
$this->success('成功', $content);
}
/**
* @ApiTitle (我的-首页)
* @ApiSummary (我的-首页)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": "暂不登录提示内容" //暂不登录提示内容
})
*/
public function index()
{
$user = $this->auth->getUser();
$this->success('成功', $content);
}
/**
* 修改会员个人信息
*
* @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();
}
/**
* 修改手机号-第一步
* @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();
}
/**
* 修改手机号-第二步
*
* @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();
}
}
\ No newline at end of file
... ...
<?php
namespace app\mobile\model;
use think\Model;
class Class extends Model
{
// 表名
protected $name = 'mobile_class';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
public function getImageAttr($value){
return !empty($value) ? cdnurl($value,true) : '';
}
}
\ No newline at end of file
... ...
<?php
namespace app\mobile\model;
use think\Model;
class ClassAppraise extends Model
{
// 表名
protected $name = 'mobile_class_appraise';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
}
\ No newline at end of file
... ...
<?php
namespace app\mobile\model;
use think\Model;
class ClassBanner extends Model
{
// 表名
protected $name = 'mobile_class_banner';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
public function getImageAttr($value){
return !empty($value) ? cdnurl($value,true) : '';
}
}
\ No newline at end of file
... ...
<?php
namespace app\mobile\model;
use think\Model;
class ClassCatalog extends Model
{
// 表名
protected $name = 'mobile_class_catalog';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
public function getVideoAttr($value){
return !empty($value) ? cdnurl($value,true) : '';
}
}
\ No newline at end of file
... ...