diff --git a/.env.example b/.env.example index 5ed72d5..3a43d2f 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,8 @@ +# ---- 基础配置 ---- APP_NAME=hyperf-chat APP_ENV=dev +# ---- Mysql 配置 ---- DB_DRIVER=mysql DB_HOST=localhost DB_PORT=3306 @@ -11,15 +13,20 @@ DB_CHARSET=utf8mb4 DB_COLLATION=utf8mb4_unicode_ci DB_PREFIX= +# ---- Redis 配置 ---- REDIS_HOST=localhost REDIS_AUTH=(null) REDIS_PORT=6379 REDIS_DB=0 -# 本机IP地址 -IP_ADDRESS=0.0.0.0 - +# ---- JWT授权配置 ---- # 务必改为你自己的字符串 JWT_SECRET=hyperf #token过期时间,单位为秒 JWT_TTL=60 + +# ---- 项目配置 ---- +WEB_URL=http://im.gzydong.club +IMG_URL=http://im-img0.gzydong.club +UPLOAD_PATH=/www/data/lumenim +IP_ADDRESS=0.0.0.0 diff --git a/app/Cache/ApplyNumCache.php b/app/Cache/ApplyNumCache.php new file mode 100644 index 0000000..fea2da3 --- /dev/null +++ b/app/Cache/ApplyNumCache.php @@ -0,0 +1,45 @@ +hget(self::KEY, strval($user_id)); + } + + /** + * 设置未读好友申请数(自增加1) + * + * @param int $user_id 用户ID + * @return int + */ + public static function setInc(int $user_id) + { + return redis()->hincrby(self::KEY, $user_id, 1); + } + + /** + * 删除好友申请未读数 + * + * @param int $user_id + */ + public static function del(int $user_id) + { + redis()->hdel(self::KEY, $user_id); + } +} diff --git a/app/Controller/Api/V1/ArticleController.php b/app/Controller/Api/V1/ArticleController.php index 51f43c7..ba8a4fb 100644 --- a/app/Controller/Api/V1/ArticleController.php +++ b/app/Controller/Api/V1/ArticleController.php @@ -33,9 +33,9 @@ class ArticleController extends CController */ public function getArticleClass() { - return $this->response->success( - $this->articleService->getUserClass($this->uid()) - ); + return $this->response->success([ + 'rows' => $this->articleService->getUserClass($this->uid()) + ]); } /** @@ -45,9 +45,9 @@ class ArticleController extends CController */ public function getArticleTags() { - return $this->response->success( - $this->articleService->getUserTags($this->uid()) - ); + return $this->response->success([ + 'tags' => $this->articleService->getUserTags($this->uid()) + ]); } /** @@ -408,7 +408,8 @@ class ArticleController extends CController */ public function uploadArticleAnnex() { - + $file = $this->request->file('annex'); + $file->isValid(); } /** diff --git a/app/Controller/Api/V1/AuthController.php b/app/Controller/Api/V1/AuthController.php index 1a2e200..b67dc3f 100644 --- a/app/Controller/Api/V1/AuthController.php +++ b/app/Controller/Api/V1/AuthController.php @@ -52,7 +52,7 @@ class AuthController extends CController $this->validate($this->request->all(), [ 'mobile' => "required|regex:/^1[345789][0-9]{9}$/", 'password' => 'required', - 'platform' => 'required|in:h5,ios,windows,mac', + 'platform' => 'required|in:h5,ios,windows,mac,web', ]); $userInfo = $this->userService->login( @@ -75,8 +75,8 @@ class AuthController extends CController return $this->response->success([ 'authorize' => [ - 'token' => $token, - 'expire' => $this->jwt->getTTL() + 'access_token' => $token, + 'expires_in' => $this->jwt->getTTL() ], 'user_info' => [ 'nickname' => $userInfo['nickname'], @@ -116,7 +116,7 @@ class AuthController extends CController 'mobile' => "required|regex:/^1[345789][0-9]{9}$/", 'password' => 'required', 'sms_code' => 'required|integer|max:999999', - 'platform' => 'required|in:h5,ios,windows,mac', + 'platform' => 'required|in:h5,ios,windows,mac,web', ]); if (!$this->smsCodeService->check('user_register', $params['mobile'], $params['sms_code'])) { diff --git a/app/Controller/Api/V1/UsersController.php b/app/Controller/Api/V1/UsersController.php index 650b424..7cdb424 100644 --- a/app/Controller/Api/V1/UsersController.php +++ b/app/Controller/Api/V1/UsersController.php @@ -2,6 +2,7 @@ namespace App\Controller\Api\V1; +use App\Cache\ApplyNumCache; use Hyperf\Di\Annotation\Inject; use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\RequestMapping; @@ -186,19 +187,17 @@ class UsersController extends CController /** * 通过手机号查找用户 * - * @RequestMapping(path="search-user", methods="get") + * @RequestMapping(path="search-user", methods="post") */ public function searchUserInfo() { $params = $this->request->inputs(['user_id', 'mobile']); - $this->validate($params, [ - 'user_id' => 'present|integer', - 'mobile' => "present|regex:/^1[345789][0-9]{9}$/", - ]); - if (!empty($params['user_id'])) { + if (isset($params['user_id'])) { + $this->validate($params, ['user_id' => 'present|integer']); $where['uid'] = $params['user_id']; - } else if (!empty($params['mobile'])) { + } else if (isset($params['mobile'])) { + $this->validate($params, ['mobile' => "present|regex:/^1[345789][0-9]{9}$/"]); $where['mobile'] = $params['mobile']; } else { return $this->response->fail('请求参数不正确...', [], ResponseCode::VALIDATION_ERROR); @@ -322,11 +321,16 @@ class UsersController extends CController } /** + * 获取好友申请未读数 + * * @RequestMapping(path="friend-apply-num", methods="get") */ public function getApplyUnreadNum() { - + $num = ApplyNumCache::get($this->uid()); + return $this->response->success([ + 'unread_num' => $num ? $num : 0 + ]); } /** diff --git a/app/Model/Article/Article.php b/app/Model/Article/Article.php index fdd44f5..1c8be1d 100644 --- a/app/Model/Article/Article.php +++ b/app/Model/Article/Article.php @@ -9,15 +9,15 @@ use App\Model\BaseModel; /** * 笔记数据表模型 * - * @property int $id 笔记ID - * @property int $user_id 用户ID - * @property int $class_id 分类ID + * @property integer $id 笔记ID + * @property integer $user_id 用户ID + * @property integer $class_id 分类ID * @property string $tags_id 笔记标签ID * @property string $title 笔记标题 * @property string $abstract 笔记摘要 * @property string $image 笔记头图 - * @property int $is_asterisk 是否标记星号 - * @property int $status 笔记状态 + * @property integer $is_asterisk 是否标记星号 + * @property integer $status 笔记状态 * @property string $created_at 创建时间 * @property string $updated_at 更新时间 * @property string $deleted_at 删除时间 diff --git a/app/Model/Article/ArticleAnnex.php b/app/Model/Article/ArticleAnnex.php index 9c59eb5..97bfd1a 100644 --- a/app/Model/Article/ArticleAnnex.php +++ b/app/Model/Article/ArticleAnnex.php @@ -9,9 +9,9 @@ use App\Model\BaseModel; /** * 笔记附件数据表模型 * - * @property int $id 笔记附件ID - * @property int $user_id 用户ID - * @property int $article_id 笔记ID + * @property integer $id 笔记附件ID + * @property integer $user_id 用户ID + * @property integer $article_id 笔记ID * @property string $file_suffix 文件后缀名 * @property int $file_size 文件大小 * @property string $save_dir 文件相对路径 diff --git a/app/Model/Article/ArticleClass.php b/app/Model/Article/ArticleClass.php index 462896c..9a9b323 100644 --- a/app/Model/Article/ArticleClass.php +++ b/app/Model/Article/ArticleClass.php @@ -9,11 +9,11 @@ use App\Model\BaseModel; /** * 笔记分类数据表模型 * - * @property int $id 分类ID - * @property int $user_id 用户ID + * @property integer $id 分类ID + * @property integer $user_id 用户ID * @property string $class_name 分类名 - * @property int $sort 排序[值越小越靠前] - * @property int $is_default 默认分类[1:是;0:不是] + * @property integer $sort 排序[值越小越靠前] + * @property integer $is_default 默认分类[1:是;0:不是] * @property string $created_at 创建时间 * * @package App\Model\Article diff --git a/app/Model/Article/ArticleDetail.php b/app/Model/Article/ArticleDetail.php index 90c17d5..62a11e7 100644 --- a/app/Model/Article/ArticleDetail.php +++ b/app/Model/Article/ArticleDetail.php @@ -9,10 +9,10 @@ use App\Model\BaseModel; /** * 笔记详情数据表模型 * - * @property int $id - * @property int $article_id - * @property string $md_content - * @property string $content + * @property integer $id 笔记详情ID + * @property integer $article_id 笔记ID + * @property string $md_content 笔记MD格式内容 + * @property string $content 笔记html格式内容 * * @package App\Model\Article */ diff --git a/app/Model/Article/ArticleTag.php b/app/Model/Article/ArticleTag.php index fd84694..a364d26 100644 --- a/app/Model/Article/ArticleTag.php +++ b/app/Model/Article/ArticleTag.php @@ -7,11 +7,11 @@ namespace App\Model\Article; use App\Model\BaseModel; /** - * @property int $id - * @property int $user_id - * @property string $tag_name - * @property int $sort - * @property \Carbon\Carbon $created_at + * @property integer $id 标签ID + * @property integer $user_id 用户ID + * @property string $tag_name 标签名称 + * @property integer $sort 标签排序 + * @property integer $created_at 创建时间 */ class ArticleTag extends BaseModel { @@ -27,7 +27,9 @@ class ArticleTag extends BaseModel * * @var array */ - protected $fillable = []; + protected $fillable = [ + 'user_id','tag_name','sort','created_at' + ]; /** * The attributes that should be cast to native types. @@ -38,6 +40,6 @@ class ArticleTag extends BaseModel 'id' => 'integer', 'user_id' => 'integer', 'sort' => 'integer', - 'created_at' => 'datetime' + 'created_at' => 'integer' ]; } diff --git a/app/Model/BaseModel.php b/app/Model/BaseModel.php index ebf98a4..1280e18 100644 --- a/app/Model/BaseModel.php +++ b/app/Model/BaseModel.php @@ -2,20 +2,21 @@ declare(strict_types=1); -/** - * This file is part of Hyperf. - * - * @link https://www.hyperf.io - * @document https://hyperf.wiki - * @contact group@hyperf.io - * @license https://github.com/hyperf/hyperf/blob/master/LICENSE - */ - namespace App\Model; use Hyperf\DbConnection\Model\Model as CModel; +/** + * 数据库模型 - 基础类 + * + * @package App\Model + */ abstract class BaseModel extends CModel { + /** + * 关闭自动维护时间字段 + * + * @var bool + */ public $timestamps = false; } diff --git a/app/Model/Chat/ChatRecordsCode.php b/app/Model/Chat/ChatRecordsCode.php index f78e23a..87c65e4 100644 --- a/app/Model/Chat/ChatRecordsCode.php +++ b/app/Model/Chat/ChatRecordsCode.php @@ -7,12 +7,16 @@ namespace App\Model\Chat; use App\Model\BaseModel; /** - * @property int $id - * @property int $record_id - * @property int $user_id - * @property string $code_lang - * @property string $code - * @property \Carbon\Carbon $created_at + * 聊天记录(代码块消息)数据表模型 + * + * @property int $id 代码块ID + * @property int $record_id 聊天记录ID + * @property int $user_id 用户ID + * @property string $code_lang 代码语言 + * @property string $code 代码详情 + * @property string $created_at 创建时间 + * + * @package App\Model\Chat */ class ChatRecordsCode extends BaseModel { @@ -35,5 +39,10 @@ class ChatRecordsCode extends BaseModel * * @var array */ - protected $casts = ['id' => 'integer', 'record_id' => 'integer', 'user_id' => 'integer', 'created_at' => 'datetime']; + protected $casts = [ + 'id' => 'integer', + 'record_id' => 'integer', + 'user_id' => 'integer', + 'created_at' => 'datetime' + ]; } diff --git a/app/Model/Chat/ChatRecordsDelete.php b/app/Model/Chat/ChatRecordsDelete.php index 5874ea3..f6226e1 100644 --- a/app/Model/Chat/ChatRecordsDelete.php +++ b/app/Model/Chat/ChatRecordsDelete.php @@ -7,10 +7,14 @@ namespace App\Model\Chat; use App\Model\BaseModel; /** - * @property int $id - * @property int $record_id - * @property int $user_id - * @property \Carbon\Carbon $created_at + * 聊天记录(已删除消息)数据表模型 + * + * @property int $id 代码块ID + * @property int $record_id 聊天记录ID + * @property int $user_id 用户ID + * @property string $created_at 删除时间 + * + * @package App\Model\Chat */ class ChatRecordsDelete extends BaseModel { diff --git a/app/Model/Chat/ChatRecordsFile.php b/app/Model/Chat/ChatRecordsFile.php index 43e4dfd..516e362 100644 --- a/app/Model/Chat/ChatRecordsFile.php +++ b/app/Model/Chat/ChatRecordsFile.php @@ -7,18 +7,22 @@ namespace App\Model\Chat; use App\Model\BaseModel; /** - * @property int $id - * @property int $record_id - * @property int $user_id - * @property int $file_source - * @property int $file_type - * @property int $save_type - * @property string $original_name - * @property string $file_suffix - * @property int $file_size - * @property string $save_dir - * @property int $is_delete - * @property \Carbon\Carbon $created_at + * 聊天记录(文件消息)数据表模型 + * + * @property int $id 文件消息ID + * @property int $record_id 聊天记录ID + * @property int $user_id 用户ID + * @property int $file_source 文件上传来源 + * @property int $file_type 文件类型 + * @property int $save_type 文件保存类型 + * @property string $original_name 文件原始名称 + * @property string $file_suffix 文件后缀名 + * @property int $file_size 文件大小 + * @property string $save_dir 文件保存路径 + * @property int $is_delete 是否已删除 + * @property string $created_at 上传时间 + * + * @package App\Model\Chat */ class ChatRecordsFile extends BaseModel { diff --git a/app/Model/Chat/ChatRecordsForward.php b/app/Model/Chat/ChatRecordsForward.php index 2720f81..febd8c7 100644 --- a/app/Model/Chat/ChatRecordsForward.php +++ b/app/Model/Chat/ChatRecordsForward.php @@ -7,12 +7,16 @@ namespace App\Model\Chat; use App\Model\BaseModel; /** - * @property int $id - * @property int $record_id - * @property int $user_id - * @property string $records_id - * @property string $text - * @property \Carbon\Carbon $created_at + * 聊天记录(转发消息)数据表模型 + * + * @property int $id 转发ID + * @property int $record_id 聊天记录ID + * @property int $user_id 用户ID + * @property string $records_id 聊天记录ID,多个用英文','拼接 + * @property string $text 缓存信息 + * @property int $created_at 转发时间 + * + * @package App\Model\Chat */ class ChatRecordsForward extends BaseModel { @@ -37,5 +41,10 @@ class ChatRecordsForward extends BaseModel * * @var array */ - protected $casts = ['id' => 'integer', 'record_id' => 'integer', 'user_id' => 'integer', 'created_at' => 'datetime']; + protected $casts = [ + 'id' => 'integer', + 'record_id' => 'integer', + 'user_id' => 'integer', + 'created_at' => 'datetime' + ]; } diff --git a/app/Model/Emoticon.php b/app/Model/Emoticon.php index b32afe4..0922228 100644 --- a/app/Model/Emoticon.php +++ b/app/Model/Emoticon.php @@ -5,10 +5,14 @@ declare (strict_types=1); namespace App\Model; /** + * Class Emoticon + * * @property int $id * @property string $name * @property string $url * @property \Carbon\Carbon $created_at + * + * @package App\Model */ class Emoticon extends BaseModel { @@ -31,5 +35,8 @@ class Emoticon extends BaseModel * * @var array */ - protected $casts = ['id' => 'integer', 'created_at' => 'datetime']; + protected $casts = [ + 'id' => 'integer', + 'created_at' => 'datetime' + ]; } diff --git a/app/Model/Group/UsersGroupMember.php b/app/Model/Group/UsersGroupMember.php index 9ba3999..6b878ab 100644 --- a/app/Model/Group/UsersGroupMember.php +++ b/app/Model/Group/UsersGroupMember.php @@ -7,13 +7,17 @@ namespace App\Model\Group; use App\Model\BaseModel; /** - * @property int $id - * @property int $group_id - * @property int $user_id - * @property int $group_owner - * @property int $status - * @property string $visit_card - * @property \Carbon\Carbon $created_at + * 用户群组[成员]数据表模型 + * + * @property int $id 群成员ID + * @property int $group_id 群组ID + * @property int $user_id 用户ID + * @property int $group_owner 是否群主[0:否;1:是;] + * @property int $status 退群状态[0:正常状态;1:已退群;] + * @property string $visit_card 用户群名片 + * @property string $created_at 入群时间 + * + * @package App\Model\Group */ class UsersGroupMember extends BaseModel { diff --git a/app/Model/Group/UsersGroupNotice.php b/app/Model/Group/UsersGroupNotice.php index 1dcd0d7..88bf525 100644 --- a/app/Model/Group/UsersGroupNotice.php +++ b/app/Model/Group/UsersGroupNotice.php @@ -7,15 +7,19 @@ namespace App\Model\Group; use App\Model\BaseModel; /** - * @property int $id - * @property int $group_id - * @property int $user_id - * @property string $title - * @property string $content - * @property int $is_delete - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $deleted_at + * 用户群组[公告消息]数据表模型 + * + * @property int $id 群公告ID + * @property int $group_id 群ID + * @property int $user_id 发布者ID + * @property string $title 公告标题 + * @property string $content 公告内容 + * @property int $is_delete 是否删除[0:否;1:是] + * @property string $created_at 发布时间 + * @property string $updated_at 修改时间 + * @property string $deleted_at 删除时间 + * + * @package App\Model\Group */ class UsersGroupNotice extends BaseModel { @@ -31,12 +35,21 @@ class UsersGroupNotice extends BaseModel * * @var array */ - protected $fillable = []; + protected $fillable = [ + + ]; /** * The attributes that should be cast to native types. * * @var array */ - protected $casts = ['id' => 'integer', 'group_id' => 'integer', 'user_id' => 'integer', 'is_delete' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; + protected $casts = [ + 'id' => 'integer', + 'group_id' => 'integer', + 'user_id' => 'integer', + 'is_delete' => 'integer', + 'created_at' => 'datetime', + 'updated_at' => 'datetime' + ]; } diff --git a/app/Service/TalkService.php b/app/Service/TalkService.php index 6cc7341..87d15cd 100644 --- a/app/Service/TalkService.php +++ b/app/Service/TalkService.php @@ -84,7 +84,7 @@ class TalkService extends BaseService } } } else { - $data['name'] = $item['group_name']; + $data['name'] = strval($item['group_name']); $data['avatar'] = $item['group_avatar']; } diff --git a/config/autoload/server.php b/config/autoload/server.php index 3e3f3cd..1b7fb67 100644 --- a/config/autoload/server.php +++ b/config/autoload/server.php @@ -46,7 +46,7 @@ return [ ], 'settings' => [ 'enable_coroutine' => true, - 'worker_num' => 1, + 'worker_num' => swoole_cpu_num(), 'pid_file' => BASE_PATH . '/runtime/hyperf.pid', 'open_tcp_nodelay' => true, 'max_coroutine' => 100000,