初始化

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_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

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()
{
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();
}
/**

View File

@ -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'])) {

View File

@ -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
]);
}
/**

View File

@ -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 删除时间

View File

@ -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 文件相对路径

View File

@ -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

View File

@ -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
*/

View File

@ -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'
];
}

View File

@ -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;
}

View File

@ -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'
];
}

View File

@ -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
{

View File

@ -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
{

View File

@ -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'
];
}

View File

@ -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'
];
}

View File

@ -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
{

View File

@ -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'
];
}

View File

@ -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'];
}

View File

@ -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,