Commit 7a7b5cf7 authored by huanle's avatar huanle

0520

parent 9c30511a
<?php
namespace app\api\controller;
use think\Request;
use think\Controller;
use app\api\model\Folder;
class Index extends Controller
{
public function index()
{
$model = new Folder();
$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,'请求失败'));
}
}
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($res){
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($name)){
return json(code([],10001,'名称不能为空'));
}else{
$res = $model->editFolder($name,$parentid,$folderid);
if($res){
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{
$res = $model->delFolder($folderid);
if($res){
return json(code([],0,'删除成功'));
}else{
return json(code([],10002,'删除失败'));
}
}
}
}
<?php
namespace app\api\model;
use think\Model;
use think\Db;
class Folder 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 folderList($parentid)
{
if (!$parentid) {
$where = ['parentid' => '', 'state' => 0];
} else {
$where = ['parentid' => $parentid, 'state' => 0];
}
$folderlist = Db::name('folder')->where($where)->order('')->select();
return $folderlist;
}
public function addFolder($name, $parentid)
{
$folderid = randomkeys(18);
$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;
}
}
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);
}
}
......@@ -10,3 +10,52 @@
// +----------------------------------------------------------------------
// 应用公共文件
/**
* 统一返回json
* @param array $data 业务数据
* @param int $code 错误码,0:成功,非0:失败
* @param string $msg 错误信息
*/
/**
* 生成带code的数组
* @param array $sendData 返回的数据
* @param int $errCode 错误码
* @param string $errMsg 附加详细错误信息
* @return array
*/
function code($sendData = [], $errCode = 0, $errMsg = '')
{
$_errCode = $errCode;
$_errMsg = $errMsg;
if (isset($_errMsg)) {
$_errMsg = $_errMsg;
// if (!empty($errMsg)) {
// $_errMsg .= empty($_errMsg) ? $errMsg : ':'.$errMsg;
// }
} else {
// 不存在的code,设置为未知错误
$_errCode = 10000;
$_errMsg = config("err_code.10000");
$_errMsg = $_errMsg;
}
// 组装返回数据
$return = ['err_code' => $_errCode, 'err_msg' => $_errMsg];
foreach ($sendData as $key => $value) {
$return["data"] = $value;
}
return $return;
}
function randomkeys($length)
{
$key = 'bp';
$pattern = '1234567890abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLOMNOPQRSTUVWXYZ';
for($i=0;$i<$length;$i++)
{
$key .= $pattern{mt_rand(0,35)}; //生成php随机数
}
return $key;
}
......@@ -158,7 +158,7 @@ return [
// 错误显示信息,非调试模式有效
'error_message' => '页面错误!请稍后再试~',
// 显示错误信息
'show_error_msg' => false,
'show_error_msg' => true,
// 异常处理handle类 留空使用 \think\exception\Handle
'exception_handle' => '',
......
......@@ -15,13 +15,13 @@ return [
// 服务器地址
'hostname' => '127.0.0.1',
// 数据库名
'database' => '',
'database' => 'doc',
// 用户名
'username' => 'root',
// 密码
'password' => '',
'password' => '123456',
// 端口
'hostport' => '',
'hostport' => '3306',
// 连接dsn
'dsn' => '',
// 数据库连接参数
......
<?php
namespace app\index\controller;
use think\Db;
class Index
{
public function index()
{
return '<style type="text/css">*{ padding: 0; margin: 0; } .think_default_text{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ad_bd568ce7058a1091"></think>';
$a=Db::table('folder')->where('state',-1)->find();
var_dump($a);
}
}
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