点击回首页
我的浏览记录 | | 帮助?
当前位置:
首页>> 行业软件>> 在线考试系统>> 源文件浏览
[免费版 Free] WebForm,下载次数:254 次 | 关键字: 考试 办公 高校 竞赛 企事业单位

源码截图

源码目录树

;
当前路径:app/control/controller/system/Book.php
<?php

declare(strict_types=1);

namespace app\control\controller\system;

use app\BaseController;
use app\common\model\book\Chapter;
use app\common\model\book\Volume;
use app\common\model\exam\Subject;
use app\control\model\User;
use mb\helper\Collection;
use think\response\Json;

/**
 * Class Book
 * @package app\control\controller
 */
class Book extends BaseController
{
    /**
     * @return Json
     * @api {post} /book/tree 电子书树状结构
     * @apiGroup Book
     * @apiName sort1
     * @apiVersion 1.0.0
     *
     * @apiDescription 电子书树状结构
     *
     * @apiSuccess {Number} code    状态码,0:请求成功
     * @apiSuccess {String} message   提示信息
     * @apiSuccess {Object} dataSet    返回数据
     *
     * @apiSuccessExample {json} Success-Response:
     * {"code":0,"message":"","dataSet":[]}
     *
     * @apiErrorExample {json} Error-Response:
     * {"code":5001,"message":"接口异常"}
     */
    public function tree()
    {
        $where = [];
        $user = User::fetchCurrent();
        if ($user['role'] != 'root') {
            $subjectIds = Subject::userWatch();
            $where['ids'] = implode(',', $subjectIds);
        }
        $subjects = Subject::search($where, 0);
        $subjects = array_map(function ($s) {
            unset($s['watch']);
            return $s;
        }, $subjects);
        $subjects = Collection::key($subjects, 'id');
        $volumes = Volume::search($where, 0);
        $volumes = Collection::key($volumes, 'id');
        $chapters = Chapter::search($where, 0);
        $newChapters = [];
        foreach ($chapters as $val) {
            $val = [
                'id' => $val['id'],
                'subjectId' => $val['subjectId'],
                'volumeId' => $val['volumeId'],
                'caption' => $val['caption'],
                'type' => 'chapter',
                'volumeTitle' => $val['volumeTitle']
            ];
            $newChapters[$val['volumeId']][] = $val;
        }
        foreach ($newChapters as $k => $val) {
            $volumes[$k]['children'] = $val;
        }
        $newVolume = [];
        foreach ($volumes as $val) {
            $val['type'] = 'volume';
            $newVolume[$val['subjectId']][] = $val;
        }
        foreach ($newVolume as $k => $val) {
            if (isset($subjects[$k])) {
                $subjects[$k]['children'] = $val;
            } else {
                continue;
            }
        }
        $subjects = array_map(function ($row) {
            $row['type'] = 'subject';
            return $row;
        }, $subjects);
        return payload(['dataSet' => array_values($subjects)]);
    }
}
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号