Compare commits

..

6 Commits

Author SHA1 Message Date
lq
edefaa4379 功能视频测试
Some checks failed
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
2025-05-28 16:51:40 +08:00
lq
2b767fb17b 项目相关功能完善
Some checks failed
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
2025-05-08 14:10:53 +08:00
lq
0d51623bbf 项目相关功能完善 2025-05-08 14:10:45 +08:00
lq
8ea4f2bafd 项目相关优化 2025-05-08 13:28:56 +08:00
lq
e68c2dc663 项目列表
Some checks failed
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
2025-05-07 23:40:40 +08:00
lq
6b4d1e5be3 项目列表 2025-05-07 23:40:31 +08:00
6 changed files with 117 additions and 15 deletions

View File

@@ -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) {

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

@@ -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,49 @@ 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->insertField = [ 'title', 'features', 'cover', 'labels', 'description', 'category_id', 'price', 'front', 'service', 'deploy', 'status', 'module_image', 'flowchart'];
$this->updateField = [ 'id', 'title', 'features', 'cover', 'labels', 'description', 'category_id', 'price', 'front', 'service', 'deploy', 'status', 'module_image', 'flowchart'];
$this->notRequest = ['screenshots', 'preferential_price', 'content', 'video_url'];
}
/**
* 修改项目内容
* @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),
'修改成功'
);
}
/**
* 修改项目内容
* @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

@@ -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

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', '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;
}
@@ -52,6 +52,9 @@ class HomeService extends BaseService
*/
public function projectList(): array
{
$this->queryField = [
'title' => 'like'
];
$this->where[] = [ 'status', '=', 1 ];
$this->with = [
'frameworks:id,name',

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', '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;
}
@@ -35,6 +36,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 +47,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 +78,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 +106,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 +185,9 @@ class ProjectService extends BaseService
$features = $params['features']?? [];
unset($params['screenshots'], $params['labels'], $params['features']);
if (empty($params['content'])) {
$params['content'] = '';
}
DB::beginTransaction();
try {
// 更新项目基本信息
@@ -243,4 +264,25 @@ class ProjectService extends BaseService
return $this->del($ids);
}
/**
* 修改项目(是否精选、是否出售、是否为轮播图)
* @param $id
* @param $type
* @return mixed
* @throws Exception
*/
public function changeType($id, $type): mixed
{
$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;
}
}