项目相关功能完善
This commit is contained in:
22
app/Enum/ProjectFieldTypeEnum.php
Executable file
22
app/Enum/ProjectFieldTypeEnum.php
Executable 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',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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),
|
||||||
|
'修改成功'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class HomeService extends BaseService
|
|||||||
{
|
{
|
||||||
$this->isAuth = false;
|
$this->isAuth = false;
|
||||||
parent::__construct();
|
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;
|
$this->model = ProjectModel::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
use App\BaseApp\BaseService;
|
use App\BaseApp\BaseService;
|
||||||
|
use App\Enum\ProjectFieldTypeEnum;
|
||||||
use App\Enum\ProjectStatusEnum;
|
use App\Enum\ProjectStatusEnum;
|
||||||
use App\Enum\StatusEnum;
|
use App\Enum\StatusEnum;
|
||||||
use App\Models\CollectionModel;
|
use App\Models\CollectionModel;
|
||||||
@@ -21,7 +22,7 @@ class ProjectService extends BaseService
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__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;
|
$this->model = ProjectModel::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,4 +264,25 @@ class ProjectService extends BaseService
|
|||||||
return $this->del($ids);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user