样机小程序
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\AgreementService;
|
||||
|
||||
class AgreementController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new AgreementService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\service\AuthService;
|
||||
use app\common\validate\UserValidate;
|
||||
use support\Redis;
|
||||
use support\Request;
|
||||
|
||||
class AuthController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要头信息的方法
|
||||
*/
|
||||
protected $noNeedHeaderData = ['feishuAuth'];
|
||||
|
||||
protected $noNeedLogin = ['feishuScope', 'login', 'register', 'feishuAuth'];
|
||||
|
||||
|
||||
// 调试
|
||||
public function feishuAuth(Request $request)
|
||||
{
|
||||
try {
|
||||
$code = $request->all();
|
||||
return $this->success($code);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function feishuScope(Request $request)
|
||||
{
|
||||
try {
|
||||
$result = (new AuthService())->feishuAuthorize($request->corp_abbr, $request->system_code);
|
||||
return $this->success($result);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function login(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = $this->validate(new UserValidate(), $this->requestData($request), $request->login_type.'_login');
|
||||
$result = (new AuthService())->login($data);
|
||||
return $this->success($result, '登录成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function register(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = $this->validate(new UserValidate(), $this->requestData($request), $request->login_type.'_register');
|
||||
$result = (new AuthService())->register($data);
|
||||
return $this->success($result, '注册成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function refresh(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = $this->requestData($request);
|
||||
if (!$data['refresh_token'] || !$data['system_code']) return $this->error('参数缺失', 422);
|
||||
$result = (new AuthService())->refreshToken($data['refresh_token'], $data['system_code']);
|
||||
return $this->success($result, '刷新成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage(), 401);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// public function perm(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $data = $this->requestData($request);
|
||||
// if (!$data['access_token'] || !$data['system_code']) return $this->error('参数缺失', 422);
|
||||
// $result = (new AuthService())->logout($data['access_token'], $data['system_code']);
|
||||
// return $this->success($result, '已登出');
|
||||
// } catch (\Throwable $e) {}
|
||||
// }
|
||||
|
||||
// public function verify(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $token = $request->post('access_token') ?: $request->header('authorization');
|
||||
// $systemCode = $request->post('system_code');
|
||||
// if (!$token || !$systemCode) return $this->error('参数缺失', 422);
|
||||
// $payload = (new AuthService())->verifyToken($token, $systemCode);
|
||||
// return $this->success($payload, '验证成功');
|
||||
// } catch (\Throwable $e) {
|
||||
// return $this->error($e->getMessage() ?: '无效或过期的token', 401);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public function logout(Request $request)
|
||||
// {
|
||||
// $token = $request->post('access_token') ?: $request->header('Authorization');
|
||||
// $systemCode = $request->post('system_code') ?: $request->header('system_code');
|
||||
// (new AuthService())->logout($token, $systemCode);
|
||||
// return $this->success([], '已登出');
|
||||
// }
|
||||
|
||||
// public function blockToken(Request $request)
|
||||
// {
|
||||
// $token = $request->post('token');
|
||||
// $systemCode = $request->post('system_code');
|
||||
// if (!$token || !$systemCode) return $this->error('参数缺失', 422);
|
||||
// (new AuthService())->blockToken($token, $systemCode);
|
||||
// return $this->success([], '已强制停用该token');
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\BannerService;
|
||||
use support\Request;
|
||||
|
||||
class BannerController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $noNeedLogin = ['getAll'];
|
||||
|
||||
protected $noNeedHeaderData = ['getAll'];
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new BannerService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 轮播
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function getAll(Request $request)
|
||||
{
|
||||
try {
|
||||
$params = $request->all();
|
||||
$result = $this->service->getBanner($params);
|
||||
foreach ($result as $key => $value) {
|
||||
if (isset($value['image_url']) && !empty($value['image_url'])){
|
||||
$ossservice = new OssService();
|
||||
$result[$key]['image_url_pull'] = $ossservice->generatePrivateUrl($value['image_url']);
|
||||
}
|
||||
}
|
||||
return $this->success($result, '获取轮播列表');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
if (isset($data['image_url']) && !empty($data['image_url'])){
|
||||
$ossservice = new OssService();
|
||||
$data['image_url_pull'] = $ossservice->generatePrivateUrl($data['image_url']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
use support\exception\BusinessException;
|
||||
use app\common\traits\ResponseTrait;
|
||||
use app\common\traits\DataTransformer;
|
||||
use think\Validate;
|
||||
use support\Request;
|
||||
|
||||
class BaseController
|
||||
{
|
||||
/**
|
||||
* 响应处理、数据格式化处理
|
||||
*/
|
||||
use ResponseTrait, DataTransformer;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
* @var Validate
|
||||
*/
|
||||
protected mixed $validator = null;
|
||||
|
||||
/**
|
||||
* @var Model
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
/**
|
||||
* 不登录不鉴权
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedLogin = [];
|
||||
|
||||
/**
|
||||
* 登录不鉴权
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedAuth = [];
|
||||
|
||||
/**
|
||||
* 不用头部数据
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedHeaderData = [];
|
||||
|
||||
/**
|
||||
* 数据限制
|
||||
* null 不做限制,任何管理员都可以查看该表的所有数据
|
||||
* auth 管理员能看到自己以及自己的子管理员插入的数据
|
||||
* personal 管理员只能看到自己插入的数据
|
||||
* @var string
|
||||
*/
|
||||
protected $dataLimit = null;
|
||||
|
||||
/**
|
||||
* 数据限制字段
|
||||
*/
|
||||
protected $dataLimitField = 'admin_id';
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
*
|
||||
* @param Validate $validator 验证器实例
|
||||
* @param array $data 待验证的数据
|
||||
* @param string $scene 验证场景
|
||||
* @return array 验证后的数据
|
||||
* @throws BusinessException 验证失败时抛出业务异常
|
||||
*/
|
||||
public function validate(Validate $validator, array $data, string $scene = ''): array
|
||||
{
|
||||
// 如果指定了验证场景,并且验证器支持场景方法,则设置验证场景
|
||||
if ($scene && method_exists($validator, 'scene')) {
|
||||
$validator->scene($scene);
|
||||
}
|
||||
// 执行数据验证
|
||||
if (!$validator->check($data)) {
|
||||
// 验证失败,抛出业务异常,异常信息为验证器返回的错误信息
|
||||
throw new BusinessException($validator->getError());
|
||||
}
|
||||
// 验证成功,返回原始数据
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数处理
|
||||
*/
|
||||
public function requestData(Request $request)
|
||||
{
|
||||
return $request->all() + $request->basic_data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\Post;
|
||||
use app\common\model\PostComment;
|
||||
use app\common\model\PostMedia;
|
||||
use app\common\model\User;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\MessageNoticeService;
|
||||
use support\Request;
|
||||
|
||||
class MessageNoticeController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new MessageNoticeService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回分页数据及总数
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceSelfList($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||
? [$this, 'indexFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
if (isset($data['post_id'])){
|
||||
$data['post'] = Post::where('id', $data['post_id'])->first();
|
||||
$data['post']['media'] = PostMedia::where('post_id', $data['post_id'])->get();
|
||||
}
|
||||
if (isset($data['sender_user_id'])){
|
||||
$ossservice = new OssService();
|
||||
$data['sender_user'] = User::where('id', $data['sender_user_id'])->select(['nickname', 'avatar', 'openid'])->first();
|
||||
|
||||
if(!str_contains($data['sender_user']['avatar'], 'http') && !empty($data['sender_user']['avatar'])){
|
||||
$data['sender_user']['avatar_pull'] = $ossservice->generatePrivateUrl($data['sender_user']['avatar']);
|
||||
}
|
||||
}
|
||||
if (!empty($data['comment_id'])){
|
||||
$data['comment'] = PostComment::where('id', $data['comment_id'])->first();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\PostCategoryService;
|
||||
|
||||
class PostCategoryController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new PostCategoryService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
if (!empty($data['icon'])){
|
||||
$ossservice = new OssService();
|
||||
$data['icon_pull'] = $ossservice->generatePrivateUrl($data['icon']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\PostComment;
|
||||
use app\common\model\User;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\PostCommentService;
|
||||
use support\Request;
|
||||
|
||||
class PostCommentController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new PostCommentService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
if (isset($data['id'])){
|
||||
$data['child'] = [];
|
||||
$child = PostComment::where(['parent_id' => $data['id']])->first();
|
||||
if(!empty($child)){
|
||||
$child = $child->toArray();
|
||||
}
|
||||
$data['count'] = PostComment::where(['parent_id' => $data['id']])->count();
|
||||
if (isset($child['user_id'])){
|
||||
$ossservice = new OssService();
|
||||
$child['user'] = User::where('id', $child['user_id'])->select(['nickname', 'avatar', 'openid'])->first();
|
||||
if(!str_contains($child['user']['avatar'], 'http') && !empty($child['user']['avatar'])){
|
||||
$child['user']['avatar_pull'] = $ossservice->generatePrivateUrl($child['user']['avatar']);
|
||||
}
|
||||
$child['created_at'] = date('Y-m-d H:i:s', strtotime($child['created_at']));
|
||||
$child['updated_at'] = date('Y-m-d H:i:s', strtotime($child['updated_at']));
|
||||
$data['child'][] = $child;
|
||||
}
|
||||
}
|
||||
if (isset($data['user_id'])){
|
||||
$ossservice = new OssService();
|
||||
$data['user'] = User::where('id', $data['user_id'])->select(['nickname', 'avatar', 'openid'])->first();
|
||||
|
||||
if(!str_contains($data['user']['avatar'], 'http') && !empty($data['user']['avatar'])){
|
||||
$data['user']['avatar_pull'] = $ossservice->generatePrivateUrl($data['user']['avatar']);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回删除操作结果
|
||||
*/
|
||||
public function delete(Request $request)
|
||||
{
|
||||
try {
|
||||
$count = $this->service->serviceDelete($request);
|
||||
return $this->success([], "删除评论成功");
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage().$e->getLine().$e->getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\Post;
|
||||
use app\common\model\PostComment;
|
||||
use app\common\model\PostFavorite;
|
||||
use app\common\model\PostLike;
|
||||
use app\common\model\PostMedia;
|
||||
use app\common\model\User;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\PostService;
|
||||
use support\Request;
|
||||
|
||||
class PostController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
// protected $noNeedLogin = ['index'];
|
||||
//
|
||||
// protected $noNeedHeaderData = ['index'];
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new PostService();
|
||||
}
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回分页数据及总数
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceList($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||
? [$this, 'indexFormat']
|
||||
: null);
|
||||
$records = $data['records'];
|
||||
foreach ($records as &$record) {
|
||||
if (!isset($record['id']))
|
||||
break;
|
||||
if(!empty($request->user) && !empty($request->user->uid)){
|
||||
$where = [
|
||||
'post_id' => $record['id'],
|
||||
'user_id' => $request->user->uid
|
||||
];
|
||||
$record['is_like'] = PostLike::where($where)->count();
|
||||
$record['is_favorite'] = PostFavorite::where($where)->count();
|
||||
$record['is_comment'] = PostComment::where($where)->count();
|
||||
}else{
|
||||
$record['is_like'] = 0;
|
||||
$record['is_favorite'] = 0;
|
||||
$record['is_comment'] = 0;
|
||||
}
|
||||
$created_at = strtotime($record['created_at']);
|
||||
$record['year'] = date('Y', $created_at);
|
||||
$record['month'] = date('m', $created_at);
|
||||
$record['day'] = date('d', $created_at);
|
||||
}
|
||||
$data['records'] = $records;
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage().$e->getFile().$e->getLine());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
$ossservice = new OssService();
|
||||
if (isset($data['id'])){
|
||||
$data['media'] = PostMedia::where('post_id', $data['id'])->get()->toArray();
|
||||
foreach ($data['media'] as &$media) {
|
||||
$media['url_pull'] = $ossservice->generatePrivateUrl($media['url']);
|
||||
}
|
||||
}
|
||||
if (isset($data['user_id'])){
|
||||
$data['user'] = User::where('id', $data['user_id'])->first();
|
||||
unset($data['user']['password']);
|
||||
$data['user']['avatar_pull'] = $data['user']['avatar'];
|
||||
if(!str_contains($data['user']['avatar'], 'http') && !empty($data['user']['avatar'])){
|
||||
$data['user']['avatar_pull'] = $ossservice->generatePrivateUrl($data['user']['avatar']);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论,点赞,收藏数量
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @param int|string $id 资源 ID
|
||||
* @return mixed 返回资源详情数据
|
||||
*/
|
||||
public function interaction(Request $request)
|
||||
{
|
||||
try {
|
||||
$param = $request->all();
|
||||
$data = Post::where('id', $param['id'])->select(['like','favorite','comment'])->first();
|
||||
|
||||
if(!empty($request->user) && !empty($request->user->uid)){
|
||||
$where = [
|
||||
'post_id' => $data['id'],
|
||||
'user_id' => $request->user->uid
|
||||
];
|
||||
$data['is_like'] = PostLike::where($where)->count();
|
||||
$data['is_favorite'] = PostFavorite::where($where)->count();
|
||||
$data['is_comment'] = PostComment::where($where)->count();
|
||||
}else{
|
||||
$data['is_like'] = 0;
|
||||
$data['is_favorite'] = 0;
|
||||
$data['is_comment'] = 0;
|
||||
}
|
||||
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage().$e->getFile().$e->getLine());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @param int|string $id 资源 ID
|
||||
* @return mixed 返回资源详情数据
|
||||
*/
|
||||
public function show(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceShow($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'showFormat')
|
||||
? [$this, 'showFormat']
|
||||
: null);
|
||||
|
||||
if(!empty($request->user) && !empty($request->user->uid)){
|
||||
$where = [
|
||||
'post_id' => $data['id'],
|
||||
'user_id' => $request->user->uid
|
||||
];
|
||||
$data['is_like'] = PostLike::where($where)->count();
|
||||
$data['is_favorite'] = PostFavorite::where($where)->count();
|
||||
$data['is_comment'] = PostComment::where($where)->count();
|
||||
}else{
|
||||
$data['is_like'] = 0;
|
||||
$data['is_favorite'] = 0;
|
||||
$data['is_comment'] = 0;
|
||||
}
|
||||
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage().$e->getFile().$e->getLine());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function showFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
$ossservice = new OssService();
|
||||
if (isset($data['id'])){
|
||||
$data['media'] = PostMedia::where('post_id', $data['id'])->get()->toArray();
|
||||
foreach ($data['media'] as &$media) {
|
||||
$media['url_pull'] = $ossservice->generatePrivateUrl($media['url']);
|
||||
}
|
||||
}
|
||||
if (isset($data['user_id'])){
|
||||
$data['user'] = User::where('id', $data['user_id'])->first();
|
||||
unset($data['user']['password']);
|
||||
$data['user']['avatar_pull'] = $data['user']['avatar'];
|
||||
if(!str_contains($data['user']['avatar'], 'http') && !empty($data['user']['avatar'])){
|
||||
$data['user']['avatar_pull'] = $ossservice->generatePrivateUrl($data['user']['avatar']);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\Post;
|
||||
use app\common\model\PostMedia;
|
||||
use app\common\model\User;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\PostFavoriteService;
|
||||
use support\Request;
|
||||
|
||||
class PostFavoriteController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new PostFavoriteService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回分页数据及总数
|
||||
*/
|
||||
public function self(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceSelfList($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||
? [$this, 'indexFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
if (isset($data['post_id'])){
|
||||
$ossservice = new OssService();
|
||||
$post = Post::where('id', $data['post_id'])->first()->toArray();
|
||||
|
||||
if (isset( $post['user_id'])){
|
||||
$user = User::where('id', $post['user_id'])->first();
|
||||
$postUser = [];
|
||||
$postUser['name'] = $user['name'];
|
||||
$postUser['nickname'] = $user['nickname'];
|
||||
$postUser['avatar'] = $user['avatar'];
|
||||
$postUser['avatar_pull'] = $user['avatar'];
|
||||
if(!str_contains($postUser['avatar'], 'http') && !empty($postUser['avatar'])){
|
||||
$postUser['avatar_pull'] = $ossservice->generatePrivateUrl($postUser['avatar']);
|
||||
}
|
||||
$post['user'] = $postUser;
|
||||
}
|
||||
|
||||
$ossservice = new OssService();
|
||||
if (isset($post['id'])){
|
||||
$post['media'] = PostMedia::where('post_id', $post['id'])->get()->toArray();
|
||||
foreach ($post['media'] as &$media) {
|
||||
$media['url_pull'] = $ossservice->generatePrivateUrl($media['url']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['post'] = $post;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回删除操作结果
|
||||
*/
|
||||
public function delete(Request $request)
|
||||
{
|
||||
try {
|
||||
$count = $this->service->serviceDelete($request);
|
||||
return $this->success([], "取消收藏成功");
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\PostLikeService;
|
||||
use support\Request;
|
||||
|
||||
class PostLikeController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new PostLikeService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回分页数据及总数
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceSelfList($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||
? [$this, 'indexFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回删除操作结果
|
||||
*/
|
||||
public function delete(Request $request)
|
||||
{
|
||||
try {
|
||||
$count = $this->service->serviceDelete($request);
|
||||
return $this->success([], "取消点赞成功");
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\PostMediaService;
|
||||
|
||||
class PostMediaController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new PostMediaService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\admin\service\RoleService;
|
||||
use app\common\service\BrandSeriesService;
|
||||
use app\common\service\BrandService;
|
||||
use app\common\service\SysAccountService;
|
||||
use app\common\service\SysCurrencyService;
|
||||
use app\common\service\SysDictItemService;
|
||||
use app\common\service\SysDictService;
|
||||
use app\common\service\SysPortService;
|
||||
use app\common\service\VehColorService;
|
||||
use app\common\service\VehModificationService;
|
||||
use support\Request;
|
||||
use app\common\service\CorpService;
|
||||
use app\common\service\CorpFeishuAppService;
|
||||
use app\common\service\SystemsService;
|
||||
use app\common\service\UserService;
|
||||
use support\Cache;
|
||||
use app\common\service\PermService;
|
||||
use app\common\service\UserGroupService;
|
||||
|
||||
class PresetController extends BaseController
|
||||
{
|
||||
|
||||
protected $noNeedLogin = ['systems'];
|
||||
|
||||
protected $noNeedHeaderData = ['systems'];
|
||||
|
||||
|
||||
public function systems()
|
||||
{
|
||||
try {
|
||||
$result = (new SystemsService())->getList();
|
||||
return $this->success($result, '获取系统列表');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function users()
|
||||
{
|
||||
try {
|
||||
$result = (new UserService())->getList();
|
||||
return $this->success($result, '获取用户列表');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function roles()
|
||||
{
|
||||
try {
|
||||
$result = (new RoleService)->getList();
|
||||
return $this->success($result, '获取角色列表');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function cacheClear()
|
||||
{
|
||||
try {
|
||||
Cache::clear();
|
||||
return $this->success([], '操作成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function menus(Request $request)
|
||||
{
|
||||
try {
|
||||
$uid = $request->user->uid;
|
||||
$systemCode = $request->system_code;
|
||||
$permService = new PermService();
|
||||
$menuTree = $permService->getMenuTree($uid, $systemCode);
|
||||
$permissionCodes = $permService->getPermissionCodes($uid, $systemCode);
|
||||
$result = [
|
||||
'menu' => $menuTree,
|
||||
'permissions' => $permissionCodes
|
||||
];
|
||||
return $this->success($result, '获取菜单权限');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\ResourceService;
|
||||
use support\Request;
|
||||
|
||||
class ResourceController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new ResourceService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function allFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源树形结构
|
||||
*/
|
||||
public function listTree(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceListAll($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'allFormat')
|
||||
? [$this, 'allFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单
|
||||
*/
|
||||
public function menuList(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceMenuList($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'allFormat')
|
||||
? [$this, 'allFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单
|
||||
*/
|
||||
public function menuTreeList(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceMenuTreeList($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'allFormat')
|
||||
? [$this, 'allFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage().$e->getFile().$e->getLine());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\SkuAttributeService;
|
||||
|
||||
class SkuAttributeController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new SkuAttributeService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\SkuAttributeValueService;
|
||||
|
||||
class SkuAttributeValueController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new SkuAttributeValueService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\SkuService;
|
||||
|
||||
class SkuController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new SkuService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\service\OssService;
|
||||
use app\common\service\UploadedFilesService;
|
||||
use app\common\service\UploadService;
|
||||
use app\common\traits\ResponseTrait;
|
||||
use support\Log;
|
||||
use support\Request;
|
||||
use support\exception\BusinessException;
|
||||
use Shopwwi\WebmanFilesystem\Facade\Storage;
|
||||
|
||||
class UploadController
|
||||
{
|
||||
|
||||
use ResponseTrait;
|
||||
|
||||
protected $noNeedLogin = ['proxy'];
|
||||
|
||||
protected $noNeedHeaderData = ['proxy'];
|
||||
|
||||
public function upload(Request $request)
|
||||
{
|
||||
try {
|
||||
$scene = $request->input('scene', 'image');
|
||||
$file = $request->file('file');
|
||||
if ($file && $file->isValid()) {
|
||||
$fileName = md5($file->getUploadName() . time()).'.'.$file->getUploadExtension();
|
||||
$pathUrl = '/bsh_sample/'.$scene.'/'.date('Ymd').'/'.$fileName;
|
||||
$fullPathUrl = public_path() . $pathUrl;
|
||||
$file->move($fullPathUrl);
|
||||
|
||||
$data = [
|
||||
'domain' => getenv('MAIN_DOMAIN'),
|
||||
'file_url' => $pathUrl,
|
||||
'full_url' => getenv('MAIN_DOMAIN') . $pathUrl,
|
||||
'scene' => $scene,
|
||||
];
|
||||
|
||||
// 记录文件信息到数据库
|
||||
try {
|
||||
$uploadedFilesService = new UploadedFilesService();
|
||||
$partition = $scene;
|
||||
$category = $request->input('category', 'general');
|
||||
|
||||
$fileInfo = [
|
||||
'file_name' => basename($fileName),
|
||||
'file_path' => $pathUrl,
|
||||
'file_size' => $file->getSize(),
|
||||
'file_type' => $file->getUploadMimeType(),
|
||||
'original_name' => $file->getUploadName(),
|
||||
];
|
||||
|
||||
$recordResult = $uploadedFilesService->recordFileInfo($fileInfo, $request, $partition, $category);
|
||||
$data['file_id'] = $recordResult['id'];
|
||||
$data['partition'] = $partition;
|
||||
$data['category'] = $category;
|
||||
} catch (\Throwable $e) {
|
||||
// 记录失败不影响上传结果,只记录日志
|
||||
Log::error('记录文件信息失败: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->success($data, 'upload success');
|
||||
}
|
||||
return $this->error('file not found');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 上传单文件附件
|
||||
public function uploadFile(Request $request)
|
||||
{
|
||||
try {
|
||||
$scene = $request->input('scene');
|
||||
$file = $request->file('file');
|
||||
|
||||
if (!$file || !$file->isValid()) {
|
||||
return $this->error('上传失败');
|
||||
}
|
||||
if (empty($scene)) {
|
||||
// return $this->error('上传场景不能为空');
|
||||
$sceneUrl = '';
|
||||
}else{
|
||||
$sceneUrl = $scene . '/';
|
||||
}
|
||||
$originalName = $file->getUploadName();
|
||||
|
||||
$result = Storage::adapter('oss')
|
||||
->path('bsh_sample/' . $sceneUrl . date('Ymd'))
|
||||
->size(1024*1024*100)
|
||||
->upload($file);
|
||||
|
||||
$ossservice = new OssService();
|
||||
|
||||
$data = [
|
||||
'original_name' => $originalName,
|
||||
'file_name' => $result->file_name,
|
||||
'file_url' => $ossservice->generatePrivateUrl($result->file_name)
|
||||
];
|
||||
|
||||
// 记录文件信息到数据库
|
||||
$category = $request->input('category', 'general');
|
||||
$res = $this->recordFileInfo($result,$request,$file,$scene,$category);
|
||||
$data = array_merge($data, $res);
|
||||
|
||||
return $this->success($data);
|
||||
}catch (\Throwable $e){
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 上传单文件图片
|
||||
public function uploadImage(Request $request)
|
||||
{
|
||||
try {
|
||||
$scene = $request->input('scene');
|
||||
$file = $request->file('image');
|
||||
|
||||
if (!$file || !$file->isValid()) {
|
||||
return $this->error('上传失败');
|
||||
}
|
||||
if (empty($scene)) {
|
||||
// return $this->error('上传场景不能为空');
|
||||
$sceneUrl = '';
|
||||
}else{
|
||||
$sceneUrl = $scene . '/';
|
||||
}
|
||||
|
||||
$result = Storage::adapter('oss')
|
||||
->path('bsh_sample/' . $sceneUrl . date('Ymd'))
|
||||
->size(1024*1024*100)
|
||||
->extYes(['image/jpeg','image/png'])
|
||||
->extNo(['image/gif'])
|
||||
->upload($file);
|
||||
|
||||
$ossservice = new OssService();
|
||||
|
||||
$data = [
|
||||
'href' => $result->file_name,
|
||||
'alt' => '',
|
||||
'url' => $ossservice->generatePrivateUrl($result->file_name)
|
||||
];
|
||||
|
||||
// 记录文件信息到数据库
|
||||
$category = $request->input('category', 'general');
|
||||
$res = $this->recordFileInfo($result,$request,$file,$scene,$category);
|
||||
$data = array_merge($data, $res);
|
||||
|
||||
return json(['errno' => 0, 'data' => $data]);
|
||||
// return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return json(['errno' => 1, 'message' => $e->getMessage()]);
|
||||
// return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function recordFileInfo($result, $request, $file, $scene, $category)
|
||||
{
|
||||
try {
|
||||
$uploadedFilesService = new UploadedFilesService();
|
||||
$partition = $scene;
|
||||
|
||||
$fileInfo = [
|
||||
'file_name' => basename($result->file_name),
|
||||
'file_path' => $result->file_name, // OSS存储路径
|
||||
'file_size' => $file->getSize(),
|
||||
'file_type' => $file->getUploadMimeType(),
|
||||
'original_name' => $file->getUploadName(),
|
||||
];
|
||||
|
||||
$partition = !empty($partition)?$partition:'other';
|
||||
$category = !empty($category)?$category:'other';
|
||||
$recordResult = $uploadedFilesService->recordFileInfo($fileInfo, $request, $partition, $category);
|
||||
$data = [];
|
||||
$data['file_id'] = $recordResult['id'];
|
||||
$data['partition'] = $partition;
|
||||
$data['category'] = $category;
|
||||
return $data;
|
||||
} catch (\Throwable $e) {
|
||||
// 记录失败不影响上传结果,只记录日志
|
||||
Log::error('记录文件信息失败: ' . $e->getMessage());
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件信息
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function getFileInfo(Request $request)
|
||||
{
|
||||
try {
|
||||
$fileId = $request->input('id');
|
||||
|
||||
if (!$fileId) {
|
||||
return $this->error('文件ID不能为空');
|
||||
}
|
||||
|
||||
$uploadedFilesService = new UploadedFilesService();
|
||||
$fileInfo = $uploadedFilesService->getFileInfo($fileId);
|
||||
|
||||
if (!$fileInfo) {
|
||||
return $this->error('文件不存在');
|
||||
}
|
||||
|
||||
return $this->success($fileInfo);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error('获取文件信息失败: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function deleteFile(Request $request)
|
||||
{
|
||||
try {
|
||||
$fileId = $request->input('id');
|
||||
$path = $request->input('path');
|
||||
|
||||
$uploadedFilesService = new UploadedFilesService();
|
||||
if(!empty($path) && empty($fileId)){
|
||||
$where = ['file_path' => $path];
|
||||
$file = $uploadedFilesService->getFile($where);
|
||||
$fileId = $file->id;
|
||||
}elseif(empty($path) && !empty($fileId)){
|
||||
$where = ['id' => $fileId];
|
||||
$file = $uploadedFilesService->getFile($where);
|
||||
$path = $file->file_path;
|
||||
}
|
||||
if (!$fileId) {
|
||||
return $this->error('文件ID与路径不能为空');
|
||||
}
|
||||
|
||||
// 删除 OSS 上的文件
|
||||
$ossService = new OssService();
|
||||
$ossService->deleteFile($path);
|
||||
|
||||
$result = $uploadedFilesService->deleteFile($fileId);
|
||||
|
||||
if ($result) {
|
||||
return $this->success([], '文件删除成功');
|
||||
} else {
|
||||
return $this->error('文件删除失败');
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error('文件删除失败: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分区配置
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function getPartitionConfig(Request $request)
|
||||
{
|
||||
try {
|
||||
$uploadedFilesService = new UploadedFilesService();
|
||||
$config = $uploadedFilesService->getPartitionConfig();
|
||||
|
||||
return $this->success($config);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error('获取分区配置失败: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function proxy(Request $request)
|
||||
{
|
||||
$filePath = $request->get('file'); // 原OSS文件路径
|
||||
try {
|
||||
// 生成签名URL
|
||||
$signedUrl = (new \app\common\service\OssService())->generatePrivateUrl($filePath);
|
||||
|
||||
// 获取图片数据并返回
|
||||
$imageData = file_get_contents($signedUrl);
|
||||
|
||||
// 根据文件类型设置Content-Type
|
||||
$mime = mime_content_type('data://application/octet-stream;base64,'.base64_encode($imageData));
|
||||
|
||||
return response($imageData, 200, [
|
||||
'Content-Type' => $mime,
|
||||
'Cache-Control' => 'public, max-age=600' // 客户端缓存10分钟
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response('Image not found '.$e->getMessage(), 404);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\UserService;
|
||||
use app\common\service\WechatService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
class UserController extends BaseController
|
||||
{
|
||||
protected $noNeedLogin = ['getQrUrl', 'getUserInfo', 'bindUser', 'miniappLogin'];
|
||||
|
||||
protected $noNeedHeaderData = ['getQrUrl', 'getUserInfo', 'bindUser', 'miniappLogin'];
|
||||
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new UserService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 获取微信二维码
|
||||
*/
|
||||
public function getQrUrl()
|
||||
{
|
||||
try {
|
||||
$result = $this->service->makeQrUrl();
|
||||
return $this->success($result);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
public function getUserInfo(Request $request)
|
||||
{
|
||||
try {
|
||||
$params = $request->all();
|
||||
$result = $this->service->userInfo($params['code'], $params['state']);
|
||||
unset($result['password']);
|
||||
|
||||
if (!isset($result['avatar'])){
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
$ossservice = new OssService();
|
||||
$result['avatar_pull'] = $result['avatar'];
|
||||
if(strpos($result['avatar'], 'http') === false && !empty($result['avatar'])){
|
||||
$result['avatar_pull'] = $ossservice->generatePrivateUrl($result['avatar']);
|
||||
}
|
||||
|
||||
return $this->success($result);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户信息(登录后调用)
|
||||
*/
|
||||
public function info(Request $request)
|
||||
{
|
||||
try {
|
||||
$uid = $request->user->uid;
|
||||
$result = (new UserService())->getUserInfo($uid);
|
||||
return $this->success($result, '获取用户信息');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定用户
|
||||
*/
|
||||
public function bindUser(Request $request)
|
||||
{
|
||||
try {
|
||||
$params = $request->all();
|
||||
$result = $this->service->bindUser($params);
|
||||
unset($result['password']);
|
||||
return $this->success($result);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
* @throws \Random\RandomException
|
||||
*/
|
||||
public function savePassword(Request $request)
|
||||
{
|
||||
try {
|
||||
$uid = $request->user->uid;
|
||||
$data = $request->all();
|
||||
$result = (new UserService())->savePassword($uid,$data);;
|
||||
return $this->success($result, '编辑成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改名字与头像
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
* @throws \Random\RandomException
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
try {
|
||||
$uid = $request->user->uid;
|
||||
$data = $request->all();
|
||||
$result = (new UserService())->save($uid,$data);;
|
||||
return $this->success($result, '编辑成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function wechatLogin($request)
|
||||
{
|
||||
try {
|
||||
$params = $request->all();
|
||||
$result = $this->service->wechatLogin($params['login_code'], $params['phone_code']);
|
||||
|
||||
return $this->success($result);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 小程序登录
|
||||
*/
|
||||
public function miniappLogin(Request $request): Response
|
||||
{
|
||||
try {
|
||||
$result = $this->service->miniappLogin($request->all());
|
||||
return $this->success($result);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取手机号
|
||||
*/
|
||||
public function miniappPhoneNumber(Request $request): Response
|
||||
{
|
||||
try {
|
||||
$result = $this->service->miniappPhoneNumber($request->all(),$request);
|
||||
return $this->success($result);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user