当前路径: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)]); } }
相关源码
- 可旋转的彩色立方体C#源代码2021-10-29
- 在线考试系统2021-10-15
- EduSoho开源网校系统源码2019-06-27
- 仿拼多多小程序商城源码2019-06-06
- PHP5网站运行监测系统源码2017-04-14
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号