Commit a3b33bed authored by huanle's avatar huanle

0520—

parent 3f18b4c3
<?php
namespace app\api\controller;
use think\Request;
use think\Controller;
use app\api\model\Folder;
use app\api\model\Doclist;
class Index extends Controller
{
public function index()
{
$model = new Folder();
$b=$model->index();
var_dump();
$b = $model->index();
var_dump();
}
public function folderList()
{
$request = Request::instance();
$model = new Folder();
$parentid =$request->param('parentid');
$res = $model->folderList($parentid);
if($res){
return json(code([$res],0,'ok'));
}else{
return json(code([],10002,'请求失败'));
}
$parentid = $request->param('parentid');
$res = $model->folderList($parentid);
if ($res) {
return json(code([$res], 0, 'ok'));
} else {
return json(code([], 10002, '请求失败'));
}
}
public function folderAdd()
{
$name = input('post.name');
$parentid = input('post.parentid');
$model = new Folder();
if(empty($name)){
return json(code([],10001,'名称不能为空'));
}else{
$res = $model->addFolder($name,$parentid);
if (empty($name)) {
return json(code([], 10001, '名称不能为空'));
} else {
$res = $model->addFolder($name, $parentid);
if($res){
if ($res) {
return json(code([$res],0,'添加成功'));
}else{
return json(code([$res],10002,'添加失败'));
return json(code([$res], 0, '添加成功'));
} else {
return json(code([$res], 10002, '添加失败'));
}
}
}
public function folderEdit()
{
$name = input('post.name');
$parentid = input('post.parentid');
$folderid = input('post.folderid');
$model = new Folder();
if(empty($parentid)||empty($folderid)){
return json(code([],10001,'参数不足'));
if (empty($parentid) || empty($folderid)) {
return json(code([], 10001, '参数不足'));
}
if(empty($name)){
return json(code([],10001,'名称不能为空'));
}else{
$res = $model->editFolder($name,$parentid,$folderid);
if (empty($name)) {
return json(code([], 10001, '名称不能为空'));
} else {
$res = $model->editFolder($name, $parentid, $folderid);
if($res){
if ($res) {
return json(code([],0,'修改成功'));
}else{
return json(code([],10002,'修改失败'));
return json(code([], 0, '修改成功'));
} else {
return json(code([], 10002, '修改失败'));
}
}
}
public function folderDel()
{
$folderid = input('post.folderid');
$model = new Folder();
if(empty($folderid)){
return json(code([],10001,'没有folderid'));
}else{
if (empty($folderid)) {
return json(code([], 10001, '没有folderid'));
} else {
$res = $model->delFolder($folderid);
if($res){
if ($res) {
return json(code([],0,'删除成功'));
}else{
return json(code([],10002,'删除失败'));
return json(code([], 0, '删除成功'));
} else {
return json(code([], 10002, '删除失败'));
}
}
}
public function articleList()
{
$folderid = input('post.folderid');
//
// $model = new Doclist();
// if(empty($folderid)){
// return json(code([],10001,'没有folderid'));
// }else{
// $res = $model->ArticleList($folderid);
//
// }
$model = new Doclist();
$folderid = input('post.folderid');
$post['origin'] = input('request.origin');
$post['pagenum'] = input('request.pagenum');
$post['current'] = input('request.current');
if ( !isset($post['origin']) || empty($post['origin']) ) {
$post['origin'] = 0 ;
}
//每页显示多少条数据
if ( !isset($post['pagenum']) || empty($post['pagenum']) ) {
$post['pagenum'] = 20 ;
}
//当前页
if ( isset($post['current']) && !empty($post['current']) && $post['current']>=1 ) {
$data['current'] = ceil($post['current']);
if (($data['current']-1)>=1){
$post['origin'] = ($post['current']-1) * $post['lenght'];
}
}else{
$data['current'] = $post['origin'] / $post['pagenum'];
}
$data['pagenum'] = $post['pagenum'];
if ($data['current']<=1) {
$data['current'] = 1;
}
$data['admin'] = AdminModel::admin_lst($post['origin'],$post['pagenum']);
//数据总条数
$data['count'] = StudyModel::rules_count();
//总页数
$data['page'] = ceil($data['count'] / $data['lenght']);
}
}
<?php
namespace app\api\model;
use think\Model;
use think\Db;
class Doclist extends Model
{
public function index()
{
$user = Db::name('folder')->where('state', '=', -1)->find();
return $user;
// $sql = Db::name('folder')->getLastSql();
//// var_dump($sql);
}
//获取文件夹名称
public function ArticleList($folderid,$origin,$pagenum)
{
var_dump($origin);
var_dump($pagenum);die();
$where = ['folderid' => $folderid];
$articlelist = Db::name('doclist')->where($where)->order('')->select();
$sql = Db::name('doclist')->getLastSql();
var_dump($sql);
return $articlelist;
}
public function addFolder($name, $parentid)
{
$folderid = randomkeys(18);
$foldername = Db::name('folder')->where(['folderid' => $folderid])->count();
$rs = new Doclist();
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;
}
}
public function editFolder($name, $parentid, $folderid)
{
$rs = new Folder();
$where = '';
$data = [
'name' => $name,
'updatetime' => date("Y-m-d H:i:s", time()),
];
if ($folderid) {
$where = ['folderid' => $folderid];
}
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;
}
// var_dump($rs);die();
// $sql = Db::name('folder')->getLastSql();
// var_dump($sql);
}
public function delFolder($folderid)
{
$rs = new Folder();
$where = ['folderid' => $folderid];
$data = [
'state' => -1,
];
$rs = $this->where($where)->update($data);
if ($rs === false) {
return false;
} else {
return true;
}
// var_dump($rs);die();
// $sql = Db::name('folder')->getLastSql();
// var_dump($sql);
}
}
......@@ -15,11 +15,11 @@ return [
// +----------------------------------------------------------------------
// 应用调试模式
'app_debug' => false,
'app_debug' => true,
// 应用Trace
'app_trace' => false,
// 应用模式状态
'app_status' => '',
'app_status' => \think\Env::get("RUN_MODE", "prod"),
// 是否支持多模块
'app_multi_module' => true,
// 入口自动绑定模块
......
<?php
return [
"database" => [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '127.0.0.1',
// 数据库名
'database' => 'doc',
// 用户名
'username' => 'root',
// 密码
'password' => '123456',
// 端口
'hostport' => '3306',
// 连接dsn
'dsn' => '',
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => '',
// 数据库调试模式
'debug' => true,
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 自动读取主库数据
'read_master' => false,
// 是否严格检查字段是否存在
'fields_strict' => true,
// 数据集返回类型
'resultset_type' => 'array',
// 自动写入时间戳字段
'auto_timestamp' => false,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 是否需要进行SQL性能分析
'sql_explain' => false,
]
];
\ No newline at end of file
<?php
return ["database" => [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => 'rds8eg4dcx15dfzx9tilo558.mysql.rds.aliyuncs.com',
// 数据库名
'database' => 'doc',
// 用户名
'username' => 'doc',
// 密码
'password' => 'doc00992783jh',
// 端口
'hostport' => '3306',
// 连接dsn
'dsn' => '',
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => '',
// 数据库调试模式
'debug' => true,
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 自动读取主库数据
'read_master' => false,
// 是否严格检查字段是否存在
'fields_strict' => true,
// 数据集返回类型
'resultset_type' => 'array',
// 自动写入时间戳字段
'auto_timestamp' => false,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 是否需要进行SQL性能分析
'sql_explain' => false,
]];
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment