项目相关优化
This commit is contained in:
@@ -7,6 +7,7 @@ use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use function PHPUnit\Framework\isString;
|
||||
|
||||
class BaseController
|
||||
{
|
||||
@@ -144,7 +145,7 @@ class BaseController
|
||||
if (is_array($checkValue) && !empty($checkValue)) {
|
||||
$result[$fieldName] = $checkValue;
|
||||
} else {
|
||||
if (mb_strlen(strval($checkValue)) <= 0 && !in_array($fieldName, $this->notRequest)) {
|
||||
if ((empty($checkValue) && $checkValue !== 0) && !in_array($fieldName, $this->notRequest)) {
|
||||
$requiredFields[] = $fieldName;
|
||||
} else {
|
||||
if (!empty($checkValue) || $checkValue === 0) {
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\ProjectService;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class ProjectController extends BaseController
|
||||
{
|
||||
@@ -13,8 +15,27 @@ class ProjectController extends BaseController
|
||||
{
|
||||
parent::__construct();
|
||||
$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', 'labels', 'preferential_price'];
|
||||
$this->insertField = [ 'title', 'features', 'cover', 'labels', 'description', 'category_id', 'video_url', 'price', 'front', 'service', 'deploy', 'status', 'module_image', 'flowchart'];
|
||||
$this->updateField = [ 'id', 'title', 'features', 'cover', 'labels', 'description', 'category_id', 'video_url', 'price', 'front', 'service', 'deploy', 'status', 'module_image', 'flowchart'];
|
||||
$this->notRequest = ['screenshots', 'preferential_price', 'content'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改项目内容
|
||||
* @Method POST
|
||||
* @return JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function changeContent(): JsonResponse
|
||||
{
|
||||
$id = request()->post('id');
|
||||
$content = request()->post('content');
|
||||
if (empty($id) || empty($content)) {
|
||||
return jerr('参数错误');
|
||||
}
|
||||
return jok(
|
||||
$this->service->changeContent($id, $content),
|
||||
'修改成功'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,15 +62,6 @@ class ProjectModel extends BaseModel
|
||||
return $this->belongsToMany(FrameworkModel::class, 'project_frameworks_relations', 'project_id', 'framework_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 技术栈关联
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function technologyStacks(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(TechnologyStackModel::class, 'project_technology_stacks_relations', 'project_id', 'technology_stacks_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能关联
|
||||
* @return HasMany
|
||||
|
||||
@@ -22,7 +22,7 @@ class HomeService extends BaseService
|
||||
{
|
||||
$this->isAuth = false;
|
||||
parent::__construct();
|
||||
$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->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->model = ProjectModel::class;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class ProjectService extends BaseService
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$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->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->model = ProjectModel::class;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ class ProjectService extends BaseService
|
||||
{
|
||||
$this->with = [
|
||||
'frameworks:id,name',
|
||||
'features:id,project_id,name',
|
||||
'labels:id,name',
|
||||
'category:id,name',
|
||||
'screenshots:id,url,project_id',
|
||||
@@ -45,6 +46,7 @@ class ProjectService extends BaseService
|
||||
|
||||
foreach ($result['items'] as &$item) {
|
||||
$item['status_text'] = ProjectStatusEnum::from($item['status'])->description();
|
||||
$item['features_names'] = array_column($item['features'], 'name');
|
||||
$item['label_ids'] = array_column($item['labels'], 'id');
|
||||
$item['screenshots'] = array_column($item['screenshots'], 'url');
|
||||
}
|
||||
@@ -75,6 +77,18 @@ class ProjectService extends BaseService
|
||||
return $this->getOption();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改项目详细介绍
|
||||
* @param $id
|
||||
* @param $content
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function changeContent($id, $content)
|
||||
{
|
||||
return $this->save($id, ['content' => $content]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建项目
|
||||
* @param $params
|
||||
@@ -91,6 +105,9 @@ class ProjectService extends BaseService
|
||||
if (empty($params['preferential_price'])) {
|
||||
$params['preferential_price'] = $params['price'];
|
||||
}
|
||||
if (empty($params['content'])) {
|
||||
$params['content'] = '';
|
||||
}
|
||||
unset($params['screenshots'], $params['labels'], $params['features']);
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
@@ -167,6 +184,9 @@ class ProjectService extends BaseService
|
||||
$features = $params['features']?? [];
|
||||
unset($params['screenshots'], $params['labels'], $params['features']);
|
||||
|
||||
if (empty($params['content'])) {
|
||||
$params['content'] = '';
|
||||
}
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
// 更新项目基本信息
|
||||
|
||||
Reference in New Issue
Block a user