初始化

main
gzydong 2020-11-13 23:09:56 +08:00
parent 0e2a77d958
commit b9e8dbbbc9
20 changed files with 215 additions and 105 deletions

View File

@ -1,6 +1,8 @@
# ---- 基础配置 ----
APP_NAME=hyperf-chat APP_NAME=hyperf-chat
APP_ENV=dev APP_ENV=dev
# ---- Mysql 配置 ----
DB_DRIVER=mysql DB_DRIVER=mysql
DB_HOST=localhost DB_HOST=localhost
DB_PORT=3306 DB_PORT=3306
@ -11,15 +13,20 @@ DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci DB_COLLATION=utf8mb4_unicode_ci
DB_PREFIX= DB_PREFIX=
# ---- Redis 配置 ----
REDIS_HOST=localhost REDIS_HOST=localhost
REDIS_AUTH=(null) REDIS_AUTH=(null)
REDIS_PORT=6379 REDIS_PORT=6379
REDIS_DB=0 REDIS_DB=0
# 本机IP地址 # ---- JWT授权配置 ----
IP_ADDRESS=0.0.0.0
# 务必改为你自己的字符串 # 务必改为你自己的字符串
JWT_SECRET=hyperf JWT_SECRET=hyperf
#token过期时间单位为秒 #token过期时间单位为秒
JWT_TTL=60 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

View File

@ -0,0 +1,45 @@
<?php
namespace App\Cache;
/**
* Class ApplyNumCache
* @package App\Cache
*/
class ApplyNumCache
{
const KEY = 'friend:apply:unread:num';
/**
* 获取好友未读申请数
*
* @param int $user_id 用户ID
* @return string
*/
public static function get(int $user_id)
{
return redis()->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);
}
}

View File

@ -33,9 +33,9 @@ class ArticleController extends CController
*/ */
public function getArticleClass() public function getArticleClass()
{ {
return $this->response->success( return $this->response->success([
$this->articleService->getUserClass($this->uid()) 'rows' => $this->articleService->getUserClass($this->uid())
); ]);
} }
/** /**
@ -45,9 +45,9 @@ class ArticleController extends CController
*/ */
public function getArticleTags() public function getArticleTags()
{ {
return $this->response->success( return $this->response->success([
$this->articleService->getUserTags($this->uid()) 'tags' => $this->articleService->getUserTags($this->uid())
); ]);
} }
/** /**
@ -408,7 +408,8 @@ class ArticleController extends CController
*/ */
public function uploadArticleAnnex() public function uploadArticleAnnex()
{ {
$file = $this->request->file('annex');
$file->isValid();
} }
/** /**

View File

@ -52,7 +52,7 @@ class AuthController extends CController
$this->validate($this->request->all(), [ $this->validate($this->request->all(), [
'mobile' => "required|regex:/^1[345789][0-9]{9}$/", 'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
'password' => 'required', 'password' => 'required',
'platform' => 'required|in:h5,ios,windows,mac', 'platform' => 'required|in:h5,ios,windows,mac,web',
]); ]);
$userInfo = $this->userService->login( $userInfo = $this->userService->login(
@ -75,8 +75,8 @@ class AuthController extends CController
return $this->response->success([ return $this->response->success([
'authorize' => [ 'authorize' => [
'token' => $token, 'access_token' => $token,
'expire' => $this->jwt->getTTL() 'expires_in' => $this->jwt->getTTL()
], ],
'user_info' => [ 'user_info' => [
'nickname' => $userInfo['nickname'], 'nickname' => $userInfo['nickname'],
@ -116,7 +116,7 @@ class AuthController extends CController
'mobile' => "required|regex:/^1[345789][0-9]{9}$/", 'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
'password' => 'required', 'password' => 'required',
'sms_code' => 'required|integer|max:999999', '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'])) { if (!$this->smsCodeService->check('user_register', $params['mobile'], $params['sms_code'])) {

View File

@ -2,6 +2,7 @@
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
use App\Cache\ApplyNumCache;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; 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() public function searchUserInfo()
{ {
$params = $this->request->inputs(['user_id', 'mobile']); $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']; $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']; $where['mobile'] = $params['mobile'];
} else { } else {
return $this->response->fail('请求参数不正确...', [], ResponseCode::VALIDATION_ERROR); return $this->response->fail('请求参数不正确...', [], ResponseCode::VALIDATION_ERROR);
@ -322,11 +321,16 @@ class UsersController extends CController
} }
/** /**
* 获取好友申请未读数
*
* @RequestMapping(path="friend-apply-num", methods="get") * @RequestMapping(path="friend-apply-num", methods="get")
*/ */
public function getApplyUnreadNum() public function getApplyUnreadNum()
{ {
$num = ApplyNumCache::get($this->uid());
return $this->response->success([
'unread_num' => $num ? $num : 0
]);
} }
/** /**

View File

@ -9,15 +9,15 @@ use App\Model\BaseModel;
/** /**
* 笔记数据表模型 * 笔记数据表模型
* *
* @property int $id 笔记ID * @property integer $id 笔记ID
* @property int $user_id 用户ID * @property integer $user_id 用户ID
* @property int $class_id 分类ID * @property integer $class_id 分类ID
* @property string $tags_id 笔记标签ID * @property string $tags_id 笔记标签ID
* @property string $title 笔记标题 * @property string $title 笔记标题
* @property string $abstract 笔记摘要 * @property string $abstract 笔记摘要
* @property string $image 笔记头图 * @property string $image 笔记头图
* @property int $is_asterisk 是否标记星号 * @property integer $is_asterisk 是否标记星号
* @property int $status 笔记状态 * @property integer $status 笔记状态
* @property string $created_at 创建时间 * @property string $created_at 创建时间
* @property string $updated_at 更新时间 * @property string $updated_at 更新时间
* @property string $deleted_at 删除时间 * @property string $deleted_at 删除时间

View File

@ -9,9 +9,9 @@ use App\Model\BaseModel;
/** /**
* 笔记附件数据表模型 * 笔记附件数据表模型
* *
* @property int $id 笔记附件ID * @property integer $id 笔记附件ID
* @property int $user_id 用户ID * @property integer $user_id 用户ID
* @property int $article_id 笔记ID * @property integer $article_id 笔记ID
* @property string $file_suffix 文件后缀名 * @property string $file_suffix 文件后缀名
* @property int $file_size 文件大小 * @property int $file_size 文件大小
* @property string $save_dir 文件相对路径 * @property string $save_dir 文件相对路径

View File

@ -9,11 +9,11 @@ use App\Model\BaseModel;
/** /**
* 笔记分类数据表模型 * 笔记分类数据表模型
* *
* @property int $id 分类ID * @property integer $id 分类ID
* @property int $user_id 用户ID * @property integer $user_id 用户ID
* @property string $class_name 分类名 * @property string $class_name 分类名
* @property int $sort 排序[值越小越靠前] * @property integer $sort 排序[值越小越靠前]
* @property int $is_default 默认分类[1:;0:不是] * @property integer $is_default 默认分类[1:;0:不是]
* @property string $created_at 创建时间 * @property string $created_at 创建时间
* *
* @package App\Model\Article * @package App\Model\Article

View File

@ -9,10 +9,10 @@ use App\Model\BaseModel;
/** /**
* 笔记详情数据表模型 * 笔记详情数据表模型
* *
* @property int $id * @property integer $id 笔记详情ID
* @property int $article_id * @property integer $article_id 笔记ID
* @property string $md_content * @property string $md_content 笔记MD格式内容
* @property string $content * @property string $content 笔记html格式内容
* *
* @package App\Model\Article * @package App\Model\Article
*/ */

View File

@ -7,11 +7,11 @@ namespace App\Model\Article;
use App\Model\BaseModel; use App\Model\BaseModel;
/** /**
* @property int $id * @property integer $id 标签ID
* @property int $user_id * @property integer $user_id 用户ID
* @property string $tag_name * @property string $tag_name 标签名称
* @property int $sort * @property integer $sort 标签排序
* @property \Carbon\Carbon $created_at * @property integer $created_at 创建时间
*/ */
class ArticleTag extends BaseModel class ArticleTag extends BaseModel
{ {
@ -27,7 +27,9 @@ class ArticleTag extends BaseModel
* *
* @var array * @var array
*/ */
protected $fillable = []; protected $fillable = [
'user_id','tag_name','sort','created_at'
];
/** /**
* The attributes that should be cast to native types. * The attributes that should be cast to native types.
@ -38,6 +40,6 @@ class ArticleTag extends BaseModel
'id' => 'integer', 'id' => 'integer',
'user_id' => 'integer', 'user_id' => 'integer',
'sort' => 'integer', 'sort' => 'integer',
'created_at' => 'datetime' 'created_at' => 'integer'
]; ];
} }

View File

@ -2,20 +2,21 @@
declare(strict_types=1); 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; namespace App\Model;
use Hyperf\DbConnection\Model\Model as CModel; use Hyperf\DbConnection\Model\Model as CModel;
/**
* 数据库模型 - 基础类
*
* @package App\Model
*/
abstract class BaseModel extends CModel abstract class BaseModel extends CModel
{ {
/**
* 关闭自动维护时间字段
*
* @var bool
*/
public $timestamps = false; public $timestamps = false;
} }

View File

@ -7,12 +7,16 @@ namespace App\Model\Chat;
use App\Model\BaseModel; use App\Model\BaseModel;
/** /**
* @property int $id * 聊天记录(代码块消息)数据表模型
* @property int $record_id *
* @property int $user_id * @property int $id 代码块ID
* @property string $code_lang * @property int $record_id 聊天记录ID
* @property string $code * @property int $user_id 用户ID
* @property \Carbon\Carbon $created_at * @property string $code_lang 代码语言
* @property string $code 代码详情
* @property string $created_at 创建时间
*
* @package App\Model\Chat
*/ */
class ChatRecordsCode extends BaseModel class ChatRecordsCode extends BaseModel
{ {
@ -35,5 +39,10 @@ class ChatRecordsCode extends BaseModel
* *
* @var array * @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'
];
} }

View File

@ -7,10 +7,14 @@ namespace App\Model\Chat;
use App\Model\BaseModel; use App\Model\BaseModel;
/** /**
* @property int $id * 聊天记录(已删除消息)数据表模型
* @property int $record_id *
* @property int $user_id * @property int $id 代码块ID
* @property \Carbon\Carbon $created_at * @property int $record_id 聊天记录ID
* @property int $user_id 用户ID
* @property string $created_at 删除时间
*
* @package App\Model\Chat
*/ */
class ChatRecordsDelete extends BaseModel class ChatRecordsDelete extends BaseModel
{ {

View File

@ -7,18 +7,22 @@ namespace App\Model\Chat;
use App\Model\BaseModel; use App\Model\BaseModel;
/** /**
* @property int $id * 聊天记录(文件消息)数据表模型
* @property int $record_id *
* @property int $user_id * @property int $id 文件消息ID
* @property int $file_source * @property int $record_id 聊天记录ID
* @property int $file_type * @property int $user_id 用户ID
* @property int $save_type * @property int $file_source 文件上传来源
* @property string $original_name * @property int $file_type 文件类型
* @property string $file_suffix * @property int $save_type 文件保存类型
* @property int $file_size * @property string $original_name 文件原始名称
* @property string $save_dir * @property string $file_suffix 文件后缀名
* @property int $is_delete * @property int $file_size 文件大小
* @property \Carbon\Carbon $created_at * @property string $save_dir 文件保存路径
* @property int $is_delete 是否已删除
* @property string $created_at 上传时间
*
* @package App\Model\Chat
*/ */
class ChatRecordsFile extends BaseModel class ChatRecordsFile extends BaseModel
{ {

View File

@ -7,12 +7,16 @@ namespace App\Model\Chat;
use App\Model\BaseModel; use App\Model\BaseModel;
/** /**
* @property int $id * 聊天记录(转发消息)数据表模型
* @property int $record_id *
* @property int $user_id * @property int $id 转发ID
* @property string $records_id * @property int $record_id 聊天记录ID
* @property string $text * @property int $user_id 用户ID
* @property \Carbon\Carbon $created_at * @property string $records_id 聊天记录ID多个用英文','拼接
* @property string $text 缓存信息
* @property int $created_at 转发时间
*
* @package App\Model\Chat
*/ */
class ChatRecordsForward extends BaseModel class ChatRecordsForward extends BaseModel
{ {
@ -37,5 +41,10 @@ class ChatRecordsForward extends BaseModel
* *
* @var array * @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'
];
} }

View File

@ -5,10 +5,14 @@ declare (strict_types=1);
namespace App\Model; namespace App\Model;
/** /**
* Class Emoticon
*
* @property int $id * @property int $id
* @property string $name * @property string $name
* @property string $url * @property string $url
* @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $created_at
*
* @package App\Model
*/ */
class Emoticon extends BaseModel class Emoticon extends BaseModel
{ {
@ -31,5 +35,8 @@ class Emoticon extends BaseModel
* *
* @var array * @var array
*/ */
protected $casts = ['id' => 'integer', 'created_at' => 'datetime']; protected $casts = [
'id' => 'integer',
'created_at' => 'datetime'
];
} }

View File

@ -7,13 +7,17 @@ namespace App\Model\Group;
use App\Model\BaseModel; use App\Model\BaseModel;
/** /**
* @property int $id * 用户群组[成员]数据表模型
* @property int $group_id *
* @property int $user_id * @property int $id 群成员ID
* @property int $group_owner * @property int $group_id 群组ID
* @property int $status * @property int $user_id 用户ID
* @property string $visit_card * @property int $group_owner 是否群主[0:;1:;]
* @property \Carbon\Carbon $created_at * @property int $status 退群状态[0:正常状态;1:已退群;]
* @property string $visit_card 用户群名片
* @property string $created_at 入群时间
*
* @package App\Model\Group
*/ */
class UsersGroupMember extends BaseModel class UsersGroupMember extends BaseModel
{ {

View File

@ -7,15 +7,19 @@ namespace App\Model\Group;
use App\Model\BaseModel; use App\Model\BaseModel;
/** /**
* @property int $id * 用户群组[公告消息]数据表模型
* @property int $group_id *
* @property int $user_id * @property int $id 群公告ID
* @property string $title * @property int $group_id 群ID
* @property string $content * @property int $user_id 发布者ID
* @property int $is_delete * @property string $title 公告标题
* @property \Carbon\Carbon $created_at * @property string $content 公告内容
* @property \Carbon\Carbon $updated_at * @property int $is_delete 是否删除[0:;1:]
* @property string $deleted_at * @property string $created_at 发布时间
* @property string $updated_at 修改时间
* @property string $deleted_at 删除时间
*
* @package App\Model\Group
*/ */
class UsersGroupNotice extends BaseModel class UsersGroupNotice extends BaseModel
{ {
@ -31,12 +35,21 @@ class UsersGroupNotice extends BaseModel
* *
* @var array * @var array
*/ */
protected $fillable = []; protected $fillable = [
];
/** /**
* The attributes that should be cast to native types. * The attributes that should be cast to native types.
* *
* @var array * @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'
];
} }

View File

@ -84,7 +84,7 @@ class TalkService extends BaseService
} }
} }
} else { } else {
$data['name'] = $item['group_name']; $data['name'] = strval($item['group_name']);
$data['avatar'] = $item['group_avatar']; $data['avatar'] = $item['group_avatar'];
} }

View File

@ -46,7 +46,7 @@ return [
], ],
'settings' => [ 'settings' => [
'enable_coroutine' => true, 'enable_coroutine' => true,
'worker_num' => 1, 'worker_num' => swoole_cpu_num(),
'pid_file' => BASE_PATH . '/runtime/hyperf.pid', 'pid_file' => BASE_PATH . '/runtime/hyperf.pid',
'open_tcp_nodelay' => true, 'open_tcp_nodelay' => true,
'max_coroutine' => 100000, 'max_coroutine' => 100000,