前台部分接口
This commit is contained in:
25
app/Enum/ProjectStatusEnum.php
Executable file
25
app/Enum/ProjectStatusEnum.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enum;
|
||||
/**
|
||||
* 状态码定义
|
||||
*/
|
||||
enum ProjectStatusEnum: int
|
||||
{
|
||||
|
||||
// '状态 0:草稿 1:上架 2:下架 3:重构中'
|
||||
case DRAFT = 0;
|
||||
case ON_SHELF = 1;
|
||||
case OFF_SHELF = 2;
|
||||
case REBUILD = 3;
|
||||
public function description(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::DRAFT => '草稿',
|
||||
self::ON_SHELF => '上架',
|
||||
self::OFF_SHELF => '下架',
|
||||
self::REBUILD => '重构中',
|
||||
default => '未知状态',
|
||||
};
|
||||
}
|
||||
}
|
||||
18
app/Http/Controllers/CollectionController.php
Normal file
18
app/Http/Controllers/CollectionController.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\CollectionService;
|
||||
|
||||
class CollectionController extends BaseController
|
||||
{
|
||||
//
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = CollectionService::getInstance();
|
||||
$this->insertField = ['project_id'];
|
||||
}
|
||||
}
|
||||
21
app/Http/Controllers/FileController.php
Normal file
21
app/Http/Controllers/FileController.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\FileService;
|
||||
use App\Service\ProjectService;
|
||||
use App\Service\RoleService;
|
||||
|
||||
class FileController extends BaseController
|
||||
{
|
||||
//
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = FileService::getInstance();
|
||||
$this->insertField = ['url', 's'];
|
||||
$this->updateField = ['id', 'url', 's'];
|
||||
}
|
||||
}
|
||||
36
app/Http/Controllers/HomeController.php
Normal file
36
app/Http/Controllers/HomeController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\HomeService;
|
||||
use App\Service\ProjectService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class HomeController extends BaseController
|
||||
{
|
||||
//
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = HomeService::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 轮播图列表
|
||||
* @Method GET
|
||||
* @return JsonResponse
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function carousel(): JsonResponse
|
||||
{
|
||||
return jok(
|
||||
$this->service->carousel(),
|
||||
'轮播图列表'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -53,4 +53,32 @@ class UserController extends BaseController
|
||||
'重置密码成功'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户信息
|
||||
* @Method GET
|
||||
* @return JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function myInfo(): JsonResponse
|
||||
{
|
||||
return jok(
|
||||
$this->service->myInfo(),
|
||||
'获取成功'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户信息
|
||||
* @Method GET
|
||||
* @return JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function userStats(): JsonResponse
|
||||
{
|
||||
return jok(
|
||||
$this->service->userStats(),
|
||||
'获取成功'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
36
app/Models/CollectionModel.php
Normal file
36
app/Models/CollectionModel.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\BaseApp\BaseModel;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
/**
|
||||
* 用户收藏表
|
||||
*/
|
||||
class CollectionModel extends BaseModel
|
||||
{
|
||||
//
|
||||
protected $table = 'collection';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 用户关联
|
||||
* @return HasOne
|
||||
*/
|
||||
public function user(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserModel::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目关联
|
||||
* @return HasOne
|
||||
*/
|
||||
public function project(): HasOne
|
||||
{
|
||||
return $this->hasOne(ProjectModel::class, 'id', 'project_id');
|
||||
}
|
||||
}
|
||||
27
app/Models/FileModel.php
Normal file
27
app/Models/FileModel.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\BaseApp\BaseModel;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
/**
|
||||
* 用户表
|
||||
*/
|
||||
class FileModel extends BaseModel
|
||||
{
|
||||
//
|
||||
protected $table = 'file';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 角色关联
|
||||
* @return HasOne
|
||||
*/
|
||||
public function user(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserModel::class, 'id', 'user_id');
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\BaseApp\BaseModel;
|
||||
|
||||
/**
|
||||
* 项目技术栈关联表
|
||||
*/
|
||||
class ProjectTechnologyStacksRelationModel extends BaseModel
|
||||
{
|
||||
//
|
||||
protected $table = 'project_technology_stacks_relations';
|
||||
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\BaseApp\BaseModel;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
/**
|
||||
* 技术栈表
|
||||
*/
|
||||
class TechnologyStackModel extends BaseModel
|
||||
{
|
||||
//
|
||||
protected $table = 'technology_stacks';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 项目关联
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function projects(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(ProjectModel::class, 'project_technology_stack_relations', 'technology_stack_id', 'project_id');
|
||||
}
|
||||
}
|
||||
36
app/Models/UserPayModel.php
Normal file
36
app/Models/UserPayModel.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\BaseApp\BaseModel;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
/**
|
||||
* 用户收藏表
|
||||
*/
|
||||
class UserPayModel extends BaseModel
|
||||
{
|
||||
//
|
||||
protected $table = 'user_pay';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 用户关联
|
||||
* @return HasOne
|
||||
*/
|
||||
public function user(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserModel::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目关联
|
||||
* @return HasOne
|
||||
*/
|
||||
public function project(): HasOne
|
||||
{
|
||||
return $this->hasOne(ProjectModel::class, 'id', 'project_id');
|
||||
}
|
||||
}
|
||||
90
app/Service/CollectionService.php
Normal file
90
app/Service/CollectionService.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BaseApp\BaseService;
|
||||
use App\Models\CollectionModel;
|
||||
use App\Models\FileModel;
|
||||
use App\Models\ProjectModel;
|
||||
use App\Models\RoleModel;
|
||||
use App\Models\UserModel;
|
||||
use Exception;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class CollectionService extends BaseService
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->selectField = ['id', 'user_id', 'project_id', 'created_at', 'updated_at', 'deleted_at'];
|
||||
$this->model = CollectionModel::class;
|
||||
$this->where[] = ['user_id', '=', $this->userId];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户收藏列表
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function list(): array
|
||||
{
|
||||
$this->with = [
|
||||
'project:id,title,cover,category_id,description,price,preferential_price,front,service,deploy,status,created_at,updated_at',
|
||||
'project.category:id,name',
|
||||
'project.labels:id,name',
|
||||
];
|
||||
return $this->getPageList();
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
return $this->getDetail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户收藏下拉列表
|
||||
* @return mixed
|
||||
*/
|
||||
public function option()
|
||||
{
|
||||
$this->optionField = ['id', 'url'];
|
||||
return $this->getOption();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建用户收藏
|
||||
* @param $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create($params): mixed
|
||||
{
|
||||
return $this->insert($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑用户收藏
|
||||
* @param $id
|
||||
* @param $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update($id, $params): mixed
|
||||
{
|
||||
return $this->save($id, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户收藏
|
||||
* @param $ids
|
||||
* @return mixed|true
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete($ids): mixed
|
||||
{
|
||||
return $this->del($ids);
|
||||
}
|
||||
|
||||
}
|
||||
83
app/Service/FileService.php
Normal file
83
app/Service/FileService.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BaseApp\BaseService;
|
||||
use App\Models\FileModel;
|
||||
use App\Models\ProjectModel;
|
||||
use App\Models\RoleModel;
|
||||
use App\Models\UserModel;
|
||||
use Exception;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class FileService extends BaseService
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->selectField = ['id', 'user_id', 'url', 'type', 'created_at', 'updated_at', 'deleted_at'];
|
||||
$this->model = FileModel::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function list(): array
|
||||
{
|
||||
return $this->getPageList();
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
return $this->getDetail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件下拉列表
|
||||
* @return mixed
|
||||
*/
|
||||
public function option()
|
||||
{
|
||||
$this->optionField = ['id', 'url'];
|
||||
return $this->getOption();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件
|
||||
* @param $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create($params): mixed
|
||||
{
|
||||
return $this->insert($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文件
|
||||
* @param $id
|
||||
* @param $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update($id, $params): mixed
|
||||
{
|
||||
return $this->save($id, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param $ids
|
||||
* @return mixed|true
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete($ids): mixed
|
||||
{
|
||||
return $this->del($ids);
|
||||
}
|
||||
|
||||
}
|
||||
76
app/Service/HomeService.php
Normal file
76
app/Service/HomeService.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BaseApp\BaseService;
|
||||
use App\Enum\ProjectStatusEnum;
|
||||
use App\Enum\StatusEnum;
|
||||
use App\Models\FeatureModel;
|
||||
use App\Models\ProjectLabelRelationModel;
|
||||
use App\Models\ProjectModel;
|
||||
use App\Models\ScreenshotModel;
|
||||
use App\Models\UserModel;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class HomeService extends BaseService
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$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->model = ProjectModel::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目列表
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function list(): array
|
||||
{
|
||||
$this->where[] = [ 'is_selected', '=', 1 ];
|
||||
$this->where[] = [ 'status', '=', 1 ];
|
||||
$this->with = [
|
||||
'frameworks:id,name',
|
||||
'labels:id,name',
|
||||
'category:id,name',
|
||||
];
|
||||
return $this->getPageList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目列表
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function carousel(): array
|
||||
{
|
||||
$this->where[] = [ 'is_carousel', '=', 1 ];
|
||||
$this->where[] = [ 'status', '=', 1 ];
|
||||
$this->with = [
|
||||
'frameworks:id,name',
|
||||
'labels:id,name',
|
||||
'category:id,name',
|
||||
];
|
||||
return $this->getPageList();
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
$this->with = [
|
||||
'frameworks:id,name',
|
||||
'labels:id,name',
|
||||
'category:id,name',
|
||||
'screenshots:id,url,project_id',
|
||||
'features:id,project_id,name',
|
||||
'author:id,nick_name,avatar,email'
|
||||
];
|
||||
return $this->getDetail($id);
|
||||
}
|
||||
}
|
||||
@@ -114,16 +114,18 @@ class LoginService
|
||||
UtilsService::getInstance()->errorThrow('注册失败!');
|
||||
}
|
||||
|
||||
$userInfo = UserModel::with(['roles:id,name,value'])->where('id', $createModel->id)->first();
|
||||
|
||||
$result = [
|
||||
'id' => $createModel->id,
|
||||
'account' => $createModel->account,
|
||||
'nick_name' => $createModel->nick_name,
|
||||
'avatar' => $createModel->avatar,
|
||||
'email' => $userModel->email?? '',
|
||||
'role_name' => $userModel->roles->name,
|
||||
'role_value' => $userModel->roles->value,
|
||||
'ip' => $createModel->ip,
|
||||
'ip_table' => $createModel->ip_table,
|
||||
'id' => $userInfo->id,
|
||||
'account' => $userInfo->account,
|
||||
'nick_name' => $userInfo->nick_name,
|
||||
'avatar' => $userInfo->avatar,
|
||||
'email' => $userInfo->email?? '',
|
||||
'role_name' => $userInfo->roles->name,
|
||||
'role_value' => $userInfo->roles->value,
|
||||
'ip' => $userInfo->ip,
|
||||
'ip_table' => $userInfo->ip_table,
|
||||
];
|
||||
$token = JWTService::getInstance()->generateToken($result);
|
||||
$result['token'] = $token;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Service;
|
||||
|
||||
use App\BaseApp\BaseService;
|
||||
use App\Enum\ProjectStatusEnum;
|
||||
use App\Enum\StatusEnum;
|
||||
use App\Models\FeatureModel;
|
||||
use App\Models\ProjectLabelRelationModel;
|
||||
@@ -36,12 +37,13 @@ class ProjectService extends BaseService
|
||||
'labels:id,name',
|
||||
'category:id,name',
|
||||
'screenshots:id,url,project_id',
|
||||
// 'features:id,project_id,name'
|
||||
// 'features:id,project_id,name',
|
||||
'author:id,nick_name,avatar'
|
||||
];
|
||||
$result = $this->getPageList();
|
||||
|
||||
foreach ($result['items'] as &$item) {
|
||||
$item['status_text'] = StatusEnum::from($item['status'])->description();
|
||||
$item['status_text'] = ProjectStatusEnum::from($item['status'])->description();
|
||||
$item['label_ids'] = array_column($item['labels'], 'id');
|
||||
$item['screenshots'] = array_column($item['screenshots'], 'url');
|
||||
}
|
||||
@@ -55,7 +57,8 @@ class ProjectService extends BaseService
|
||||
'labels:id,name',
|
||||
'category:id,name',
|
||||
'screenshots:id,url,project_id',
|
||||
'features:id,project_id,name'
|
||||
'features:id,project_id,name',
|
||||
'author:id,nick_name,avatar'
|
||||
];
|
||||
return $this->getDetail($id);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ namespace App\Service;
|
||||
|
||||
use App\BaseApp\BaseService;
|
||||
use App\Enum\UserStatusEnum;
|
||||
use App\Models\CollectionModel;
|
||||
use App\Models\RoleModel;
|
||||
use App\Models\UserModel;
|
||||
use App\Models\UserPayModel;
|
||||
use Exception;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@@ -160,4 +163,48 @@ class UserService extends BaseService
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function myInfo(): mixed
|
||||
{
|
||||
$this->with = [
|
||||
'roles'
|
||||
];
|
||||
$result = $this->getDetail($this->userId);
|
||||
$result['created_day_at'] = format_time(strtotime($result['created_at']), 'Y-m-d');
|
||||
$result['account'] = desensitization($result['account']);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户统计
|
||||
* @return array[]
|
||||
*/
|
||||
public function userStats()
|
||||
{
|
||||
$payProject = UserPayModel::where('user_id', $this->userId)->count();
|
||||
$collection = CollectionModel::where('user_id', $this->userId)->count();
|
||||
$role = $this->userInfo['role_name'];
|
||||
return [
|
||||
'pay_project' => [
|
||||
'label' => '已购项目',
|
||||
'value' => $payProject,
|
||||
'icon' => 'shopping-bag'
|
||||
],
|
||||
'collection' => [
|
||||
'label' => '我的收藏',
|
||||
'value' => $collection,
|
||||
'icon' => 'heart'
|
||||
],
|
||||
'role' => [
|
||||
'label' => '用户类型',
|
||||
'value' => $role,
|
||||
'icon' => 'user'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class JWTService
|
||||
'exp' => $expirationTime,
|
||||
'data' => $data
|
||||
];
|
||||
|
||||
RedisService::getInstance()->init(config('cc.redis.jwt'))->set($data['id'], json_encode($data));
|
||||
return JWT::encode($payload, $this->secretKey, 'HS256');
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Models\ProjectModel;
|
||||
use App\Models\RoleModel;
|
||||
use App\Models\UserModel;
|
||||
use App\Service\common\upload\QiniuStorageService;
|
||||
use App\Service\FileService;
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
@@ -20,28 +21,52 @@ class UploadService extends BaseService
|
||||
$this->model = RoleModel::class;
|
||||
}
|
||||
|
||||
public function uploadImage($file)
|
||||
/**
|
||||
* 上传OSS图片
|
||||
* @param $file
|
||||
* @return array|bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function uploadImage($file): array|bool
|
||||
{
|
||||
// 获取文件后缀
|
||||
$ext = $file->getClientOriginalExtension();
|
||||
$key = 'spa/image/'. date('Ymd') . '/' . 'cc_upload_'. Str::random(). uniqid() . '.' . $ext;
|
||||
return [
|
||||
// $result = QiniuStorageService::getInstance()->uploadVideo($file, $key);
|
||||
$result = [
|
||||
'key' => $key,
|
||||
'url' => 'https://img2.baidu.com/it/u=1629222614,1358629025&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500&a='. rand(1111111, 9999999)
|
||||
];
|
||||
return QiniuStorageService::getInstance()->uploadImage($file, $key);
|
||||
FileService::getInstance()->create([
|
||||
'user_id' => $this->userId,
|
||||
'url' => $result['url'],
|
||||
]);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function uploadVideo($file)
|
||||
/**
|
||||
* 上传OSS视频
|
||||
* @param $file
|
||||
* @return array|bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function uploadVideo($file): array|bool
|
||||
{
|
||||
// 获取文件后缀
|
||||
$ext = $file->getClientOriginalExtension();
|
||||
$key = 'spa/video/'. date('Ymd') . '/' . 'cc_upload_'. Str::random(). uniqid() . '.' . $ext;
|
||||
return [
|
||||
// $result = QiniuStorageService::getInstance()->uploadVideo($file, $key);
|
||||
$result = [
|
||||
'key' => $key,
|
||||
'url' => 'http://d-jy.nailaoyun.cn/storage/video//20250410/ca1bbbb3af5853c7fc4ef23b8a918922.mp4?a='. rand(1111111, 9999999)
|
||||
'url' => 'https://img2.baidu.com/it/u=1629222614,1358629025&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500&a='. rand(1111111, 9999999)
|
||||
];
|
||||
return QiniuStorageService::getInstance()->uploadVideo($file, $key);
|
||||
FileService::getInstance()->create([
|
||||
'user_id' => $this->userId,
|
||||
'url' => $result['url'],
|
||||
]);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ Route::get('/', function () {
|
||||
*/
|
||||
UtilsService::class::getInstance()->autoRouteRegister([
|
||||
'' => \App\Http\Controllers\LoginController::class, // 登录控制器
|
||||
'home' => \App\Http\Controllers\HomeController::class, // 首页控制器
|
||||
]);
|
||||
|
||||
Route::group([], function () {
|
||||
@@ -22,5 +23,6 @@ Route::group([], function () {
|
||||
'upload' => \App\Http\Controllers\UploadController::class, // 上传控制器
|
||||
'label' => \App\Http\Controllers\LabelController::class, // 标签控制器
|
||||
'category' => \App\Http\Controllers\CategoryController::class, // 分类控制器
|
||||
'collection' => \App\Http\Controllers\CollectionController::class, // 收藏控制器
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user