feat:兼容开发

main
gzydong 2022-01-22 12:48:28 +08:00
parent afcf456d60
commit c3b17a583b
9 changed files with 54 additions and 38 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
@ -7,7 +8,6 @@ use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
use App\Middleware\JWTAuthMiddleware; use App\Middleware\JWTAuthMiddleware;
use App\Constants\ResponseCode;
use App\Model\Emoticon\Emoticon; use App\Model\Emoticon\Emoticon;
use App\Model\Emoticon\EmoticonItem; use App\Model\Emoticon\EmoticonItem;
use App\Service\EmoticonService; use App\Service\EmoticonService;
@ -66,7 +66,7 @@ class EmoticonController extends CController
/** /**
* 获取系统表情包 * 获取系统表情包
* *
* @RequestMapping(path="system", methods="get") * @RequestMapping(path="system/list", methods="get")
*/ */
public function system(): ResponseInterface public function system(): ResponseInterface
{ {
@ -85,7 +85,7 @@ class EmoticonController extends CController
/** /**
* 安装或移除系统表情包 * 安装或移除系统表情包
* *
* @RequestMapping(path="set-user-emoticon", methods="post") * @RequestMapping(path="system/install", methods="post")
*/ */
public function setUserEmoticon(): ResponseInterface public function setUserEmoticon(): ResponseInterface
{ {
@ -95,6 +95,8 @@ class EmoticonController extends CController
'type' => 'required|in:1,2' 'type' => 'required|in:1,2'
]); ]);
$params['emoticon_id'] = intval($params['emoticon_id']);
$user_id = $this->uid(); $user_id = $this->uid();
// 移除表情包 // 移除表情包
@ -132,7 +134,8 @@ class EmoticonController extends CController
/** /**
* 自定义上传表情包 * 自定义上传表情包
* *
* @RequestMapping(path="upload-emoticon", methods="post") * @RequestMapping(path="customize/create", methods="post")
*
* @param Filesystem $filesystem * @param Filesystem $filesystem
* @return ResponseInterface * @return ResponseInterface
*/ */
@ -140,24 +143,16 @@ class EmoticonController extends CController
{ {
$file = $this->request->file('emoticon'); $file = $this->request->file('emoticon');
if (!$file->isValid()) { if (!$file->isValid()) {
return $this->response->fail( return $this->response->invalidParams('上传文件验证失败!');
'图片上传失败,请稍后再试!',
[],
ResponseCode::VALIDATION_ERROR
);
} }
$ext = $file->getExtension(); $ext = $file->getExtension();
if (!in_array($ext, ['jpg', 'png', 'jpeg', 'gif', 'webp'])) { if (!in_array($ext, ['jpg', 'png', 'jpeg', 'gif', 'webp'])) {
return $this->response->fail( return $this->response->invalidParams('图片格式错误目前仅支持jpg、png、jpeg、gif和webp');
'图片格式错误目前仅支持jpg、png、jpeg、gif和webp',
[],
ResponseCode::VALIDATION_ERROR
);
} }
try { try {
$path = 'media/images/emoticon/' . date('Ymd') . '/' . create_image_name($ext, getimagesize($file->getRealPath())); $path = 'public/media/images/emoticon/' . date('Ymd') . '/' . create_image_name($ext, getimagesize($file->getRealPath()));
$filesystem->write($path, file_get_contents($file->getRealPath())); $filesystem->write($path, file_get_contents($file->getRealPath()));
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->response->fail('图片上传失败!'); return $this->response->fail('图片上传失败!');
@ -165,10 +160,9 @@ class EmoticonController extends CController
$result = EmoticonItem::create([ $result = EmoticonItem::create([
'user_id' => $this->uid(), 'user_id' => $this->uid(),
'url' => $path, 'url' => get_media_url($path),
'file_suffix' => $ext, 'file_suffix' => $ext,
'file_size' => $file->getSize(), 'file_size' => $file->getSize(),
'created_at' => date('Y-m-d H:i:s')
]); ]);
if (!$result) { if (!$result) {
@ -177,14 +171,15 @@ class EmoticonController extends CController
return $this->response->success([ return $this->response->success([
'media_id' => $result->id, 'media_id' => $result->id,
'src' => get_media_url($result->url) 'src' => $result->url,
]); ]);
} }
/** /**
* 移除收藏的表情包 * 移除收藏的表情包
* *
* @RequestMapping(path="del-collect-emoticon", methods="post") * @RequestMapping(path="customize/delete", methods="post")
* @throws \Exception
*/ */
public function delCollectEmoticon(): ResponseInterface public function delCollectEmoticon(): ResponseInterface
{ {

View File

@ -136,7 +136,7 @@ class MessageController extends CController
} }
try { try {
$path = 'media/images/talks/' . date('Ymd') . '/' . create_image_name($ext, getimagesize($file->getRealPath())); $path = 'public/media/images/talks/' . date('Ymd') . '/' . create_image_name($ext, getimagesize($file->getRealPath()));
$filesystem->write($path, file_get_contents($file->getRealPath())); $filesystem->write($path, file_get_contents($file->getRealPath()));
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->response->fail(); return $this->response->fail();
@ -152,6 +152,7 @@ class MessageController extends CController
'suffix' => $ext, 'suffix' => $ext,
'size' => $file->getSize(), 'size' => $file->getSize(),
'path' => $path, 'path' => $path,
'url' => get_media_url($path),
'original_name' => $file->getClientFilename(), 'original_name' => $file->getClientFilename(),
]); ]);
@ -254,6 +255,7 @@ class MessageController extends CController
public function emoticon(): ResponseInterface public function emoticon(): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'emoticon_id']); $params = $this->request->inputs(['talk_type', 'receiver_id', 'emoticon_id']);
$this->validate($params, [ $this->validate($params, [
'talk_type' => 'required|in:1,2', 'talk_type' => 'required|in:1,2',
'receiver_id' => 'required|integer|min:1', 'receiver_id' => 'required|integer|min:1',
@ -269,6 +271,8 @@ class MessageController extends CController
if (!$emoticon) return $this->response->fail('表情不存在!'); if (!$emoticon) return $this->response->fail('表情不存在!');
var_dump($emoticon->toArray());
$isTrue = $this->talkMessageService->insertFile([ $isTrue = $this->talkMessageService->insertFile([
'talk_type' => $params['talk_type'], 'talk_type' => $params['talk_type'],
'user_id' => $user_id, 'user_id' => $user_id,

View File

@ -34,7 +34,7 @@ class UploadController extends CController
* @param Filesystem $filesystem * @param Filesystem $filesystem
* @return ResponseInterface * @return ResponseInterface
*/ */
public function fileStream(Filesystem $filesystem): ResponseInterface public function avatar(Filesystem $filesystem): ResponseInterface
{ {
$file = $this->request->file("file"); $file = $this->request->file("file");
@ -60,6 +60,7 @@ class UploadController extends CController
public function initiateMultipart(): ResponseInterface public function initiateMultipart(): ResponseInterface
{ {
$params = $this->request->inputs(['file_name', 'file_size']); $params = $this->request->inputs(['file_name', 'file_size']);
$this->validate($params, [ $this->validate($params, [
'file_name' => "required", 'file_name' => "required",
'file_size' => 'required|integer' 'file_size' => 'required|integer'
@ -79,14 +80,16 @@ class UploadController extends CController
*/ */
public function fileSubareaUpload(): ResponseInterface public function fileSubareaUpload(): ResponseInterface
{ {
$file = $this->request->file('file');
$params = $this->request->inputs(['upload_id', 'split_index', 'split_num']); $params = $this->request->inputs(['upload_id', 'split_index', 'split_num']);
$this->validate($params, [ $this->validate($params, [
'upload_id' => 'required', 'upload_id' => 'required',
'split_index' => 'required', 'split_index' => 'required',
'split_num' => 'required' 'split_num' => 'required'
]); ]);
$file = $this->request->file('file');
if (!$file || !$file->isValid()) { if (!$file || !$file->isValid()) {
return $this->response->fail(); return $this->response->fail();
} }

View File

@ -81,7 +81,8 @@ class UsersController extends CController
/** /**
* 编辑我的信息 * 编辑我的信息
* @RequestMapping(path="edit/detail", methods="post") *
* @RequestMapping(path="change/detail", methods="post")
* *
* @return ResponseInterface * @return ResponseInterface
*/ */
@ -103,7 +104,8 @@ class UsersController extends CController
/** /**
* 修改我的密码 * 修改我的密码
* @RequestMapping(path="edit/password", methods="post") *
* @RequestMapping(path="change/password", methods="post")
* *
* @return ResponseInterface * @return ResponseInterface
*/ */
@ -133,7 +135,8 @@ class UsersController extends CController
/** /**
* 更换用户手机号 * 更换用户手机号
* @RequestMapping(path="edit/mobile", methods="post") *
* @RequestMapping(path="change/mobile", methods="post")
* *
* @param SmsCodeService $smsCodeService * @param SmsCodeService $smsCodeService
* @return ResponseInterface * @return ResponseInterface
@ -168,7 +171,8 @@ class UsersController extends CController
/** /**
* 修改用户邮箱接口 * 修改用户邮箱接口
* @RequestMapping(path="edit/email", methods="post") *
* @RequestMapping(path="change/email", methods="post")
* *
* @param \App\Support\SendEmailCode $emailCode * @param \App\Support\SendEmailCode $emailCode
* @return \Psr\Http\Message\ResponseInterface * @return \Psr\Http\Message\ResponseInterface

View File

@ -1,5 +1,4 @@
<?php <?php
declare (strict_types=1); declare (strict_types=1);
namespace App\Model\Emoticon; namespace App\Model\Emoticon;
@ -18,12 +17,15 @@ use App\Model\BaseModel;
* @property int $file_size 表情包文件大小 * @property int $file_size 表情包文件大小
* @property string $created_at 创建时间 * @property string $created_at 创建时间
* @property string $updated_at 更新时间 * @property string $updated_at 更新时间
*
* @package App\Model * @package App\Model
*/ */
class EmoticonItem extends BaseModel class EmoticonItem extends BaseModel
{ {
protected $table = 'emoticon_item'; protected $table = 'emoticon_item';
public $timestamps = true;
protected $fillable = [ protected $fillable = [
'emoticon_id', 'emoticon_id',
'user_id', 'user_id',

View File

@ -36,6 +36,7 @@ class TalkRecordsFile extends BaseModel
'suffix', 'suffix',
'size', 'size',
'path', 'path',
'url',
'created_at' 'created_at'
]; ];

View File

@ -157,11 +157,6 @@ class EmoticonService extends BaseService
*/ */
public function getDetailsAll(array $where = []): array public function getDetailsAll(array $where = []): array
{ {
$items = EmoticonItem::where($where)->get(['id as media_id', 'url as src'])->toArray(); return EmoticonItem::where($where)->get(['id as media_id', 'url as src'])->toArray();
foreach ($items as $k => $item) {
$items[$k]['src'] = get_media_url($item['src']);
}
return $items;
} }
} }

View File

@ -97,7 +97,7 @@ class FormatMessageService
if ($files) { if ($files) {
$files = TalkRecordsFile::whereIn('record_id', $files)->get([ $files = TalkRecordsFile::whereIn('record_id', $files)->get([
'id', 'record_id', 'user_id', 'source', 'type', 'drive', 'id', 'record_id', 'user_id', 'source', 'type', 'drive',
'original_name', 'suffix', 'size', 'path' 'original_name', 'suffix', 'size', 'path', 'url'
])->keyBy('record_id')->toArray(); ])->keyBy('record_id')->toArray();
} }
@ -149,7 +149,7 @@ class FormatMessageService
case TalkMessageType::FILE_MESSAGE: case TalkMessageType::FILE_MESSAGE:
$rows[$k]['file'] = $files[$row['id']] ?? []; $rows[$k]['file'] = $files[$row['id']] ?? [];
if ($rows[$k]['file']) { if ($rows[$k]['file']) {
$rows[$k]['file']['file_url'] = get_media_url($rows[$k]['file']['path']); $rows[$k]['file']['file_url'] = $rows[$k]['file']['url'];
} }
break; break;

View File

@ -39,10 +39,9 @@ class Response
$resp = [ $resp = [
"code" => ResponseCode::SUCCESS, "code" => ResponseCode::SUCCESS,
"message" => $message, "message" => $message,
"data" => $data,
]; ];
// if ($data) $resp["data"] = $data; if ($data) $resp["data"] = $data;
return $this->response->json($resp); return $this->response->json($resp);
} }
@ -55,7 +54,7 @@ class Response
* @param int $code 错误码 * @param int $code 错误码
* @return PsrResponseInterface * @return PsrResponseInterface
*/ */
public function fail(string $message = 'fail', array $data = [], $code = ResponseCode::FAIL): PsrResponseInterface public function fail(string $message = 'fail', array $data = [], int $code = ResponseCode::FAIL): PsrResponseInterface
{ {
$resp = [ $resp = [
"code" => $code, "code" => $code,
@ -67,6 +66,19 @@ class Response
return $this->response->json($resp); return $this->response->json($resp);
} }
/**
* 参数验证错误
* @param string $message 错误信息
* @return PsrResponseInterface
*/
public function invalidParams(string $message = 'fail'): PsrResponseInterface
{
return $this->response->json([
"code" => ResponseCode::VALIDATION_ERROR,
"message" => $message,
]);
}
/** /**
* 处理错误信息返回 * 处理错误信息返回
* *