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

1

  1 +<?php
  2 +namespace app\mobile\controller;
  3 +
  4 +use think\Validate;
  5 +use think\Db;
  6 +use app\common\controller\Api;
  7 +use app\mobile\model\Class as ClassModel;
  8 +use app\mobile\model\ClassBanner;
  9 +use app\mobile\model\ClassCatalog;
  10 +use app\mobile\model\ClassAppraise;
  11 +
  12 +/**
  13 + * 课程接口
  14 + */
  15 +class Class extends Api
  16 +{
  17 + protected $noNeedLogin = ['banner','index','info','catalog','appraiseList'];
  18 + protected $noNeedRight = ['*'];
  19 +
  20 + public function _initialize()
  21 + {
  22 + parent::_initialize();
  23 + }
  24 +
  25 + /**
  26 + * @ApiTitle (课程-轮播图)
  27 + * @ApiSummary (课程-轮播图)
  28 + * @ApiMethod (POST)
  29 + *
  30 + * @ApiReturn({
  31 + "code": 1,
  32 + "msg": "成功",
  33 + "time": "1599201246",
  34 + "data": [{
  35 + "id": 1, //密卷名称
  36 + "title": "测试密卷", //密卷标题
  37 + "do_num": 20, //做过人数
  38 + "current_price": "10.00", //现价
  39 + "original_price": "10000.00" //原价
  40 + }]
  41 + })
  42 + */
  43 + public function banner()
  44 + {
  45 + $list = ClassBanner::order('createtime desc')->field('id,image')->select();
  46 + $this->success('成功',$list);
  47 + }
  48 +
  49 + /**
  50 + * @ApiTitle (论坛-首页)
  51 + * @ApiSummary (论坛-首页)
  52 + * @ApiMethod (POST)
  53 + * @ApiParams (name="forum_category_id", type="inter", required=false, description="话题分类ID")
  54 + * @ApiParams (name="order", type="inter", required=false, description="排序方式:0=综合排序,1=按学习人数,2=价格从低到高,3=价格从高到低")
  55 + * @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
  56 + * @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
  57 + * @ApiReturn({
  58 + "code": 1,
  59 + "msg": "成功",
  60 + "time": "1599201246",
  61 + "data": [{
  62 + "id": 1, //密卷名称
  63 + "title": "测试密卷", //密卷标题
  64 + "do_num": 20, //做过人数
  65 + "current_price": "10.00", //现价
  66 + "original_price": "10000.00" //原价
  67 + }]
  68 + })
  69 + */
  70 + public function index()
  71 + {
  72 + $order = $this->request->param('order',0);
  73 + $page = $this->request->param('page', 1, 'intval');
  74 + $page_num = $this->request->param('page_num', 10, 'intval');
  75 + switch ($order) {
  76 + case 0:
  77 + $order = ['is_top' => 'desc','top_time' => 'desc'];
  78 + break;
  79 + case 1:
  80 + $order = ['study_num' => 'desc'];
  81 + break;
  82 + case 2:
  83 + $order = ['current_price' => 'asc'];
  84 + break;
  85 + case 3:
  86 + $order = ['current_price' => 'desc'];
  87 + break;
  88 + }
  89 + $data = ClassModel::where($where)
  90 + ->field("
  91 + id,
  92 + title,
  93 + cover,
  94 + current_price,
  95 + original_price,
  96 + (study_num_virtua + study_num_real) study_num
  97 + ")
  98 + ->order($order)
  99 + ->paginate($page_num,false,['page'=>$page])
  100 + ->toArray();
  101 + $this->success('成功',['total'=>$data['total'],'list'=>$data['list']]);
  102 + }
  103 +
  104 + /**
  105 + * @ApiTitle (课程详情)
  106 + * @ApiSummary (课程详情)
  107 + * @ApiMethod (POST)
  108 + *
  109 + * @ApiParams (name="class_id", type="int", required=true, description="课程ID")
  110 + *
  111 + * @ApiReturn({
  112 + "code": 1,
  113 + "msg": "成功",
  114 + "time": "1599046220",
  115 + "data": {
  116 + "id": 1, //试卷ID
  117 + "title": "测试试卷", //试卷标题
  118 + "year": 2015, //年费(单位:年)
  119 + "time": 100, //答题时间(单位:分)
  120 + "pass_score": 80, //合格分数
  121 + "description": "这个还行", //试卷描述
  122 + "do_num": 10, //回答人数
  123 + "full_score": 100 //试卷分数(单位:分)
  124 + }
  125 + })
  126 + */
  127 + public function info()
  128 + {
  129 + $class_id = $this->request->param('class_id');
  130 + empty($class_id) && $this->error('缺少必要参数');
  131 + $info = ClassModel::get($class_id);
  132 + // 课程视频
  133 + // 第一节目录
  134 + $catalog_parent = ClassCatalog::where('class_id',$class_id)
  135 + ->where('pid',0)
  136 + ->order('weigh asc')
  137 + ->find();
  138 + // 第一节目录下的第一课程
  139 + $catalog_child = ClassCatalog::where('class_id',$class_id)
  140 + ->where('pid',$catalog_parent['id'])
  141 + ->order('weigh asc')
  142 + ->find();
  143 + $video = '';
  144 + if(!empty($catalog_parent) && !empty($catalog_child)){
  145 + $video = $catalog_child['video'];
  146 + }
  147 + $info['video'] = $video;
  148 + $this->success('成功',);
  149 + }
  150 +
  151 + /**
  152 + * @ApiTitle (课程详情-目录)
  153 + * @ApiSummary (课程详情-目录)
  154 + * @ApiMethod (POST)
  155 + *
  156 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  157 + * @ApiParams (name="class_id", type="int", required=true, description="课程ID")
  158 + *
  159 + * @ApiReturn({
  160 + "code": 1,
  161 + "msg": "成功",
  162 + "time": "1599046220",
  163 + "data": {
  164 + "id": 1, //试卷ID
  165 + "title": "测试试卷", //试卷标题
  166 + "year": 2015, //年费(单位:年)
  167 + "time": 100, //答题时间(单位:分)
  168 + "pass_score": 80, //合格分数
  169 + "description": "这个还行", //试卷描述
  170 + "do_num": 10, //回答人数
  171 + "full_score": 100 //试卷分数(单位:分)
  172 + }
  173 + })
  174 + */
  175 + public function catalog()
  176 + {
  177 + $class_id = $this->request->param('class_id');
  178 + empty($class_id) && $this->error('缺少必要参数');
  179 + $list = ClassCatalog::where('class_id',$class_id)
  180 + ->where('pid',0)
  181 + ->field('id,name')
  182 + ->order('weigh asc')
  183 + ->select();
  184 + foreach ($list as &$v) {
  185 + $childlist = ClassCatalog::where('pid',$v['id'])
  186 + ->where('class_id',$class_id)
  187 + ->order('weigh asc')
  188 + ->select();
  189 + foreach ($childlist as $val) {
  190 + $val->visible(['id','name','video']);
  191 + }
  192 + $v['childlist'] = $childlist;
  193 + }
  194 + $this->success('成功',$list);
  195 + }
  196 +
  197 + /**
  198 + * @ApiTitle (课程详情-评价)
  199 + * @ApiSummary (课程详情-评价)
  200 + * @ApiMethod (POST)
  201 + *
  202 + * @ApiParams (name="class_id", type="int", required=true, description="课程ID")
  203 + * @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
  204 + * @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
  205 + *
  206 + * @ApiReturn({
  207 + "code": 1,
  208 + "msg": "成功",
  209 + "time": "1599046220",
  210 + "data": {
  211 + "id": 1, //试卷ID
  212 + "title": "测试试卷", //试卷标题
  213 + "year": 2015, //年费(单位:年)
  214 + "time": 100, //答题时间(单位:分)
  215 + "pass_score": 80, //合格分数
  216 + "description": "这个还行", //试卷描述
  217 + "do_num": 10, //回答人数
  218 + "full_score": 100 //试卷分数(单位:分)
  219 + }
  220 + })
  221 + */
  222 + public function appraiseList()
  223 + {
  224 + $class_id = $this->request->param('class_id');
  225 + $page = $this->request->param('page', 1, 'intval');
  226 + $page_num = $this->request->param('page_num', 10, 'intval');
  227 + empty($class_id) && $this->error('缺少必要参数');
  228 + $data = ClassAppraise::with(['user'])
  229 + ->where('class_id',$class_id)
  230 + ->order('createtime desc')
  231 + ->paginate($page_num,false,['page'=>$page])
  232 + ->each(function($v){
  233 + $v->visible(['id','star','content','createtime','user']);
  234 + $v->createtime = date('Y.m.d H:i',$v['createtime']);
  235 + $v->getRelation('user')->visible(['user_id','avatar','nickname']);
  236 + })->toArray();
  237 + $this->success('成功',['total'=>$data['total'],'list'=>$data['list']]);
  238 + }
  239 +
  240 + /**
  241 + * @ApiTitle (下载)
  242 + * @ApiSummary (下载)
  243 + * @ApiMethod (POST)
  244 + *
  245 + * @ApiParams (name="forum_id", type="int", required=true, description="话题ID")
  246 + *
  247 + * @ApiReturn({
  248 + "code": 1,
  249 + "msg": "成功",
  250 + "time": "1599046220",
  251 + "data": {
  252 + "id": 1, //试卷ID
  253 + "title": "测试试卷", //试卷标题
  254 + "year": 2015, //年费(单位:年)
  255 + "time": 100, //答题时间(单位:分)
  256 + "pass_score": 80, //合格分数
  257 + "description": "这个还行", //试卷描述
  258 + "do_num": 10, //回答人数
  259 + "full_score": 100 //试卷分数(单位:分)
  260 + }
  261 + })
  262 + */
  263 + public function download()
  264 + {
  265 + $forum_id = $this->request->param('forum_id');
  266 + }
  267 +}
@@ -125,17 +125,16 @@ class Forum extends Api @@ -125,17 +125,16 @@ class Forum extends Api
125 $order = ['download_num' => 'desc']; 125 $order = ['download_num' => 'desc'];
126 break; 126 break;
127 } 127 }
128 - $list = ForumModel::with(['user']) 128 + $data = ForumModel::with(['user'])
129 ->where($where) 129 ->where($where)
130 ->order($order) 130 ->order($order)
131 - ->page($page,$page_num)  
132 - ->select();  
133 - foreach ($list as $v) { 131 + ->paginate($page_num,false,['page'=>$page])
  132 + ->each(function($v){
134 $v->visible(['id','title','content','createtime','agree_num','download_num','user']); 133 $v->visible(['id','title','content','createtime','agree_num','download_num','user']);
135 $v->createtime = date('Y.m.d H:i',$v['createtime']); 134 $v->createtime = date('Y.m.d H:i',$v['createtime']);
136 $v->getRelation('user')->visible(['user_id','avatar','nickname']); 135 $v->getRelation('user')->visible(['user_id','avatar','nickname']);
137 - }  
138 - $this->success('成功',$list); 136 + })->toArray();
  137 + $this->success('成功',['total'=>$data['total'],'list'=>$data['list']]);
139 } 138 }
140 139
141 /** 140 /**
@@ -204,17 +203,16 @@ class Forum extends Api @@ -204,17 +203,16 @@ class Forum extends Api
204 $page = $this->request->param('page', 1, 'intval'); 203 $page = $this->request->param('page', 1, 'intval');
205 $page_num = $this->request->param('page_num', 10, 'intval'); 204 $page_num = $this->request->param('page_num', 10, 'intval');
206 empty($keyword) && $this->error('请输入关键词'); 205 empty($keyword) && $this->error('请输入关键词');
207 - $list = ForumModel::with(['user'])  
208 - ->where($order) 206 + $data = ForumModel::with(['user'])
  207 + ->where('title','like','%'.$keyword.'%')
209 ->order(['hot_num'=>'desc']) 208 ->order(['hot_num'=>'desc'])
210 - ->page($page,$page_num)  
211 - ->select();  
212 - foreach ($list as $v) { 209 + ->paginate($page_num,false,['page'=>$page])
  210 + ->each(function($v){
213 $v->visible(['id','title','content','createtime','agree_num','download_num','user']); 211 $v->visible(['id','title','content','createtime','agree_num','download_num','user']);
214 $v->createtime = date('Y.m.d H:i',$v['createtime']); 212 $v->createtime = date('Y.m.d H:i',$v['createtime']);
215 $v->getRelation('user')->visible(['user_id','avatar','nickname']); 213 $v->getRelation('user')->visible(['user_id','avatar','nickname']);
216 - }  
217 - $this->success('成功',$list); 214 + })->toArray();
  215 + $this->success('成功',['total'=>$data['total'],'list'=>$data['list']]);
218 } 216 }
219 217
220 /** 218 /**
@@ -71,6 +71,39 @@ class Index extends Api @@ -71,6 +71,39 @@ class Index extends Api
71 } 71 }
72 72
73 /** 73 /**
  74 + * @ApiTitle (报考资讯)
  75 + * @ApiSummary (报考资讯)
  76 + * @ApiMethod (POST)
  77 + *
  78 + * @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
  79 + * @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
  80 + *
  81 + * @ApiReturn({
  82 + "code": 1,
  83 + "msg": "成功",
  84 + "time": "1599026840",
  85 + "data": {
  86 + "id": 1, //资讯ID
  87 + "title": "关于建造师", //资讯标题
  88 + "content": "关于建造师内容", //资讯内容
  89 + "createtime": "1970.01.01", //发布时间
  90 + "read_num": 120 //阅读量
  91 + }
  92 + })
  93 + */
  94 + public function newsList()
  95 + {
  96 + $page = $this->request->param('page', 1, 'intval');
  97 + $page_num = $this->request->param('page_num', 10, 'intval');
  98 + $data = News::order('createtime desc')
  99 + ->paginate($page_num,false,['page'=>$page])
  100 + ->each(function($v){
  101 + $v->visible(['id','cover','title','read_num','createtime']);
  102 + })->toArray();
  103 + $this->success('成功',['total'=>$data['total'],'list'=>$data['data']]);
  104 + }
  105 +
  106 + /**
74 * @ApiTitle (资讯详情) 107 * @ApiTitle (资讯详情)
75 * @ApiSummary (资讯详情) 108 * @ApiSummary (资讯详情)
76 * @ApiMethod (POST) 109 * @ApiMethod (POST)
@@ -19,13 +19,13 @@ class Sms extends Api @@ -19,13 +19,13 @@ class Sms extends Api
19 * 发送验证码 19 * 发送验证码
20 * 20 *
21 * @param string $mobile 手机号 21 * @param string $mobile 手机号
22 - * @param string $event 事件名称 22 + * @param string $event 事件名称:register=注册,resetpwd=忘记密码,changemobile1=修改手机号第一步,changemobile2=修改手机号第二步,changepwd=修改密码
23 */ 23 */
24 public function send() 24 public function send()
25 { 25 {
26 $mobile = $this->request->get("mobile"); 26 $mobile = $this->request->get("mobile");
27 $event = $this->request->get("event"); 27 $event = $this->request->get("event");
28 - $event = $event ? $event : 'changemobile'; 28 + $event = $event ? $event : 'register';
29 if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) { 29 if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
30 $this->error(__('手机号不正确')); 30 $this->error(__('手机号不正确'));
31 } 31 }
@@ -39,9 +39,15 @@ class Sms extends Api @@ -39,9 +39,15 @@ class Sms extends Api
39 } 39 }
40 if ($event) { 40 if ($event) {
41 $userinfo = User::getByMobile($mobile); 41 $userinfo = User::getByMobile($mobile);
42 - if ($event == 'changemobile' && $userinfo) { 42 + if ($event == 'register' && $userinfo) {
43 //已被注册 43 //已被注册
  44 + $this->error(__('已被注册'));
  45 + } elseif (in_array($event, ['changemobile2']) && $userinfo) {
  46 + //被占用
44 $this->error(__('已被占用')); 47 $this->error(__('已被占用'));
  48 + } elseif (in_array($event, ['changepwd', 'resetpwd', 'changemobile1']) && !$userinfo) {
  49 + //未注册
  50 + $this->error(__('未注册'));
45 } 51 }
46 } 52 }
47 $ret = $this->getCode($mobile, null, $event); 53 $ret = $this->getCode($mobile, null, $event);
@@ -65,7 +65,8 @@ class User extends Api @@ -65,7 +65,8 @@ class User extends Api
65 */ 65 */
66 public function agreementUser() 66 public function agreementUser()
67 { 67 {
68 - $this->success('成功', Agreement::where('id',1)->value('content')); 68 + $content = Db::name('mobile_config')->where('id',1)->value('user_agreement');
  69 + $this->success('成功', $content);
69 } 70 }
70 71
71 /** 72 /**
@@ -129,7 +130,8 @@ class User extends Api @@ -129,7 +130,8 @@ class User extends Api
129 */ 130 */
130 public function agreementCompany() 131 public function agreementCompany()
131 { 132 {
132 - $this->success('成功', Agreement::where('id',2)->value('content')); 133 + $content = Db::name('mobile_config')->where('id',1)->value('company_agreement');
  134 + $this->success('成功', $content);
133 } 135 }
134 136
135 /** 137 /**
@@ -233,6 +235,102 @@ class User extends Api @@ -233,6 +235,102 @@ class User extends Api
233 */ 235 */
234 public function noLogin() 236 public function noLogin()
235 { 237 {
236 - $this->success('成功', Agreement::where('id',3)->value('content')); 238 + $content = Db::name('mobile_config')->where('id',1)->value('no_login');
  239 + $this->success('成功', $content);
  240 + }
  241 +
  242 + /**
  243 + * @ApiTitle (我的-首页)
  244 + * @ApiSummary (我的-首页)
  245 + * @ApiMethod (POST)
  246 + *
  247 + * @ApiReturn({
  248 + "code": 1,
  249 + "msg": "成功",
  250 + "time": "1599017563",
  251 + "data": "暂不登录提示内容" //暂不登录提示内容
  252 + })
  253 + */
  254 + public function index()
  255 + {
  256 + $user = $this->auth->getUser();
  257 + $this->success('成功', $content);
  258 + }
  259 +
  260 + /**
  261 + * 修改会员个人信息
  262 + *
  263 + * @param string $image 头像地址
  264 + * @param string $username 用户名
  265 + * @param string $nickname 真实姓名
  266 + */
  267 + public function profile()
  268 + {
  269 + $user = $this->auth->getUser();
  270 + $username = $this->request->param('username');
  271 + $nickname = $this->request->param('nickname');
  272 + $image = $this->request->param('image', '', 'trim,strip_tags,htmlspecialchars');
  273 + if($username || $nickname || $image) {
  274 + if ($username) {
  275 + $user->username = $username;
  276 + }
  277 + if ($nickname) {
  278 + $user->nickname = $nickname;
  279 + }
  280 + if ($image) {
  281 + $user->image = $image;
  282 + }
  283 + $user->save();
  284 + }
  285 + $this->success();
  286 + }
  287 +
  288 + /**
  289 + * 修改手机号-第一步
  290 + * @param string $code 验证码
  291 + */
  292 + public function changemobile1()
  293 + {
  294 + $user = $this->auth->getUser();
  295 + $code = $this->request->param('code');
  296 + !$code && $this->error(__('请输入验证码'));
  297 + $ret = Sms::check($user['mobile'], $code, 'changemobile1');
  298 + !$ret && $this->error('验证码不正确');
  299 + Smslib::flush($user['mobile'], 'changemobile1');
  300 + $this->success();
  301 + }
  302 +
  303 + /**
  304 + * 修改手机号-第二步
  305 + *
  306 + * @param string $mobile 新手机号
  307 + * @param string $code 验证码
  308 + */
  309 + public function changemobile2()
  310 + {
  311 + $user = $this->auth->getUser();
  312 + $mobile = $this->request->param('mobile');
  313 + $code = $this->request->param('code');
  314 + if (!$mobile || !$code) {
  315 + $this->error(__('Invalid parameters'));
  316 + }
  317 + if (!Validate::regex($mobile, "^1\d{10}$")) {
  318 + $this->error(__('Mobile is incorrect'));
  319 + }
  320 + if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  321 + $this->error(__('Mobile already exists'));
  322 + }
  323 + $result = Sms::check($mobile, $code, 'changemobile2');
  324 + if (!$result) {
  325 + $this->error(__('Captcha is incorrect'));
  326 + }
  327 + $verification = $user->verification;
  328 + $verification->mobile = 1;
  329 + $user->verification = $verification;
  330 + $user->mobile = $mobile;
  331 + $user->save();
  332 +
  333 + Smslib::flush($mobile, 'changemobile2');
  334 + $this->success();
237 } 335 }
238 } 336 }
  1 +<?php
  2 +namespace app\mobile\model;
  3 +
  4 +use think\Model;
  5 +
  6 +class Class extends Model
  7 +{
  8 + // 表名
  9 + protected $name = 'mobile_class';
  10 + // 开启自动写入时间戳字段
  11 + protected $autoWriteTimestamp = 'int';
  12 + // 定义时间戳字段名
  13 + protected $createTime = 'createtime';
  14 + protected $updateTime = 'updatetime';
  15 +
  16 + public function getImageAttr($value){
  17 + return !empty($value) ? cdnurl($value,true) : '';
  18 + }
  19 +}
  1 +<?php
  2 +namespace app\mobile\model;
  3 +
  4 +use think\Model;
  5 +
  6 +class ClassAppraise extends Model
  7 +{
  8 + // 表名
  9 + protected $name = 'mobile_class_appraise';
  10 + // 开启自动写入时间戳字段
  11 + protected $autoWriteTimestamp = 'int';
  12 + // 定义时间戳字段名
  13 + protected $createTime = 'createtime';
  14 + protected $updateTime = 'updatetime';
  15 +}
  1 +<?php
  2 +namespace app\mobile\model;
  3 +
  4 +use think\Model;
  5 +
  6 +class ClassBanner extends Model
  7 +{
  8 + // 表名
  9 + protected $name = 'mobile_class_banner';
  10 + // 开启自动写入时间戳字段
  11 + protected $autoWriteTimestamp = 'int';
  12 + // 定义时间戳字段名
  13 + protected $createTime = 'createtime';
  14 + protected $updateTime = 'updatetime';
  15 +
  16 + public function getImageAttr($value){
  17 + return !empty($value) ? cdnurl($value,true) : '';
  18 + }
  19 +}
  1 +<?php
  2 +namespace app\mobile\model;
  3 +
  4 +use think\Model;
  5 +
  6 +class ClassCatalog extends Model
  7 +{
  8 + // 表名
  9 + protected $name = 'mobile_class_catalog';
  10 + // 开启自动写入时间戳字段
  11 + protected $autoWriteTimestamp = 'int';
  12 + // 定义时间戳字段名
  13 + protected $createTime = 'createtime';
  14 + protected $updateTime = 'updatetime';
  15 +
  16 + public function getVideoAttr($value){
  17 + return !empty($value) ? cdnurl($value,true) : '';
  18 + }
  19 +}