项目相关功能完善

This commit is contained in:
2025-05-08 14:10:45 +08:00
parent 8ea4f2bafd
commit 0d51623bbf
4 changed files with 65 additions and 2 deletions

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Enum;
/**
* 状态码定义
*/
enum ProjectFieldTypeEnum: int
{
case SOLD = 1;
case SELECTED = 2;
case CAROUSEL = 3;
public function description(): string
{
return match ($this) {
self::SELECTED => 'is_selected',
self::CAROUSEL => 'is_carousel',
self::SOLD => 'is_sold',
};
}
}

View File

@@ -38,4 +38,23 @@ class ProjectController extends BaseController
'修改成功'
);
}
/**
* 修改项目内容
* @Method POST
* @return JsonResponse
* @throws Exception
*/
public function changeType(): JsonResponse
{
$id = request()->post('id');
$type = request()->post('type');
if (empty($id) || empty($type)) {
return jerr('参数错误');
}
return jok(
$this->service->changeType($id, $type),
'修改成功'
);
}
}

View File

@@ -22,7 +22,7 @@ class HomeService extends BaseService
{
$this->isAuth = false;
parent::__construct();
$this->selectField = [ 'id', 'user_id', 'title', 'cover', 'category_id', 'description', 'module_image', 'flowchart', 'content', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status', 'created_at', 'updated_at', 'deleted_at', ];
$this->selectField = [ 'id', 'user_id', 'title', 'cover', 'category_id', 'is_sold', 'description', 'module_image', 'flowchart', 'content', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status', 'created_at', 'updated_at', 'deleted_at', ];
$this->model = ProjectModel::class;
}

View File

@@ -3,6 +3,7 @@
namespace App\Service;
use App\BaseApp\BaseService;
use App\Enum\ProjectFieldTypeEnum;
use App\Enum\ProjectStatusEnum;
use App\Enum\StatusEnum;
use App\Models\CollectionModel;
@@ -21,7 +22,7 @@ class ProjectService extends BaseService
public function __construct()
{
parent::__construct();
$this->selectField = [ 'id', 'user_id', 'title', 'module_image', 'flowchart', 'content', 'cover', 'category_id', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status', 'created_at', 'updated_at', 'deleted_at', ];
$this->selectField = [ 'id', 'user_id', 'title', 'is_selected', 'is_carousel', 'module_image', 'is_sold', 'flowchart', 'content', 'cover', 'category_id', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status', 'created_at', 'updated_at', 'deleted_at', ];
$this->model = ProjectModel::class;
}
@@ -263,4 +264,25 @@ class ProjectService extends BaseService
return $this->del($ids);
}
/**
* 修改项目(是否精选、是否出售、是否为轮播图)
* @param $id
* @param $type
* @return mixed
* @throws Exception
*/
public function changeType($id, $type)
{
$field = ProjectFieldTypeEnum::from($type)->description();
$this->selectField = [$field];
$detail = $this->detail($id);
if (empty($detail)) {
$this->utils->errorThrow('项目不存在');
}
$update = $this->save($id, [$field => $detail[$field] === 0? 1 : 0]);
if (!$update) {
$this->utils->errorThrow('项目状改失败');
}
return $update;
}
}