Skip to content

Commit d7d0ebc

Browse files
committed
后端部分接口实现
1 parent a598685 commit d7d0ebc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2437
-19
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.idea
2+
/.vscode
3+
/vendor
4+
*.log
5+
thinkphp
6+
.env
7+
.DS_Store

.travis.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
sudo: false
2+
3+
language: php
4+
5+
branches:
6+
only:
7+
- stable
8+
9+
cache:
10+
directories:
11+
- $HOME/.composer/cache
12+
13+
before_install:
14+
- composer self-update
15+
16+
install:
17+
- composer install --no-dev --no-interaction --ignore-platform-reqs
18+
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip .
19+
- composer require --update-no-dev --no-interaction "topthink/think-image:^1.0"
20+
- composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0"
21+
- composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0"
22+
- composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0"
23+
- composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0"
24+
- composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0"
25+
- composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0"
26+
- composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0"
27+
- composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0"
28+
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip .
29+
30+
script:
31+
- php think unit
32+
33+
deploy:
34+
provider: releases
35+
api_key:
36+
secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw=
37+
file:
38+
- ThinkPHP_Core.zip
39+
- ThinkPHP_Full.zip
40+
skip_cleanup: true
41+
on:
42+
tags: true

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
## V5.1.34 LTS(2019-1-30)
3+
4+
本次更新为常规更新,修正了一些反馈的问题。
5+
6+
* 改进Request类的`has`方法,支持`patch`
7+
* 改进`unique`验证的多条件支持
8+
* 修复自定义上传验证,检测文件大小
9+
* 改进`in`查询支持表达式
10+
* 改进路由的`getBind`方法
11+
* 改进验证类的错误信息获取
12+
* 改进`response`助手函数默认值
13+
* 修正mysql的`regexp`查询
14+
* 改进模型类型强制转换写入对`Expression`对象的支持

LICENSE

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
MIT License
1+
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
2+
版权所有Copyright © 2006-2018 by ThinkPHP (http://thinkphp.cn)
3+
All rights reserved。
4+
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
25

3-
Copyright (c) 2019 ChenJinchuang
6+
Apache Licence是著名的非盈利开源组织Apache采用的协议。
7+
该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
8+
允许代码修改,再作为开源或商业软件发布。需要满足
9+
的条件:
10+
1. 需要给代码的用户一份Apache Licence ;
11+
2. 如果你修改了代码,需要在被修改的文件中说明;
12+
3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
13+
带有原来代码中的协议,商标,专利声明和其他原来作者规
14+
定需要包含的说明;
15+
4. 如果再发布的产品中包含一个Notice文件,则在Notice文
16+
件中需要带有本协议内容。你可以在Notice中增加自己的
17+
许可,但不可以表现为对Apache Licence构成更改。
18+
具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
419

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
11-
12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24+
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
POSSIBILITY OF SUCH DAMAGE.

application/.htaccess

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deny from all
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: 沁塵
5+
* Date: 2019/4/16
6+
* Time: 11:21
7+
*/
8+
9+
namespace app\api\controller\cms;
10+
11+
use app\api\model\Group as GroupModel;
12+
use app\lib\auth\AuthMap;
13+
use app\lib\exception\group\GroupException;
14+
use think\Request;
15+
16+
class Admin
17+
{
18+
/**
19+
* @auth('查询所有权限组','管理员')
20+
* @return mixed
21+
*/
22+
public function getGroupAll()
23+
{
24+
$result = GroupModel::all();
25+
26+
return $result;
27+
}
28+
29+
/**
30+
* @auth('查询一个权限组及其权限','管理员')
31+
* @param $id
32+
* @return array|\PDOStatement|string|\think\Model
33+
* @throws \app\lib\exception\group\GroupException
34+
* @throws \think\db\exception\DataNotFoundException
35+
* @throws \think\db\exception\ModelNotFoundException
36+
* @throws \think\exception\DbException
37+
*/
38+
public function getGroup($id)
39+
{
40+
$result = GroupModel::getGroupByID($id);
41+
42+
return $result;
43+
}
44+
45+
46+
/**
47+
* @auth('删除一个权限组','管理员')
48+
* @param $id
49+
* @return \think\response\Json
50+
*/
51+
public function deleteGroup($id)
52+
{
53+
GroupModel::destroy($id);
54+
55+
return writeJson(201, '','删除分组成功');
56+
}
57+
58+
/**
59+
* @auth('新建权限组','管理员')
60+
* @param Request $request
61+
* @return \think\response\Json
62+
* @throws \ReflectionException
63+
* @throws \app\lib\exception\group\GroupException
64+
* @throws \think\db\exception\DataNotFoundException
65+
* @throws \think\db\exception\ModelNotFoundException
66+
* @throws \think\exception\DbException
67+
*/
68+
public function createGroup(Request $request)
69+
{
70+
$params = $request->post();
71+
GroupModel::createGroup($params);
72+
73+
return writeJson(201, '', '成功');
74+
}
75+
76+
/**
77+
* @auth('更新一个权限组','管理员')
78+
* @param Request $request
79+
* @param $id
80+
* @return \think\response\Json
81+
* @throws \think\Exception
82+
*/
83+
public function updateGroup(Request $request, $id)
84+
{
85+
$params = $request->put();
86+
87+
$group = GroupModel::find($id);
88+
if (!$group) {
89+
throw new GroupException([
90+
'code' => 404,
91+
'msg' => '指定的分组不存在',
92+
'errorCode' => 30003
93+
]);
94+
}
95+
$group->save($params);
96+
97+
return writeJson(201, '', '更新分组成功');
98+
99+
}
100+
101+
/**
102+
* @auth('查询所有可分配的权限','管理员')
103+
* @throws \ReflectionException
104+
*/
105+
public function authority()
106+
{
107+
$result = (new AuthMap())->run();
108+
109+
return $result;
110+
}
111+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace app\api\controller\cms;
4+
5+
use app\lib\token\Token;
6+
use think\Controller;
7+
use think\Request;
8+
use app\api\model\User as UserModel;
9+
10+
class User extends Controller
11+
{
12+
/**
13+
* 账户登陆
14+
* @param Request $request
15+
* @return array
16+
* @throws \think\Exception
17+
*/
18+
public function login(Request $request)
19+
{
20+
$params = $request->post();
21+
$user = UserModel::verify($params['nickname'], $params['password']);
22+
// TODO 记录日志
23+
$result = Token::getToken($user);
24+
return $result;
25+
}
26+
27+
28+
/**
29+
* 查询自己拥有的权限
30+
* @throws \app\lib\exception\token\TokenException
31+
* @throws \think\Exception
32+
*/
33+
public function getAllowedApis()
34+
{
35+
$uid = Token::getCurrentUID();
36+
$result = UserModel::getUserByUID($uid);
37+
return $result;
38+
}
39+
40+
}

application/api/model/Auth.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: 沁塵
5+
* Date: 2019/2/19
6+
* Time: 12:49
7+
*/
8+
9+
namespace app\api\model;
10+
11+
12+
class Auth extends BaseModel
13+
{
14+
protected $hidden = ['id'];
15+
}

application/api/model/BaseModel.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: 沁塵
5+
* Date: 2019/2/19
6+
* Time: 11:22
7+
*/
8+
9+
namespace app\api\model;
10+
11+
12+
use think\Model;
13+
14+
class BaseModel extends Model
15+
{
16+
17+
}

0 commit comments

Comments
 (0)