Skip to content

Commit 2ce4bed

Browse files
author
lichenchen
committed
基本写完了,就提交以下,保存
1 parent e7273ff commit 2ce4bed

File tree

279 files changed

+47308
-0
lines changed

Some content is hidden

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

279 files changed

+47308
-0
lines changed

LICENSE.txt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
3+
版权所有Copyright © 2006-2017 by ThinkPHP (http://thinkphp.cn)
4+
All rights reserved。
5+
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
6+
7+
Apache Licence是著名的非盈利开源组织Apache采用的协议。
8+
该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
9+
允许代码修改,再作为开源或商业软件发布。需要满足
10+
的条件:
11+
1. 需要给代码的用户一份Apache Licence ;
12+
2. 如果你修改了代码,需要在被修改的文件中说明;
13+
3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
14+
带有原来代码中的协议,商标,专利声明和其他原来作者规
15+
定需要包含的说明;
16+
4. 如果再发布的产品中包含一个Notice文件,则在Notice文
17+
件中需要带有本协议内容。你可以在Notice中增加自己的
18+
许可,但不可以表现为对Apache Licence构成更改。
19+
具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25+
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
POSSIBILITY OF SUCH DAMAGE.

application/.htaccess

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deny from all

application/admin/config.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
return [
4+
// +----------------------------------------------------------------------
5+
// | 后台模板设置
6+
// +----------------------------------------------------------------------
7+
8+
'template' => [
9+
// 模板路径
10+
// 'view_path' => './themes/admin/'
11+
],
12+
];
+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
namespace app\admin\controller;
3+
4+
use app\common\model\AdminUser as AdminUserModel;
5+
use app\common\model\AuthGroup as AuthGroupModel;
6+
use app\common\model\AuthGroupAccess as AuthGroupAccessModel;
7+
use app\common\controller\AdminBase;
8+
use think\Config;
9+
use think\Db;
10+
11+
/**
12+
* 管理员管理
13+
* Class AdminUser
14+
* @package app\admin\controller
15+
*/
16+
class AdminUser extends AdminBase
17+
{
18+
protected $admin_user_model;
19+
protected $auth_group_model;
20+
protected $auth_group_access_model;
21+
22+
protected function _initialize()
23+
{
24+
parent::_initialize();
25+
$this->admin_user_model = new AdminUserModel();
26+
$this->auth_group_model = new AuthGroupModel();
27+
$this->auth_group_access_model = new AuthGroupAccessModel();
28+
}
29+
30+
/**
31+
* 管理员管理
32+
* @return mixed
33+
*/
34+
public function index()
35+
{
36+
$admin_user_list = $this->admin_user_model->select();
37+
38+
return $this->fetch('index', ['admin_user_list' => $admin_user_list]);
39+
}
40+
41+
/**
42+
* 添加管理员
43+
* @return mixed
44+
*/
45+
public function add()
46+
{
47+
$auth_group_list = $this->auth_group_model->select();
48+
49+
return $this->fetch('add', ['auth_group_list' => $auth_group_list]);
50+
}
51+
52+
/**
53+
* 保存管理员
54+
* @param $group_id
55+
*/
56+
public function save($group_id)
57+
{
58+
if ($this->request->isPost()) {
59+
$data = $this->request->param();
60+
$validate_result = $this->validate($data, 'AdminUser');
61+
62+
if ($validate_result !== true) {
63+
$this->error($validate_result);
64+
} else {
65+
$data['password'] = md5($data['password'] . Config::get('salt'));
66+
if ($this->admin_user_model->allowField(true)->save($data)) {
67+
$auth_group_access['uid'] = $this->admin_user_model->id;
68+
$auth_group_access['group_id'] = $group_id;
69+
$this->auth_group_access_model->save($auth_group_access);
70+
$this->success('保存成功');
71+
} else {
72+
$this->error('保存失败');
73+
}
74+
}
75+
}
76+
}
77+
78+
/**
79+
* 编辑管理员
80+
* @param $id
81+
* @return mixed
82+
*/
83+
public function edit($id)
84+
{
85+
$admin_user = $this->admin_user_model->find($id);
86+
$auth_group_list = $this->auth_group_model->select();
87+
$auth_group_access = $this->auth_group_access_model->where('uid', $id)->find();
88+
$admin_user['group_id'] = $auth_group_access['group_id'];
89+
90+
return $this->fetch('edit', ['admin_user' => $admin_user, 'auth_group_list' => $auth_group_list]);
91+
}
92+
93+
/**
94+
* 更新管理员
95+
* @param $id
96+
* @param $group_id
97+
*/
98+
public function update($id, $group_id)
99+
{
100+
if ($this->request->isPost()) {
101+
$data = $this->request->param();
102+
$validate_result = $this->validate($data, 'AdminUser');
103+
104+
if ($validate_result !== true) {
105+
$this->error($validate_result);
106+
} else {
107+
$admin_user = $this->admin_user_model->find($id);
108+
109+
$admin_user->id = $id;
110+
$admin_user->username = $data['username'];
111+
$admin_user->status = $data['status'];
112+
113+
if (!empty($data['password']) && !empty($data['confirm_password'])) {
114+
$admin_user->password = md5($data['password'] . Config::get('salt'));
115+
}
116+
if ($admin_user->save() !== false) {
117+
$auth_group_access['uid'] = $id;
118+
$auth_group_access['group_id'] = $group_id;
119+
$this->auth_group_access_model->where('uid', $id)->update($auth_group_access);
120+
$this->success('更新成功');
121+
} else {
122+
$this->error('更新失败');
123+
}
124+
}
125+
}
126+
}
127+
128+
/**
129+
* 删除管理员
130+
* @param $id
131+
*/
132+
public function delete($id)
133+
{
134+
if ($id == 1) {
135+
$this->error('默认管理员不可删除');
136+
}
137+
if ($this->admin_user_model->destroy($id)) {
138+
$this->auth_group_access_model->where('uid', $id)->delete();
139+
$this->success('删除成功');
140+
} else {
141+
$this->error('删除失败');
142+
}
143+
}
144+
}
+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?php
2+
namespace app\admin\controller;
3+
4+
use app\common\model\Article as ArticleModel;
5+
use app\common\model\Category as CategoryModel;
6+
use app\common\controller\AdminBase;
7+
8+
/**
9+
* 文章管理
10+
* Class Article
11+
* @package app\admin\controller
12+
*/
13+
class Article extends AdminBase
14+
{
15+
protected $article_model;
16+
protected $category_model;
17+
18+
protected function _initialize()
19+
{
20+
parent::_initialize();
21+
$this->article_model = new ArticleModel();
22+
$this->category_model = new CategoryModel();
23+
24+
$category_level_list = $this->category_model->getLevelList();
25+
$this->assign('category_level_list', $category_level_list);
26+
}
27+
28+
/**
29+
* 文章管理
30+
* @param int $cid 分类ID
31+
* @param string $keyword 关键词
32+
* @param int $page
33+
* @return mixed
34+
*/
35+
public function index($cid = 0, $keyword = '', $page = 1)
36+
{
37+
$map = [];
38+
$field = 'id,title,cid,author,reading,status,publish_time,sort';
39+
40+
if ($cid > 0) {
41+
$category_children_ids = $this->category_model->where(['path' => ['like', "%,{$cid},%"]])->column('id');
42+
$category_children_ids = (!empty($category_children_ids) && is_array($category_children_ids)) ? implode(',', $category_children_ids) . ',' . $cid : $cid;
43+
$map['cid'] = ['IN', $category_children_ids];
44+
}
45+
46+
if (!empty($keyword)) {
47+
$map['title'] = ['like', "%{$keyword}%"];
48+
}
49+
50+
$article_list = $this->article_model->field($field)->where($map)->order(['publish_time' => 'DESC'])->paginate(15, false, ['page' => $page]);
51+
$category_list = $this->category_model->column('name', 'id');
52+
53+
return $this->fetch('index', ['article_list' => $article_list, 'category_list' => $category_list, 'cid' => $cid, 'keyword' => $keyword]);
54+
}
55+
56+
/**
57+
* 添加文章
58+
* @return mixed
59+
*/
60+
public function add()
61+
{
62+
return $this->fetch();
63+
}
64+
65+
/**
66+
* 保存文章
67+
*/
68+
public function save()
69+
{
70+
if ($this->request->isPost()) {
71+
$data = $this->request->param();
72+
$validate_result = $this->validate($data, 'Article');
73+
74+
if ($validate_result !== true) {
75+
$this->error($validate_result);
76+
} else {
77+
if ($this->article_model->allowField(true)->save($data)) {
78+
$this->article_model->articleContent()->save(['content' => $data["content"]]);
79+
$this->success('保存成功');
80+
} else {
81+
$this->error('保存失败');
82+
}
83+
}
84+
}
85+
}
86+
87+
/**
88+
* 编辑文章
89+
* @param $id
90+
* @return mixed
91+
*/
92+
public function edit($id)
93+
{
94+
$article = $this->article_model->find($id);
95+
96+
return $this->fetch('edit', ['article' => $article]);
97+
}
98+
99+
/**
100+
* 更新文章
101+
* @param $id
102+
*/
103+
public function update($id)
104+
{
105+
if ($this->request->isPost()) {
106+
$data = $this->request->param();
107+
$validate_result = $this->validate($data, 'Article');
108+
109+
if ($validate_result !== true) {
110+
$this->error($validate_result);
111+
} else {
112+
if ($this->article_model->together('articleContent')->allowField(true)->save($data, $id) !== false) {
113+
$this->article_model->articleContent->save(['content' => $data['content']]);
114+
$this->success('更新成功');
115+
} else {
116+
$this->error('更新失败');
117+
}
118+
}
119+
}
120+
}
121+
122+
/**
123+
* 删除文章
124+
* @param int $id
125+
* @param array $ids
126+
*/
127+
public function delete($id = 0, $ids = [])
128+
{
129+
$id = $ids ? $ids : $id;
130+
if ($id) {
131+
if ($this->article_model->destroy($id)) {
132+
$this->success('删除成功');
133+
} else {
134+
$this->error('删除失败');
135+
}
136+
} else {
137+
$this->error('请选择需要删除的文章');
138+
}
139+
}
140+
141+
/**
142+
* 文章审核状态切换
143+
* @param array $ids
144+
* @param string $type 操作类型
145+
*/
146+
public function toggle($ids = [], $type = '')
147+
{
148+
$data = [];
149+
$status = $type == 'audit' ? 1 : 0;
150+
151+
if (!empty($ids)) {
152+
foreach ($ids as $value) {
153+
$data[] = ['id' => $value, 'status' => $status];
154+
}
155+
if ($this->article_model->saveAll($data)) {
156+
$this->success('操作成功');
157+
} else {
158+
$this->error('操作失败');
159+
}
160+
} else {
161+
$this->error('请选择需要操作的文章');
162+
}
163+
}
164+
}

0 commit comments

Comments
 (0)