Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
doc_phone
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiangyipeng
doc_phone
Commits
b2b86b96
Commit
b2b86b96
authored
May 25, 2020
by
huanle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
0525_文件夹操作优化
parent
cbb8faf7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
65 deletions
+108
-65
Index.php
application/api/controller/Index.php
+2
-2
Doclist.php
application/api/model/Doclist.php
+30
-30
Folder.php
application/api/model/Folder.php
+76
-33
No files found.
application/api/controller/Index.php
View file @
b2b86b96
...
...
@@ -38,11 +38,11 @@ class Index extends Controller
}
else
{
$res
=
$model
->
addFolder
(
$name
,
$parentid
);
if
(
$res
)
{
if
(
$res
[
'code'
]
>=
0
)
{
return
json
(
code
([
$res
],
0
,
'添加成功'
));
}
else
{
return
json
(
code
([
$res
],
10002
,
'添加失败'
));
return
json
(
code
([],
10002
,
'添加失败'
));
}
}
}
...
...
application/api/model/Doclist.php
View file @
b2b86b96
...
...
@@ -16,20 +16,20 @@ class Doclist extends Model
}
//获取文件夹名称
public
function
articleList
(
$folderid
,
$origin
,
$pagenum
)
public
function
articleList
(
$folderid
,
$origin
,
$pagenum
)
{
if
(
$folderid
)
{
$where
[
'folderid'
]
=
array
(
'='
,
$folderid
);
$where
[
'state'
]
=
array
(
'='
,
0
);
$articlelist
=
Db
::
name
(
'doclist'
)
->
field
(
'docid,title,type,updatetime'
)
->
where
(
$where
)
->
order
(
'createtime'
)
->
limit
(
$origin
,
$pagenum
)
->
select
();
// var_dump($folderid);
if
(
$folderid
)
{
$where
[
'folderid'
]
=
array
(
'='
,
$folderid
);
$where
[
'state'
]
=
array
(
'='
,
0
);
$articlelist
=
Db
::
name
(
'doclist'
)
->
field
(
'docid,title,type,updatetime'
)
->
where
(
$where
)
->
order
(
'createtime'
)
->
limit
(
$origin
,
$pagenum
)
->
select
();
// $sql = Db::name('doclist')->getLastSql();
// var_dump($sql);
}
else
{
$articlelist
=
[];
}
}
else
{
$articlelist
=
[];
}
return
$articlelist
;
}
...
...
@@ -37,14 +37,13 @@ class Doclist extends Model
public
function
articleDetail
(
$docid
)
{
if
(
$docid
)
{
$where
=
[
'docid'
=>
$docid
];
$articldetail
=
Db
::
name
(
'doclist'
)
->
field
(
'docid,title,type,updatetime,doc'
)
->
where
(
$where
)
->
find
();
return
$articldetail
;
}
if
(
$docid
)
{
$where
=
[
'docid'
=>
$docid
];
$articldetail
=
Db
::
name
(
'doclist'
)
->
field
(
'docid,title,type,updatetime,doc'
)
->
where
(
$where
)
->
find
();
return
$articldetail
;
}
}
public
function
addArticle
(
$title
,
$folderid
,
$type
,
$doc
)
public
function
addArticle
(
$title
,
$folderid
,
$type
,
$doc
)
{
$docid
=
randomkeys
(
18
);
...
...
@@ -55,24 +54,24 @@ class Doclist extends Model
$rs
=
new
Doclist
();
if
(
$docname
==
0
)
{
$data
=
[
'docid'
=>
$docid
,
'title'
=>
$title
,
'docid'
=>
$docid
,
'title'
=>
$title
,
'type'
=>
$type
,
'doc'
=>
$doc
,
'folderid'
=>
$folderid
,
'createtime'
=>
date
(
"Y-m-d H:i:s"
,
time
())
'createtime'
=>
date
(
"Y-m-d H:i:s"
,
time
())
];
$rs
->
isUpdate
(
false
)
->
save
(
$data
);
// $sql = Db::name('doclist')->getLastSql();
// var_dump($sql);
$return
=
$rs
->
docid
;
return
$return
;
}
}
public
function
editArticle
(
$title
,
$folderid
,
$doc
,
$docid
)
public
function
editArticle
(
$title
,
$folderid
,
$doc
,
$docid
)
{
$rs
=
new
Doclist
();
...
...
@@ -80,22 +79,23 @@ class Doclist extends Model
$where
=
[];
$data
=
[
'title'
=>
$title
,
'doc'
=>
$doc
,
'doc'
=>
$doc
,
'updatetime'
=>
date
(
"Y-m-d H:i:s"
,
time
()),
];
if
(
$docid
)
{
$where
[
'docid'
]
=
array
(
'='
,
$docid
);
$where
[
'folderid'
]
=
array
(
'='
,
$folderid
);
$where
[
'docid'
]
=
array
(
'='
,
$docid
);
$where
[
'folderid'
]
=
array
(
'='
,
$folderid
);
}
$rs
=
$this
->
where
(
$where
)
->
update
(
$data
);
$rs
=
$this
->
where
(
$where
)
->
update
(
$data
);
if
(
$rs
===
false
)
{
return
false
;
}
else
{
return
true
;
}
if
(
$rs
===
false
)
{
return
false
;
}
else
{
return
true
;
}
// var_dump($rs);die();
...
...
application/api/model/Folder.php
View file @
b2b86b96
...
...
@@ -26,7 +26,8 @@ class Folder extends Model
}
$folderlist
=
Db
::
name
(
'folder'
)
->
where
(
$where
)
->
order
(
''
)
->
select
();
// $sql = Db::name('folder')->getLastSql();
// var_dump($sql);
return
$folderlist
;
}
...
...
@@ -35,55 +36,97 @@ class Folder extends Model
{
$folderid
=
randomkeys
(
18
);
// $folderid='bpy0p4617b7fun9lxqa1';
if
(
!
$parentid
)
{
$parentid
=
''
;
}
$foldername
=
Db
::
name
(
'folder'
)
->
where
([
'folderid'
=>
$folderid
])
->
count
();
$rs
=
new
Folder
();
if
(
$foldername
==
0
)
{
$data
=
[
'folderid'
=>
$folderid
,
'name'
=>
$name
,
'updatetime'
=>
date
(
"Y-m-d H:i:s"
,
time
()),
'parentid'
=>
$parentid
,
'state'
=>
0
];
$rs
->
isUpdate
(
false
)
->
save
(
$data
);
$return
=
$rs
->
folderid
;
return
$return
;
}
// $data = [
// 'folderid' => $folderid,
// 'name' => $name,
// 'updatetime' => date("Y-m-d H:i:s", time()),
// 'parentid' => $parentid,
// 'state' => 0
// ];
// $childfolder_nums = Db::name('folder')->where(['parentid' => $parentid])->count();
//
// $rs->isUpdate(false)->save($data);
// if ($rs) {
// $items = $this->where(['folderid' => $parentid])->setField('items', $childfolder_nums + 1);
// }
// $return = $rs->folderid;
// return $return;
// 启动事务
Db
::
startTrans
();
try
{
$data
=
[
'folderid'
=>
$folderid
,
'name'
=>
$name
,
'updatetime'
=>
date
(
"Y-m-d H:i:s"
,
time
()),
'parentid'
=>
$parentid
,
'state'
=>
0
];
$childfolder_nums
=
Db
::
name
(
'folder'
)
->
where
([
'parentid'
=>
$parentid
])
->
count
();
$res
=
$rs
->
isUpdate
(
false
)
->
save
(
$data
);
if
(
$res
!==
false
)
{
if
(
$parentid
)
{
$items
=
$this
->
where
([
'folderid'
=>
$parentid
])
->
setField
(
'items'
,
$childfolder_nums
+
1
);
if
(
$items
)
{
$return
=
$rs
->
folderid
;
}
else
{
throw
new
\Exception
(
'添加失败'
);
}
}
else
{
$return
=
$rs
->
folderid
;
}
}
// 提交事务
Db
::
commit
();
}
catch
(
\Exception
$e
)
{
// 回滚事务
Db
::
rollback
();
$return
=
[
'code'
=>
-
200
,
'msg'
=>
$e
->
getMessage
()];
}
}
else
{
$return
=
[
'code'
=>
-
10002
,
'msg'
=>
'文件名重复'
];
}
return
$return
;
}
public
function
editFolder
(
$name
,
$parentid
,
$folderid
)
public
function
editFolder
(
$name
,
$parentid
,
$folderid
)
{
$rs
=
new
Folder
();
$where
=
''
;
$where
=
''
;
$data
=
[
'name'
=>
$name
,
'updatetime'
=>
date
(
"Y-m-d H:i:s"
,
time
()),
];
if
(
$folderid
)
{
if
(
$folderid
)
{
$where
=
[
'folderid'
=>
$folderid
];
}
if
(
$parentid
)
{
if
(
$parentid
)
{
$where
=
[
'parentid'
=>
$parentid
];
}
$oldname
=
Db
::
name
(
'folder'
)
->
where
(
$where
)
->
value
(
'name'
);
if
(
$name
!=
$oldname
)
{
$rs
=
$this
->
where
(
$where
)
->
update
(
$data
);
if
(
$rs
===
false
)
{
return
false
;
}
else
{
return
true
;
}
}
else
{
return
false
;
}
if
(
$name
!=
$oldname
)
{
$rs
=
$this
->
where
(
$where
)
->
update
(
$data
);
if
(
$rs
===
false
)
{
return
false
;
}
else
{
return
true
;
}
}
else
{
return
false
;
}
// var_dump($rs);die();
...
...
@@ -91,23 +134,23 @@ class Folder extends Model
// var_dump($sql);
}
public
function
delFolder
(
$folderid
)
{
$rs
=
new
Folder
();
$where
=
[
'folderid'
=>
$folderid
];
$data
=
[
'state'
=>-
1
,
'state'
=>
-
1
,
];
$rs
=
$this
->
where
(
$where
)
->
update
(
$data
);
if
(
$rs
===
false
)
{
if
(
$rs
===
false
)
{
return
false
;
}
else
{
}
else
{
return
true
;
}
// var_dump($rs);die();
// $sql = Db::name('folder')->getLastSql();
// var_dump($sql);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment