From 5f3c9d4ca758b7dc126e81ff818b0f802a01499e Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Sun, 23 Jan 2022 15:13:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=85=BC=E5=AE=B9=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Command/TestCommand.php | 8 -------- app/Controller/Api/V1/CommonController.php | 1 + .../Api/V1/Contact/ContactController.php | 4 ++++ app/Controller/Api/V1/EmoticonController.php | 1 + app/Controller/Api/V1/Talk/MessageController.php | 6 +++--- app/Controller/Api/V1/Talk/RecordsController.php | 1 - app/Controller/Api/V1/UploadController.php | 16 ++++++++++------ app/Exception/Handler/AppExceptionHandler.php | 2 +- app/Model/SplitUpload.php | 2 ++ app/Service/ArticleService.php | 2 +- app/Service/Message/SubscribeHandleService.php | 11 +---------- app/Service/RobotService.php | 1 + app/Support/SendEmailCode.php | 2 +- app/{Templates => Template}/BaseTemplate.php | 2 +- app/{Templates => Template}/MailerTemplate.php | 2 +- ...0_11_04_153251_create_article_annex_table.php | 1 + ...20_11_04_153358_create_split_upload_table.php | 6 ++++-- ...20_11_04_153626_create_group_member_table.php | 1 + seeders/initialize.php | 8 ++++---- 19 files changed, 38 insertions(+), 39 deletions(-) rename app/{Templates => Template}/BaseTemplate.php (94%) rename app/{Templates => Template}/MailerTemplate.php (94%) diff --git a/app/Command/TestCommand.php b/app/Command/TestCommand.php index 76af0ce..9f5eaf5 100644 --- a/app/Command/TestCommand.php +++ b/app/Command/TestCommand.php @@ -41,13 +41,5 @@ class TestCommand extends HyperfCommand { // $repository = di()->get(ExampleRepository::class); // $repository->where_case2(); - - // di()->get(RobotService::class)->create([ - // 'robot_name' => "登录助手", - // 'describe' => "异地登录助手", - // 'logo' => '', - // 'is_talk' => 0, - // 'type' => 1, - // ]); } } diff --git a/app/Controller/Api/V1/CommonController.php b/app/Controller/Api/V1/CommonController.php index 8e30993..b6b7ca6 100644 --- a/app/Controller/Api/V1/CommonController.php +++ b/app/Controller/Api/V1/CommonController.php @@ -84,6 +84,7 @@ class CommonController extends CController public function EmailCode(SendEmailCode $sendEmailCode) { $params = $this->request->inputs(['email']); + $this->validate($params, [ 'email' => "required|email" ]); diff --git a/app/Controller/Api/V1/Contact/ContactController.php b/app/Controller/Api/V1/Contact/ContactController.php index deae312..d7b9ad9 100644 --- a/app/Controller/Api/V1/Contact/ContactController.php +++ b/app/Controller/Api/V1/Contact/ContactController.php @@ -109,6 +109,10 @@ class ContactController extends CController 'id', 'nickname', 'mobile', 'avatar', 'gender' ]); + if (empty($result)) { + return $this->response->fail("手机号不存在!"); + } + return $this->response->success($result); } diff --git a/app/Controller/Api/V1/EmoticonController.php b/app/Controller/Api/V1/EmoticonController.php index fc8d375..a2e20b3 100644 --- a/app/Controller/Api/V1/EmoticonController.php +++ b/app/Controller/Api/V1/EmoticonController.php @@ -15,6 +15,7 @@ use Psr\Http\Message\ResponseInterface; /** * Class EmoticonController + * * @Controller(prefix="/api/v1/emoticon") * @Middleware(JWTAuthMiddleware::class) * diff --git a/app/Controller/Api/V1/Talk/MessageController.php b/app/Controller/Api/V1/Talk/MessageController.php index 9505d1b..5d2ffc1 100644 --- a/app/Controller/Api/V1/Talk/MessageController.php +++ b/app/Controller/Api/V1/Talk/MessageController.php @@ -176,12 +176,12 @@ class MessageController extends CController */ public function file(Filesystem $filesystem): ResponseInterface { - $params = $this->request->inputs(['talk_type', 'receiver_id', 'hash_name']); + $params = $this->request->inputs(['talk_type', 'receiver_id', 'upload_id']); $this->validate($params, [ 'talk_type' => 'required|in:1,2', 'receiver_id' => 'required|integer|min:1', - 'hash_name' => 'required', + 'upload_id' => 'required', ]); $user_id = $this->uid(); @@ -189,7 +189,7 @@ class MessageController extends CController return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!'); } - $file = SplitUpload::where('user_id', $user_id)->where('upload_id', $params['hash_name'])->where('type', 1)->first(); + $file = SplitUpload::where('user_id', $user_id)->where('upload_id', $params['upload_id'])->where('type', 1)->first(); if (!$file || empty($file->path)) { return $this->response->fail('文件不存在...'); } diff --git a/app/Controller/Api/V1/Talk/RecordsController.php b/app/Controller/Api/V1/Talk/RecordsController.php index e487e61..075141b 100644 --- a/app/Controller/Api/V1/Talk/RecordsController.php +++ b/app/Controller/Api/V1/Talk/RecordsController.php @@ -33,7 +33,6 @@ class RecordsController extends CController */ private $talkService; - public function __construct(TalkService $talkService) { parent::__construct(); diff --git a/app/Controller/Api/V1/UploadController.php b/app/Controller/Api/V1/UploadController.php index cbfb483..e676ad2 100644 --- a/app/Controller/Api/V1/UploadController.php +++ b/app/Controller/Api/V1/UploadController.php @@ -72,10 +72,14 @@ class UploadController extends CController ]); $data = $this->splitUploadService->create($this->uid(), $params['file_name'], $params['file_size']); + if (empty($data)) { + return $this->response->fail('获取文件拆分信息失败!'); + } - $data['hash_name'] = $data["upload_id"]; - - return $data ? $this->response->success($data) : $this->response->fail('获取文件拆分信息失败!'); + return $this->response->success([ + "upload_id" => $data["upload_id"], + "split_size" => $data["split_size"], + ]); } /** @@ -111,11 +115,11 @@ class UploadController extends CController } return $this->response->success([ - 'is_file_merge' => true, - 'hash' => $params['upload_id'] + 'is_merge' => true, + 'upload_id' => $params['upload_id'] ]); } - return $this->response->success(['is_file_merge' => false]); + return $this->response->success(['is_merge' => false]); } } diff --git a/app/Exception/Handler/AppExceptionHandler.php b/app/Exception/Handler/AppExceptionHandler.php index c244ec2..574fe0b 100644 --- a/app/Exception/Handler/AppExceptionHandler.php +++ b/app/Exception/Handler/AppExceptionHandler.php @@ -5,7 +5,7 @@ namespace App\Exception\Handler; use App\Cache\Repository\LockRedis; use App\Constant\ResponseCode; -use App\Templates\MailerTemplate; +use App\Template\MailerTemplate; use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\ExceptionHandler\ExceptionHandler; use Hyperf\HttpMessage\Stream\SwooleStream; diff --git a/app/Model/SplitUpload.php b/app/Model/SplitUpload.php index 1c06fd0..72aa24d 100644 --- a/app/Model/SplitUpload.php +++ b/app/Model/SplitUpload.php @@ -28,6 +28,8 @@ class SplitUpload extends BaseModel { protected $table = 'split_upload'; + public $timestamps = true; + protected $fillable = [ 'type', 'drive', diff --git a/app/Service/ArticleService.php b/app/Service/ArticleService.php index 9c5f1da..33a4111 100644 --- a/app/Service/ArticleService.php +++ b/app/Service/ArticleService.php @@ -498,7 +498,7 @@ class ArticleService extends BaseService return false; } - $annex_files = $info->annexs()->get(['id', 'article_id', 'save_dir'])->toArray(); + $annex_files = $info->annexs()->get(['id', 'article_id', 'path'])->toArray(); //判断笔记是否存在附件,不存在直接删除 if (count($annex_files) == 0) { diff --git a/app/Service/Message/SubscribeHandleService.php b/app/Service/Message/SubscribeHandleService.php index 707c225..b2f6bf2 100644 --- a/app/Service/Message/SubscribeHandleService.php +++ b/app/Service/Message/SubscribeHandleService.php @@ -12,7 +12,6 @@ use App\Model\User; use App\Model\Contact\ContactApply; use App\Repository\Contact\ContactRepository; use App\Service\SocketClientService; -use App\Service\UserService; class SubscribeHandleService { @@ -49,15 +48,7 @@ class SubscribeHandleService } /** - * @param array $data 数据 - *
-     *                    [
-     *                    'uuid'    => '',
-     *                    'event'   => '',
-     *                    'data'    => '',
-     *                    'options' => ''
-     *                    ];
-     *                    
+ * @param array $data 数据 ['uuid' => '','event' => '','data' => '','options' => '']; */ public function handle(array $data) { diff --git a/app/Service/RobotService.php b/app/Service/RobotService.php index 80701b1..292c2f0 100644 --- a/app/Service/RobotService.php +++ b/app/Service/RobotService.php @@ -23,6 +23,7 @@ class RobotService try { $user = User::create([ 'mobile' => '100' . mt_rand(1000, 9999) . mt_rand(1000, 9999), + "nickname" => "登录助手", 'password' => HashHelper::make(Str::random(10)), 'is_robot' => 1 ]); diff --git a/app/Support/SendEmailCode.php b/app/Support/SendEmailCode.php index b345268..32c7a8b 100644 --- a/app/Support/SendEmailCode.php +++ b/app/Support/SendEmailCode.php @@ -3,7 +3,7 @@ declare(strict_types=1); namespace App\Support; -use App\Templates\MailerTemplate; +use App\Template\MailerTemplate; class SendEmailCode { diff --git a/app/Templates/BaseTemplate.php b/app/Template/BaseTemplate.php similarity index 94% rename from app/Templates/BaseTemplate.php rename to app/Template/BaseTemplate.php index 6156612..1e809a1 100644 --- a/app/Templates/BaseTemplate.php +++ b/app/Template/BaseTemplate.php @@ -1,7 +1,7 @@ unsignedBigInteger('id', true)->comment('文件ID'); $table->unsignedInteger('user_id')->unsigned()->comment('上传文件的用户ID'); $table->unsignedInteger('article_id')->default(0)->comment('笔记ID'); + $table->unsignedInteger('drive')->unsigned()->default(1)->comment('文件驱动[1:local;2:cos;]'); $table->string('suffix', 10)->default('')->comment('文件后缀名'); $table->unsignedBigInteger('size')->default(0)->comment('文件大小(单位字节)'); $table->string('path', 500)->nullable(false)->default('')->comment('文件保存地址(相对地址)'); diff --git a/migrations/2020_11_04_153358_create_split_upload_table.php b/migrations/2020_11_04_153358_create_split_upload_table.php index bf5c3f3..91c230e 100644 --- a/migrations/2020_11_04_153358_create_split_upload_table.php +++ b/migrations/2020_11_04_153358_create_split_upload_table.php @@ -14,6 +14,7 @@ class CreateSplitUploadTable extends Migration Schema::create('split_upload', function (Blueprint $table) { $table->unsignedInteger('id', true)->comment('临时文件ID'); $table->unsignedTinyInteger('type')->default(2)->comment('数据类型[1:合并文件;2:拆分文件]'); + $table->unsignedInteger('drive')->unsigned()->default(1)->comment('文件驱动[1:local;2:cos;]'); $table->unsignedInteger('user_id')->default(0)->comment('上传的用户ID'); $table->string('upload_id', 32)->default('')->comment('上传文件ID'); $table->string('original_name', 100)->default('')->comment('原文件名'); @@ -23,8 +24,9 @@ class CreateSplitUploadTable extends Migration $table->string('file_ext', 10)->default('')->comment('文件后缀名'); $table->unsignedInteger('file_size')->default(0)->comment('临时文件大小'); $table->unsignedTinyInteger('is_delete')->default(0)->comment('文件是否已被删除[0:否;1:是]'); - $table->unsignedInteger('created_at')->nullable(true)->comment('创建时间'); - $table->unsignedInteger('updated_at')->nullable(true)->comment('更新时间'); + $table->json('attr')->nullable(false)->comment('额外参数Json'); + $table->dateTime('created_at')->nullable(true)->comment('创建时间'); + $table->dateTime('updated_at')->nullable(true)->comment('更新时间'); $table->charset = 'utf8'; $table->collation = 'utf8_general_ci'; diff --git a/migrations/2020_11_04_153626_create_group_member_table.php b/migrations/2020_11_04_153626_create_group_member_table.php index 964e3f9..7e00bf1 100644 --- a/migrations/2020_11_04_153626_create_group_member_table.php +++ b/migrations/2020_11_04_153626_create_group_member_table.php @@ -20,6 +20,7 @@ class CreateGroupMemberTable extends Migration $table->tinyInteger('is_quit')->default(0)->comment('是否退群[0:否;1:是;]'); $table->string('user_card', 20)->default('')->comment('群名片'); $table->dateTime('created_at')->nullable()->comment('入群时间'); + $table->dateTime('updated_at')->nullable()->comment('更新时间'); $table->dateTime('deleted_at')->nullable()->comment('退群时间'); $table->charset = 'utf8'; diff --git a/seeders/initialize.php b/seeders/initialize.php index 225d0df..8008a96 100644 --- a/seeders/initialize.php +++ b/seeders/initialize.php @@ -18,7 +18,7 @@ class Initialize extends Seeder */ public function run() { - if (User::count() > 0) { + if (User::count() > 1) { echo "数据库已存在数据,不能执行初始化数据脚本...\n"; return; } @@ -37,14 +37,14 @@ class Initialize extends Seeder User::insert($users); $defaultArticleClass = []; - $usersFriends = []; foreach (User::all() as $user) { $defaultArticleClass[] = [ 'user_id' => $user->id, 'class_name' => '我的笔记', 'sort' => 1, 'is_default' => 1, - 'created_at' => time(), + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s') ]; } @@ -67,7 +67,7 @@ class Initialize extends Seeder Contact::insert($friends); - $service = new \App\Service\TalkSessionService(); + $service = di()->get(\App\Service\TalkSessionService::class); foreach ($list as $item) { $service->create($item->user_id, $item->friend_id, \App\Constant\TalkModeConstant::PRIVATE_CHAT); }