This commit is contained in:
mkm 2023-06-07 09:14:57 +08:00
parent ab8732cf4a
commit f71a92c456
2 changed files with 79 additions and 44 deletions

View File

@ -2,78 +2,112 @@
namespace app\api\controller;
use Illuminate\Support\Env;
use support\Request;
use plugin\admin\app\model\Admin;
use plugin\admin\app\controller\Base;
use support\exception\BusinessException;
use plugin\admin\app\common\Util;
use plugin\admin\app\model\Project as ProjectModel;
use plugin\admin\app\model\Projectdata as ProjectdataModel;
use think\facade\Db;
class Project extends Base
{
public function list(Request $request){
$select=ProjectModel::paginate();
return json(['code'=>200,'msg'=>'获取成功','count'=>$select->total(),'data'=>$select->items()]);
/**
* 获取项目列表
*/
public function list(Request $request)
{
$select = Db::name('Projects')->where('is_delete',-1)->order('id', 'desc')->paginate($request->get('limit', 10));
return json(['code' => 200, 'msg' => '获取成功', 'count' => $select->total(), 'data' => $select->items()]);
}
public function edit(Request $request){
Db::name('Projects')->where('id', $request->post('id'))->update(['indexImage'=>$request->post('indexImage')]);
return json(['code'=>200,'msg'=>'更新成功']);
/**
* 更新图片
*/
public function edit(Request $request)
{
Db::name('Projects')->where('id', $request->post('id'))->update(['indexImage' => $request->post('indexImage')]);
return json(['code' => 200, 'msg' => '更新成功']);
}
public function create(Request $request){
/**
* 创建项目
*/
public function create(Request $request)
{
$data = $request->post();
$id= ProjectModel::insertGetId($data);
$res=ProjectModel::where('id',$id)->first();
$res['CreateTime']=$res['created_at'];
$res['CreateUserId']=1;
return $this->json(200,'ok',$res->toArray());
$id = ProjectModel::insertGetId($data);
$res = ProjectModel::where('id', $id)->first();
$res['CreateTime'] = $res['created_at'];
$res['CreateUserId'] = 1;
return $this->json(200, 'ok', $res->toArray());
}
public function publish(Request $request){
/**
* 更新项目
*/
public function publish(Request $request)
{
$data = $request->post();
$find=ProjectModel::find($data['id']);
$find['state']=$data['state'];
$find = ProjectModel::find($data['id']);
$find['state'] = $data['state'];
$find->save();
if($find){
return $this->json(200,'操作成功');
}else{
return $this->json(500,'操作失败');
if ($find) {
return $this->json(200, '操作成功');
} else {
return $this->json(500, '操作失败');
}
}
public function getData(Request $request){
/**
* 获取内容
*/
public function getData(Request $request)
{
$data = $request->get();
$find=ProjectModel::find($data['projectId']);
$ProjectdataModel=ProjectdataModel::where('project_id',$data['projectId'])->first();
if($ProjectdataModel){
$find['content']=$ProjectdataModel['content'];
}else{
$find['content']='';
$find = ProjectModel::find($data['projectId']);
$ProjectdataModel = ProjectdataModel::where('project_id', $data['projectId'])->first();
if ($ProjectdataModel) {
$find['content'] = $ProjectdataModel['content'];
} else {
$find['content'] = '';
}
return $this->json(200,'ok',$find->toArray());
return $this->json(200, 'ok', $find->toArray());
}
public function data(Request $request){
/**
* 保存内容
*/
public function data(Request $request)
{
$data = $request->post();
$find=Db::name('projectdatas')->where('project_id', $data['projectId'])->find();
if($find){
Db::name('projectdatas')->where('project_id',$data['projectId'])->update(['content'=>$data['content']]);
}else{
$id=Db::name('projectdatas')->insertGetId(['project_id'=>$data['projectId'],'content'=>$data['content']]);
$find=Db::name('projectdatas')->where('id', $id)->find();
$find = Db::name('projectdatas')->where('project_id', $data['projectId'])->find();
if ($find) {
Db::name('projectdatas')->where('project_id', $data['projectId'])->update(['content' => $data['content']]);
} else {
$id = Db::name('projectdatas')->insertGetId(['project_id' => $data['projectId'], 'content' => $data['content']]);
$find = Db::name('projectdatas')->where('id', $id)->find();
}
return $this->json(200,'ok',$find);
return $this->json(200, 'ok', $find);
}
public function upload(Request $request){
public function delete(Request $request)
{
$ids = $request->get('ids');
$res = Db::name('projects')->where('id', $ids)->update(['is_delete' => 1]);
if ($res) {
return $this->json(200, '删除成功');
} else {
return $this->json(500, '删除失败');
}
}
/**
* 上传图片
*/
public function upload(Request $request)
{
$file = current($request->file());
if (!$file || !$file->isValid()) {
return $this->json(1, '未找到文件');
}
$relative_dir='/upload/img/'.date('Ymd');
$relative_dir = '/upload/img/' . date('Ymd');
$relative_dir = ltrim($relative_dir, '/');
$file = current($request->file());
if (!$file || !$file->isValid()) {
@ -92,7 +126,7 @@ class Project extends Base
throw new BusinessException('不支持该格式的文件上传', 400);
}
$relative_path = $relative_dir . '/' . bin2hex(pack('Nn',time(), random_int(1, 65535))) . ".$ext";
$relative_path = $relative_dir . '/' . bin2hex(pack('Nn', time(), random_int(1, 65535))) . ".$ext";
$full_path = $base_dir . $relative_path;
var_dump($full_path);
@ -105,4 +139,4 @@ class Project extends Base
'size' => $file_size,
]);
}
}
}

View File

@ -22,6 +22,7 @@ Route::group('/api', function () {
Route::any('/getOssInfo',[app\api\controller\IndexController::class,'getOssInfo']);
});
Route::group('/project', function () {
Route::any('/delete',[app\api\controller\Project::class,'delete']);
Route::any('/create',[app\api\controller\Project::class,'create']);
Route::any('/edit',[app\api\controller\Project::class,'edit']);
Route::any('/upload',[app\api\controller\Project::class,'upload']);