项目相关接口、图片视频上传
This commit is contained in:
@@ -15,6 +15,6 @@ class ProjectController extends BaseController
|
||||
$this->service = ProjectService::getInstance();
|
||||
$this->insertField = [ 'title', 'cover', 'description', 'category_id', 'video_url', 'price', 'front', 'service', 'deploy', 'status'];
|
||||
$this->updateField = [ 'id', 'title', 'cover', 'description', 'category_id', 'video_url', 'price', 'front', 'service', 'deploy', 'status'];
|
||||
$this->notRequest = ['features', 'screenshots', 'tags'];
|
||||
$this->notRequest = ['features', 'screenshots', 'labels', 'preferential_price'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Service;
|
||||
|
||||
use App\BaseApp\BaseService;
|
||||
use App\Enum\StatusEnum;
|
||||
use App\Models\FeatureModel;
|
||||
use App\Models\ProjectLabelRelationModel;
|
||||
use App\Models\ProjectModel;
|
||||
@@ -18,7 +19,7 @@ class ProjectService extends BaseService
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->selectField = [ 'id', 'user_id', 'title', 'cover', 'description', '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', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status', 'created_at', 'updated_at', 'deleted_at', ];
|
||||
$this->model = ProjectModel::class;
|
||||
}
|
||||
|
||||
@@ -33,9 +34,18 @@ class ProjectService extends BaseService
|
||||
$this->with = [
|
||||
'frameworks:id,name',
|
||||
'labels:id,name',
|
||||
'category:id,name',
|
||||
'screenshots:id,url,project_id',
|
||||
// 'features:id,project_id,name'
|
||||
];
|
||||
return $this->getPageList();
|
||||
$result = $this->getPageList();
|
||||
|
||||
foreach ($result['items'] as &$item) {
|
||||
$item['status_text'] = StatusEnum::from($item['status'])->description();
|
||||
$item['label_ids'] = array_column($item['labels'], 'id');
|
||||
$item['screenshots'] = array_column($item['screenshots'], 'url');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
@@ -43,6 +53,8 @@ class ProjectService extends BaseService
|
||||
$this->with = [
|
||||
'frameworks:id,name',
|
||||
'labels:id,name',
|
||||
'category:id,name',
|
||||
'screenshots:id,url,project_id',
|
||||
'features:id,project_id,name'
|
||||
];
|
||||
return $this->getDetail($id);
|
||||
@@ -68,11 +80,10 @@ class ProjectService extends BaseService
|
||||
{
|
||||
$params['user_id'] = $this->userId;
|
||||
$params['author_id'] = $params['author_id']?? $this->userId;
|
||||
// TODO 项目
|
||||
$screenshots = $params['screenshots'];
|
||||
$labels = $params['tags'];
|
||||
$labels = $params['labels'];
|
||||
$features = $params['features'];
|
||||
unset($params['screenshots'], $params['tags'], $params['features']);
|
||||
unset($params['screenshots'], $params['labels'], $params['features']);
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$insertProjectModel = $this->insert($params);
|
||||
@@ -120,12 +131,6 @@ class ProjectService extends BaseService
|
||||
DB::commit();
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
ds([
|
||||
'message' => $e->getMessage(),
|
||||
'line' => $e->getLine(),
|
||||
'file' => $e->getFile(),
|
||||
'code' => $e->getCode(),
|
||||
]);
|
||||
$this->utils->errorThrow($e->getMessage());
|
||||
}
|
||||
|
||||
@@ -141,7 +146,76 @@ class ProjectService extends BaseService
|
||||
*/
|
||||
public function update($id, $params): mixed
|
||||
{
|
||||
return $this->save($id, $params);
|
||||
$params['user_id'] = $this->userId;
|
||||
$params['author_id'] = $params['author_id']?? $this->userId;
|
||||
$screenshots = $params['screenshots']?? [];
|
||||
$labels = $params['labels']?? [];
|
||||
$features = $params['features']?? [];
|
||||
unset($params['screenshots'], $params['labels'], $params['features']);
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
// 更新项目基本信息
|
||||
$updateProjectModel = $this->save($id, $params);
|
||||
|
||||
// 先删除旧的标签关联数据
|
||||
ProjectLabelRelationModel::where('project_id', $id)->delete();
|
||||
$labelInsertData = [];
|
||||
foreach ($labels as $label) {
|
||||
$labelInsertData[] = [
|
||||
'project_id' => $id,
|
||||
'label_id' => $label,
|
||||
'created_at' => get_time()
|
||||
];
|
||||
}
|
||||
if (!empty($labelInsertData)) {
|
||||
$insertLabelModel = ProjectLabelRelationModel::insert($labelInsertData);
|
||||
if (!$insertLabelModel) {
|
||||
$this->utils->errorThrow('标签更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 先删除旧的功能数据
|
||||
FeatureModel::where('project_id', $id)->delete();
|
||||
$featureInsertData = [];
|
||||
foreach ($features as $feature) {
|
||||
$featureInsertData[] = [
|
||||
'project_id' => $id,
|
||||
'name' => $feature,
|
||||
'created_at' => get_time()
|
||||
];
|
||||
}
|
||||
if (!empty($featureInsertData)) {
|
||||
$insertFeatureModel = FeatureModel::insert($featureInsertData);
|
||||
if (!$insertFeatureModel) {
|
||||
$this->utils->errorThrow('项目功能更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 先删除旧的截图数据
|
||||
ScreenshotModel::where('project_id', $id)->delete();
|
||||
$screenInsertData = [];
|
||||
foreach ($screenshots as $screenshot) {
|
||||
$screenInsertData[] = [
|
||||
'project_id' => $id,
|
||||
'url' => $screenshot,
|
||||
'created_at' => get_time()
|
||||
];
|
||||
}
|
||||
if (!empty($screenInsertData)) {
|
||||
$insertScreenModel = ScreenshotModel::insert($screenInsertData);
|
||||
if (!$insertScreenModel) {
|
||||
$this->utils->errorThrow('项目截图更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
$this->utils->errorThrow($e->getMessage());
|
||||
}
|
||||
|
||||
return $updateProjectModel;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user