审查视图

application/api/controller/Lists.php 30.9 KB
杨育虎 authored
1 2 3 4 5
<?php

namespace app\api\controller;

use app\common\controller\Api;
杨育虎 authored
6
use think\Cookie;
杨育虎 authored
7
use app\common\library\Auth;
杨育虎 authored
8
use think\Db;
杨育虎 authored
9 10 11 12
use fast\Random;
use think\Session;
use think\Cache;
use think\Validate;
杨育虎 authored
13 14

/**
杨育虎 authored
15
 * 各种列表以及详情接口
杨育虎 authored
16 17 18
 */
class Lists extends Api
{
杨育虎 authored
19
    protected $noNeedLogin = ['get_list','type_title','type_list','ke_list','index','policy','index_info','policy_info','video_list','video_detail','study','password_login','find_pwd','getcode','verify'];
杨育虎 authored
20 21 22 23 24 25 26 27
    protected $noNeedRight = ['*'];

    /**
     * @ApiTitle    (通知公告列表)
     * @ApiSummary  (通知公告列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/index)
     *
杨育虎 authored
28 29
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
杨育虎 authored
30
     * @ApiParams   (name="keyword", type="string", required=false, description="搜索关键字")
杨育虎 authored
31
     *
杨育虎 authored
32 33 34 35 36
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
杨育虎 authored
37 38 39 40 41 42 43 44 45 46
          "total_num"://总条数
          "info":[
                "id"://ID
                "title"://标题
                "is_up"://是否上架0否1是
                 "file_name"://附件名称
                "createtime"://创建时间
                 "desc"://简介
          ]
杨育虎 authored
47 48 49 50 51
    }
    })
     */
    public function index()
    {
杨育虎 authored
52 53 54 55 56 57
        $keyword = $this->request->param('keyword');
        if(empty($keyword)){
            $where = true;
        }else{
            $where['title'] = ['like',"%$keyword%"];
        }
杨育虎 authored
58 59
        $page = $this->request->param('page', 1, 'intval');
        $pageNum = $this->request->param('pageNum', 10, 'intval');
杨育虎 authored
60 61 62 63 64 65 66 67

        $data['total_num'] = Db::name('information')
            ->where($where)
            ->count();

        $data['info'] = Db::name('information')
            ->field('id,title,is_up,desc,createtime')
            ->where($where)
杨育虎 authored
68
            ->order('is_up desc,createtime desc')
杨育虎 authored
69
            ->page($page,$pageNum)
杨育虎 authored
70
            ->select();
杨育虎 authored
71
        foreach ($data['info'] as &$v){
杨育虎 authored
72 73 74 75 76 77
            $v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
        }
        $this->success('success',$data);
    }

    /**
杨育虎 authored
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
     * @ApiTitle    (搜索)
     * @ApiSummary  (搜索)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/sou)
     *
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
     * @ApiParams   (name="keyword", type="string", required=false, description="搜索关键字")
     * @ApiParams   (name="type", type="inter", required=false, description="类型1通知公告2优选课程3培训课程")
     * @ApiParams   (name="id", type="inter", required=false, description="学习系统id")
     * 
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "total_num"://总条数
    "info":[

    ]

    }
    })
     */
    public function sou()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $user_id = $this->auth->id;
        $page = $this->request->param('page', 1, 'intval');
        $pageNum = $this->request->param('pageNum', 10, 'intval');

        $type = $this->request->param('type');
        if(empty($type)){
            $this->error('缺少必要参数');
        }

        $keyword = $this->request->param('keyword');
        if(empty($keyword)){
            $this->error('请输入关键字');
        }

        if($type == 1){
            $data['total_num'] = Db::name('information')
                ->where('title','like',"%$keyword%")
                ->count();

            $data['info'] = Db::name('information')
                ->field('id,title,is_up,desc,createtime')
                ->where('title','like',"%$keyword%")
                ->order('is_up desc,createtime desc')
                ->page($page,$pageNum)
                ->select();
            foreach ($data['info'] as &$v){
                $v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
            }
            $this->success('success',$data);
        }elseif ($type == 2){
            $data['total_num'] = Db::name('optimization')
                ->where('title','like',"%$keyword%")
                ->count();

            $data['info'] = Db::name('optimization')
                ->where('title','like',"%$keyword%")
                ->order('createtime desc')
                ->page($page,$pageNum)
                ->select();
            foreach ($data['info'] as &$v){
                // 获取视频时长
                $video_avinfo = json_decode(file_get_contents(cdnurl($v['video_file'], true) . '?avinfo'), true); // 获取视频元信息
                $duration = ceil($video_avinfo['format']['duration']);
                $v['duration'] = gmdate('H:i:s',$duration);
                $v['image'] = $qiniu.$v['image'];
                $v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
            }
            $this->success('success',$data);
        }elseif ($type == 3){
            $id = $this->request->param('id');
            if(empty($id)){
                $this->error('学习系统id不能为空');
            }

            $data['total_num'] = Db::name('classes')
                ->where('name','like',"%$keyword%")
                ->count();
            $data['info'] = Db::name('classes')
                ->field('createtime,updatetime',true)
                ->where('name','like',"%$keyword%")
                ->page($page,$pageNum)
                ->order('id desc')
                ->select();
            foreach ($data['info'] as &$v){
                $v['video_file'] = $qiniu.$v['video_file'];
                $video_info = json_decode(file_get_contents($v['video_file'] . '?avinfo'), true);
                $v['video_image'] = $this->get_video_first_image( $v['video_file'], $video_info);
            }
            $this->success('success',$data);
        }else{
            $this->error('类型错误');
        }
    }
    public function get_video_first_image($video_url,$video_info){
        if(empty($video_info['streams'][0]['width'])) {
            $width = $video_info['streams'][1]['width'];
            $height = $video_info['streams'][1]['height'];
        } else {
            $width = $video_info['streams'][0]['width'];
            $height = $video_info['streams'][0]['height'];
        }
        return $video_url.'?vframe/jpg/offset/1/w/'.$width.'/h/'.$height;
    }

    /**
杨育虎 authored
190 191 192 193 194
     * @ApiTitle    (政策动态列表)
     * @ApiSummary  (政策动态列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/policy)
     *
杨育虎 authored
195 196 197
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
     *
杨育虎 authored
198 199 200 201 202
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
杨育虎 authored
203 204
    "total_num"://总条数
    "info":[
杨育虎 authored
205
    "id"://ID
杨育虎 authored
206
    "file_name"://附件名称
杨育虎 authored
207 208 209
    "title"://标题
    "is_up"://是否上架0否1是
    "createtime"://创建时间
杨育虎 authored
210
    ]
杨育虎 authored
211 212 213 214 215
    }
    })
     */
    public function policy()
    {
杨育虎 authored
216 217
        $page = $this->request->param('page', 1, 'intval');
        $pageNum = $this->request->param('pageNum', 10, 'intval');
杨育虎 authored
218 219 220 221
        $data['total_num'] = Db::name('policy')
            ->count();
        $data['info'] = Db::name('policy')
            ->field('id,title,is_up,desc,createtime')
杨育虎 authored
222
            ->order('is_up desc,createtime desc')
杨育虎 authored
223
            ->page($page,$pageNum)
杨育虎 authored
224
            ->select();
杨育虎 authored
225
        foreach ($data['info'] as &$v){
杨育虎 authored
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
            $v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
        }
        $this->success('success',$data);
    }

    /**
     * @ApiTitle    (通知公告详情)
     * @ApiSummary  (通知公告详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/index_info)
     *
     * @ApiParams   (name="id", type="int", required=true, description="公告ID")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id"://ID
    "title"://标题
    "from"://转载于
    "content"://内容详情
杨育虎 authored
248
    "file_name"://附件名称
杨育虎 authored
249 250 251 252 253 254 255 256
    "file"://附件
    "is_up"://是否上架0否1是
    "createtime"://创建时间
    }
    })
     */
    public function index_info()
    {
杨育虎 authored
257
        $qiniu = get_addon_config('qiniu')['cdnurl'];
杨育虎 authored
258 259 260 261 262 263 264 265
        $id = $this->request->param('id');
        if(empty($id)){
            $this->error('缺少必要参数');
        }
        $data = Db::name('information')
            ->where('id',$id)
            ->field('updatetime',true)
            ->find();
杨育虎 authored
266 267 268 269 270 271 272 273 274 275 276 277 278
        if(!empty($data['file'])){
            $base_url = $data['file'];
            $qiniu_url = $qiniu.$data['file'];
            $a = file_get_contents($qiniu_url);
            $path = './uploads/'.explode('/',$base_url)[2].'/';
            if(!file_exists($path)) {
                mkdir($path,0777,true);
            }
            file_put_contents('.'.$base_url,$a);
            $data['file'] = request()->domain().$base_url;
        }else{
            $data['file'] = '';
        }
杨育虎 authored
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
        $data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
        $this->success('success',$data);
    }

    /**
     * @ApiTitle    (政策动态详情)
     * @ApiSummary  (政策动态详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/policy_info)
     *
     * @ApiParams   (name="id", type="int", required=true, description="政策动态ID")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id"://ID
    "title"://标题
    "from"://转载于
    "content"://内容详情
杨育虎 authored
300
    "file_name"://附件名称
杨育虎 authored
301 302 303 304 305 306 307 308
    "file"://附件
    "is_up"://是否上架0否1是
    "createtime"://创建时间
    }
    })
     */
    public function policy_info()
    {
杨育虎 authored
309
        $qiniu = get_addon_config('qiniu')['cdnurl'];
杨育虎 authored
310 311 312 313 314 315 316 317
        $id = $this->request->param('id');
        if(empty($id)){
            $this->error('缺少必要参数');
        }
        $data = Db::name('policy')
            ->where('id',$id)
            ->field('updatetime',true)
            ->find();
杨育虎 authored
318 319 320 321 322 323 324 325 326 327 328 329 330
        if(!empty($data['file'])){
            $base_url = $data['file'];
            $qiniu_url = $qiniu.$data['file'];
            $a = file_get_contents($qiniu_url);
            $path = './uploads/'.explode('/',$base_url)[2].'/';
            if(!file_exists($path)) {
                mkdir($path,0777,true);
            }
            file_put_contents('.'.$base_url,$a);
            $data['file'] = request()->domain().$base_url;
        }else{
            $data['file'] = '';
        }
杨育虎 authored
331 332 333 334 335 336 337 338 339 340
        $data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
        $this->success('success',$data);
    }

    /**
     * @ApiTitle    (优选课程列表)
     * @ApiSummary  (优选课程列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/video_list)
     *
杨育虎 authored
341 342 343
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
     *
杨育虎 authored
344 345 346 347 348
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
杨育虎 authored
349 350 351 352 353 354 355 356 357
          "total_num"://总条数
          "info":[
                 "id"://ID
                "title"://标题
                "desc"://简介
                "content"://内容详情
                "image"://图片
                "createtime"://创建时间
          ]
杨育虎 authored
358 359 360 361 362
    }
    })
     */
    public function video_list()
    {
杨育虎 authored
363 364
        $page = $this->request->param('page', 1, 'intval');
        $pageNum = $this->request->param('pageNum', 10, 'intval');
杨育虎 authored
365
        $qiniu = get_addon_config('qiniu')['cdnurl'];
杨育虎 authored
366 367 368
        $data['total_num'] = Db::name('optimization')
            ->count();
        $data['info'] = Db::name('optimization')
杨育虎 authored
369 370
            ->field('id,title,image,desc,createtime,video_file')
            ->order('createtime desc')
杨育虎 authored
371
            ->page($page,$pageNum)
杨育虎 authored
372
            ->select();
杨育虎 authored
373
        foreach ($data['info'] as &$v){
杨育虎 authored
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
            // 获取视频时长
            $video_avinfo = json_decode(file_get_contents(cdnurl($v['video_file'], true) . '?avinfo'), true); // 获取视频元信息
            $duration = ceil($video_avinfo['format']['duration']);
            $v['duration'] = gmdate('H:i:s',$duration);
            $v['image'] = $qiniu.$v['image'];
            $v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
        }
        $this->success('success',$data);
    }

    /**
     * @ApiTitle    (优选课程详情)
     * @ApiSummary  (优选课程详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/video_detail)
     *
     * @ApiParams   (name="id", type="int", required=true, description="优选课程ID")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id"://ID
    "title"://标题
    "desc"://简介
    "content"://内容详情
    "video_file"://视频信息
    "image"://图片
    "createtime"://创建时间
    }
    })
     */
    public function video_detail()
    {
        $id = $this->request->param('id');
        if(empty($id)){
            $this->error('缺少必要参数');
        }
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $data = Db::name('optimization')
            ->where('id',$id)
            ->find();
        $data['image'] = $qiniu.$data['image'];
        $data['video_file'] = $qiniu.$data['video_file'];

        // 获取视频时长
        $video_avinfo = json_decode(file_get_contents(cdnurl($data['video_file'], true) . '?avinfo'), true); // 获取视频元信息
        $duration = ceil($video_avinfo['format']['duration']);
        $data['duration'] = gmdate('H:i:s',$duration);
杨育虎 authored
425 426 427
        $data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
        $this->success('success',$data);
    }
杨育虎 authored
428 429 430 431 432 433 434 435 436 437

    /**
     * @ApiTitle    (学习系统)
     * @ApiSummary  (学习系统)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/study)
     *
     *
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
杨育虎 authored
438
     * @ApiParams   (name="type_id", type="inter", required=false, description="分类id")
杨育虎 authored
439 440 441 442 443 444
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
杨育虎 authored
445 446 447 448 449 450 451 452 453 454
          "total_num"://总条数
          "info":[
                "id"://ID
                "examname"://考试名称
                "class_hour"://所需课时
                "finish_hour"://完成课时
                "image"://图片
                "expirationtime"://截止日期
          ]
杨育虎 authored
455 456 457 458 459
    }
    })
     */
    public function study()
    {
杨育虎 authored
460 461 462 463 464 465 466 467 468 469 470 471
        $type_id = $this->request->param('type_id');
        $erzi = Db::name('type')->where('id',$type_id)->field('id,pid')->select();
        if(!empty($erzi)){
            $erzi_id = array_column($erzi,"id");
            $sunzi = Db::name('type')->where(['pid'=>['in',$erzi_id]])->field("id")->select();
            $sunzi_id = array_column($sunzi,"id");
            $son = array_merge($sunzi_id,$erzi_id);
            array_push($son,$type_id);
            $where['type_id'] = ['in',$son];
        }else{
            $where['type_id'] = ['eq',$type_id];
        }
杨育虎 authored
472 473 474 475 476
        $page = $this->request->param('page', 1, 'intval');
        $pageNum = $this->request->param('pageNum', 10, 'intval');
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $user_id = Session::get('user_id');
        $where['expirationtime'] = ['>',time()];
杨育虎 authored
477 478 479 480
        $data['total_num'] = Db::name('study')
            ->where($where)
            ->count();
        $data['info'] = Db::name('study')
杨育虎 authored
481 482 483 484 485
            ->field('updatetime,createtime',true)
            ->where($where)
            ->order('id desc')
            ->page($page,$pageNum)
            ->select();
杨育虎 authored
486
        foreach ($data['info'] as &$v){
杨育虎 authored
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
            if(empty($user_id)){
                $v['finish_hour'] = 0;
            }else{
                $finish_hour = Db::name('study_class')
                    ->alias('a')
                    ->join('classes b','a.class_id = b.id')
                    ->where('a.third_id',$user_id)
                    ->where('a.study_id',$v['id'])
                    ->where('a.status',2)
                    ->field('sum(b.class_hour) as finsh_hour')
                    ->find();
                if(empty($finish_hour['finsh_hour'])){
                    $v['finish_hour'] = 0;
                }else{
                    $v['finish_hour'] = $finish_hour['finsh_hour'];
                }
杨育虎 authored
503
                
杨育虎 authored
504 505 506 507 508 509 510 511 512 513 514 515 516
            }
            $v['image'] = $qiniu.$v['image'];
            $v['expirationtime'] = date('Y-m-d H:i:s',$v['expirationtime']);
        }
        $this->success('success',$data);
    }

    /**
     * @ApiTitle    (查看用户是否有权限)
     * @ApiSummary  (查看用户是否有权限)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/study_detail)
     *
杨育虎 authored
517
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
杨育虎 authored
518 519 520 521 522 523 524 525 526 527 528 529
     * @ApiParams   (name="id", type="int", required=true, description="学习系统id")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    }
    })
     */
    public function study_detail()
    {
杨育虎 authored
530
        $user_id = $this->auth->id;
杨育虎 authored
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
        $id = $this->request->param('id');
        if(empty($id)){
            $this->error('缺少必要参数');
        }
        $third_study = Db::name('third_study')->where('third_id',$user_id)->where('study_id',$id)->find();
        if(empty($third_study)){
            $this->error('您没有该场考试的权限');
        }else{
            $this->success('success');
        }
    }



    /**
     * @ApiTitle    (账号密码登录)
     * @ApiSummary  (账号密码登录)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/password_login)
     *
     * @ApiParams   (name="username", type="string", required=true, description="用户名")
     * @ApiParams   (name="password", type="string", required=true, description="密码")
杨育虎 authored
553
     * @ApiParams   (name="type", type="inter", required=false, description="是否记住账号密码 为空或者1否2是")
杨育虎 authored
554 555 556 557 558 559 560 561 562 563 564
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    ]
    }
    })
     */
    public function password_login(){
杨育虎 authored
565 566 567

        $type = $this->request->param('type');
杨育虎 authored
568 569 570 571 572 573
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $username = $this->request->param('username');
        $password = $this->request->param('password');
        if(empty($username) || empty($password)){
            $this->error('缺少必要参数');
        }
杨育虎 authored
574
        $result = Db::name('user')->where('username',$username)->find();
杨育虎 authored
575 576 577 578 579 580
        if(empty($result)){
            $this->error('账号错误');
        }
        if($result['password'] != $password){
            $this->error('密码错误');
        }
杨育虎 authored
581
        $user = Db::name('user')->where(['id'=>$result['id']])->find();
杨育虎 authored
582 583 584 585 586 587 588 589 590 591 592
        if($user['expirationtime'] < time()){
            $this->error('抱歉,有效期已过');
        }
        if(!empty($user['image'])){
            $user['image'] = $qiniu.$user['image'];
        }else{
            $user['image'] = '';
        }
        if(empty($user['nickname'])){
            $user['nickname'] = '';
        }
杨育虎 authored
593 594 595 596 597 598 599 600 601 602

        $auth =  Auth::instance();
        $this->auth->direct($user['id']);

        $userInfo = $auth->getUserinfo();
        $userInfo['image'] = $user['image'];
        unset($userInfo['avatar']);
        unset($userInfo['score']);
        unset($userInfo['mobile']);
        $this->success('SUCCESS',$userInfo);
杨育虎 authored
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
    }

    /**
     * @ApiTitle    (找回密码)
     * @ApiSummary  (找回密码)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/find_pwd)
     *
     * @ApiParams   (name="phone", type="string", required=true, description="手机号")
     * @ApiParams   (name="code", type="string", required=true, description="验证码")
     * @ApiParams   (name="new_password", type="string", required=true, description="新密码")
     * @ApiParams   (name="re_pwd", type="string", required=true, description="确认密码")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    ]
    }
    })
     */
    public function find_pwd()
    {
        $phone = $this->request->param('phone');
        $code = $this->request->param('code');
        $new_password = $this->request->param('new_password');
        $re_pwd = $this->request->param('re_pwd');
        if(empty($phone) || empty($code) || empty($new_password) || empty($re_pwd)){
            $this->error('缺少必要参数');
        }

        if($new_password != $re_pwd){
            $this->error('两次密码不一致,请重新输入');
        }
杨育虎 authored
639
        $result1 = Db::name('user')->where('phone',$phone)->find();
杨育虎 authored
640 641 642 643 644 645 646 647 648
        if(empty($result1)){
            $this->error('该手机号暂无绑定账号');
        }

        //验证手机号验证码是否正确
        $yuancode = Cache::get($phone);
        if($code != $yuancode){
            $this->error('验证码错误或者失效,请重新发送');
        }
杨育虎 authored
649 650

        $data = Db::name('user')->where('id',$result1['id'])->update(['password'=>$new_password]);
杨育虎 authored
651 652 653 654 655 656 657 658 659 660 661 662 663
        if(empty($data)){
            $this->error('修改失败');
        }else{
            $this->success('success');
        }
    }

    /**
     * @ApiTitle    (修改密码)
     * @ApiSummary  (修改密码)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/edit_pwd)
     *
杨育虎 authored
664 665
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
杨育虎 authored
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
     * @ApiParams   (name="pwd", type="string", required=true, description="密码")
     * @ApiParams   (name="new_password", type="string", required=true, description="新密码")
     * @ApiParams   (name="re_pwd", type="string", required=true, description="确认密码")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    ]
    }
    })
     */
    public function edit_pwd()
    {
杨育虎 authored
681
        $user_id = $this->auth->id;
杨育虎 authored
682 683 684 685 686 687 688 689 690
        $username = $this->request->param('username');
        $pwd = $this->request->param('pwd');
        $new_password = $this->request->param('new_password');
        $re_pwd = $this->request->param('re_pwd');

        if(empty($username) || empty($pwd) || empty($new_password) || empty($re_pwd)){
            $this->error('缺少必要参数');
        }
杨育虎 authored
691 692
        $userinfo = Db::name('user')->where('id',$user_id)->find();
        if($userinfo['password'] != $pwd){
杨育虎 authored
693 694 695 696 697 698
            $this->error('您的密码不正确');
        }

        if($new_password != $re_pwd){
            $this->error('两次密码不一致');
        }
杨育虎 authored
699
        $data = Db::name('user')->where('id',$user_id)->update(['password'=>$new_password]);
杨育虎 authored
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
        if(empty($data)){
            $this->error('修改失败');
        }else{
            $this->success('修改成功');
        }
    }


    /**
     * @ApiTitle    (获取验证码)
     * @ApiSummary  (获取验证码)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/getcode)
     *
     * @ApiParams   (name="mobile", type="string", required=false, description="手机号")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1553839125",
    "data": {

    }
    })
     */
    public function getcode()
    {
        $phone = $this->request->param('mobile');
        if (empty($phone)) {
            $this->error(['code' => 40005, 'msg' => '手机号不能为空']);
        }
        if (!preg_match('/^1[0-9]{10}$/', $phone)) {
            $this->error(['code' => 40005, 'msg' => "请输入正确的手机格式!"]);
        }
        //生成验证码
        $number = generateCode();
        //发送验证码
        $data = array(
            'content' => "【企智邦】提醒您,您的验证码是:" .$number.",十分钟之内有效,请勿向他人泄漏您的验证码",//短信内容
            'mobile' => $phone,//手机号码
            'productid' => '676767',//产品id
            'xh' => ''//小号
        );
        $result = send_sms($data);
        if (substr($result, 0, strpos($result, ',')) != "1") {
            $this->error(['code' => 42001, 'msg' => $result]);
        }
        Cache::set($phone,$number,600);
        $this->success('SUCCESS');
    }

    /**
     * @ApiTitle    (验证验证码)
     * @ApiSummary  (验证验证码)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/verify)
     *
     * @ApiParams   (name="mobile", type="string", required=true, description="手机号")
     * @ApiParams   (name="code", type="string", required=true, description="验证码")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1553839125",
    "data": {

    }
    })
     */
    public function verify()
    {
        $param = $this->request->param();
        $validate = new Validate([
            'mobile' => 'require|max:11',
            'code'=>'require'
        ]);
        if (!$validate->check($param)) {
            $this->error(['code'=>40005,'msg'=>$validate->getError()]);
        }
        $code = Cache::get($param['mobile']);
        if($param['code'] == $code){
            $this->success('SUCCESS');
        }else{
            $this->error('验证码错误或者失效,请重新发送');
        }

    }
杨育虎 authored
788 789

    /**
杨育虎 authored
790 791
     * @ApiTitle    (客服列表)
     * @ApiSummary  (客服列表)
杨育虎 authored
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/ke_list)
     *
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "total_num"://总条数
    "info":[
    "id"://ID
    "phone2"://手机号2
    "phone1"://手机号1
    "image"://二维码
    "createtime"://创建时间
    ]

    }
    })
     */
    public function ke_list()
    {
        $page = $this->request->param('page', 1, 'intval');
        $pageNum = $this->request->param('pageNum', 10, 'intval');
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $data['total_num'] = Db::name('kelist')->count();
        $data['info'] = Db::name('kelist')->order('id desc')->field('updatetime',true)->page($page,$pageNum)->select();
        foreach ($data['info'] as &$v){
            $v['image'] = $qiniu.$v['image'];
            $v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
        }
        $this->success('success',$data);
    }
杨育虎 authored
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865
    /**
     * @ApiTitle    (客服详情)
     * @ApiSummary  (客服详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/ke_list_detail)
     *
     * @ApiParams   (name="id", type="inter", required=false, description="客服id")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "total_num"://总条数
    "info":[
    "id"://ID
    "phone2"://手机号2
    "phone1"://手机号1
    "image"://二维码
    "createtime"://创建时间
    ]

    }
    })
     */
    public function ke_list_detail()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $id = $this->request->param('id');
        if(empty($id)){
            $this->error('缺少必要参数');
        }
        $data = Db::name('kelist')->where('id',$id)->find();
        $data['image'] = $qiniu.$data['image'];
        $this->success('success',$data);
    }
杨育虎 authored
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931

    /**
     * @ApiTitle    (分类列表)
     * @ApiSummary  (分类列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/type_list)
     *
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "one": [
    {
    "id": 1,
    "name": "学习类型",
    "pid": 0,
    "level": 1,
    "createtime": 1597834718,
    "updatetime": 1597834718
    }
    ],
    "two": [
    {
    "id": 2,
    "name": "理科类型",
    "pid": 1,
    "level": 2,
    "createtime": 1597834738,
    "updatetime": 1597834738
    }
    ],
    "three": [
    {
    "id": 3,
    "name": "测试",
    "pid": 2,
    "level": 3,
    "createtime": 1597835130,
    "updatetime": 1597835130
    }
    ]

    }
    })
     */
    public function type_list()
    {
        $data = Db::name('type')->select();
        $info['one'] = [];
        $info['two'] = [];
        $info['three'] = [];
        foreach ($data as $k=>$v){
            if($v['level'] == 1){
                array_push($info['one'],$data[$k]);
            }elseif ($v['level'] == 2){
                array_push($info['two'],$data[$k]);
            }else{
                array_push($info['three'],$data[$k]);
            }
        }
        $this->success('success',$info);
    }

    /**
杨育虎 authored
932 933
     * @ApiTitle    (通过id获取分类列表)
     * @ApiSummary  (通过id获取分类列表)
杨育虎 authored
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/get_list)
     *
     * @ApiParams   (name="id", type="inter", required=false, description="分类id")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    }
    })
     */
    public function get_list()
    {
        $id = $this->request->param('id');
        if(empty($id)){
            $this->error('缺少必要参数');
        }

        $data = Db::name('type')->where('pid',$id)->select();
        $this->success('success',$data);
    }
杨育虎 authored
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983
    /**
     * @ApiTitle    (获取分类标题)
     * @ApiSummary  (获取分类标题)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/lists/type_title)
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
          "title_one"://标题1
          "title_two"://标题2
          "title_three"://标题3
    }
    })
     */
    public function type_title()
    {
        $data = Db::name('type_title')
            ->where('id',1)
            ->field('title_one,title_two,title_three')
            ->find();
        $this->success('success',$data);
    }
杨育虎 authored
984
}