初始化
parent
3d8ecb6c08
commit
5ff02a48c7
|
@ -8,6 +8,7 @@ use Hyperf\HttpServer\Annotation\Controller;
|
|||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\HttpServer\Annotation\Middleware;
|
||||
use App\Service\UserService;
|
||||
use App\Service\SmsCodeService;
|
||||
use Phper666\JWTAuth\JWT;
|
||||
use Phper666\JWTAuth\Middleware\JWTAuthMiddleware;
|
||||
|
||||
|
@ -84,7 +85,7 @@ class AuthController extends CController
|
|||
/**
|
||||
* 退出登录接口
|
||||
*
|
||||
* @RequestMapping(path="logout", methods="get,post")
|
||||
* @RequestMapping(path="logout", methods="post")
|
||||
* @Middleware(JWTAuthMiddleware::class)
|
||||
*/
|
||||
public function logout()
|
||||
|
@ -96,10 +97,38 @@ class AuthController extends CController
|
|||
|
||||
/**
|
||||
* 账号注册接口
|
||||
*
|
||||
* @RequestMapping(path="register", methods="post")
|
||||
*
|
||||
* @param SmsCodeService $smsCodeService
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
public function register()
|
||||
public function register(SmsCodeService $smsCodeService)
|
||||
{
|
||||
$params = $this->request->all();
|
||||
$this->validate($params, [
|
||||
'nickname' => "required",
|
||||
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
|
||||
'password' => 'required',
|
||||
'sms_code' => 'required|integer|max:999999',
|
||||
'platform' => 'required|in:h5,ios,windows,mac',
|
||||
]);
|
||||
|
||||
if (!$smsCodeService->check('user_register', $params['mobile'], $params['sms_code'])) {
|
||||
return $this->response->fail('验证码填写错误...');
|
||||
}
|
||||
|
||||
$isTrue = $this->userService->register([
|
||||
'mobile' => $params['mobile'],
|
||||
'password' => $params['password'],
|
||||
'nickname' => strip_tags($params['nickname']),
|
||||
]);
|
||||
|
||||
if ($isTrue) {
|
||||
$smsCodeService->delCode('user_register', $params['mobile']);
|
||||
}
|
||||
|
||||
return $this->response->success([], 'Successfully logged out');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int $class_id
|
||||
* @property string $tags_id
|
||||
* @property string $title
|
||||
* @property string $abstract
|
||||
* @property string $image
|
||||
* @property int $is_asterisk
|
||||
* @property int $status
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property string $deleted_at
|
||||
*/
|
||||
class Article extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'article';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'user_id' => 'integer', 'class_id' => 'integer', 'is_asterisk' => 'integer', 'status' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int $article_id
|
||||
* @property string $file_suffix
|
||||
* @property int $file_size
|
||||
* @property string $save_dir
|
||||
* @property string $original_name
|
||||
* @property int $status
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property string $deleted_at
|
||||
*/
|
||||
class ArticleAnnex extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'article_annex';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'user_id' => 'integer', 'article_id' => 'integer', 'file_size' => 'integer', 'status' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property string $class_name
|
||||
* @property int $sort
|
||||
* @property int $is_default
|
||||
* @property \Carbon\Carbon $created_at
|
||||
*/
|
||||
class ArticleClass extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'article_class';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'user_id' => 'integer', 'sort' => 'integer', 'is_default' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $article_id
|
||||
* @property string $md_content
|
||||
* @property string $content
|
||||
*/
|
||||
class ArticleDetail extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'article_detail';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'article_id' => 'integer'];
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property string $tag_name
|
||||
* @property int $sort
|
||||
* @property \Carbon\Carbon $created_at
|
||||
*/
|
||||
class ArticleTag extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'article_tags';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'user_id' => 'integer', 'sort' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $source
|
||||
* @property int $msg_type
|
||||
* @property int $user_id
|
||||
* @property int $receive_id
|
||||
* @property string $content
|
||||
* @property int $is_revoke
|
||||
* @property \Carbon\Carbon $created_at
|
||||
*/
|
||||
class ChatRecord extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'chat_records';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'source' => 'integer', 'msg_type' => 'integer', 'user_id' => 'integer', 'receive_id' => 'integer', 'is_revoke' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $record_id
|
||||
* @property int $user_id
|
||||
* @property string $code_lang
|
||||
* @property string $code
|
||||
* @property \Carbon\Carbon $created_at
|
||||
*/
|
||||
class ChatRecordsCode extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'chat_records_code';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'record_id' => 'integer', 'user_id' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $record_id
|
||||
* @property int $user_id
|
||||
* @property \Carbon\Carbon $created_at
|
||||
*/
|
||||
class ChatRecordsDelete extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'chat_records_delete';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'record_id' => 'integer', 'user_id' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
class ChatRecordsFile extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'chat_records_file';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'record_id' => 'integer', 'user_id' => 'integer', 'file_source' => 'integer', 'file_type' => 'integer', 'save_type' => 'integer', 'file_size' => 'integer', 'is_delete' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $record_id
|
||||
* @property int $user_id
|
||||
* @property string $records_id
|
||||
* @property string $text
|
||||
* @property \Carbon\Carbon $created_at
|
||||
*/
|
||||
class ChatRecordsForward extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'chat_records_forward';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'record_id' => 'integer', 'user_id' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $record_id
|
||||
* @property int $type
|
||||
* @property int $operate_user_id
|
||||
* @property string $user_ids
|
||||
*/
|
||||
class ChatRecordsInvite extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'chat_records_invite';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'record_id' => 'integer', 'type' => 'integer', 'operate_user_id' => 'integer'];
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $url
|
||||
* @property \Carbon\Carbon $created_at
|
||||
*/
|
||||
class Emoticon extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'emoticon';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $emoticon_id
|
||||
* @property int $user_id
|
||||
* @property string $describe
|
||||
* @property string $url
|
||||
* @property string $file_suffix
|
||||
* @property int $file_size
|
||||
* @property \Carbon\Carbon $created_at
|
||||
*/
|
||||
class EmoticonDetail extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'emoticon_details';
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'emoticon_id' => 'integer', 'user_id' => 'integer', 'file_size' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $file_type
|
||||
* @property int $user_id
|
||||
* @property string $hash_name
|
||||
* @property string $original_name
|
||||
* @property int $split_index
|
||||
* @property int $split_num
|
||||
* @property string $save_dir
|
||||
* @property string $file_ext
|
||||
* @property int $file_size
|
||||
* @property int $is_delete
|
||||
* @property int $upload_at
|
||||
*/
|
||||
class FileSplitUpload extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'file_split_upload';
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'file_type' => 'integer', 'user_id' => 'integer', 'split_index' => 'integer', 'split_num' => 'integer', 'file_size' => 'integer', 'is_delete' => 'integer', 'upload_at' => 'integer'];
|
||||
}
|
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
|||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\DbConnection\Model\Model as BaseModel;
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $type
|
||||
* @property int $uid
|
||||
* @property int $friend_id
|
||||
* @property int $group_id
|
||||
* @property int $status
|
||||
* @property int $is_top
|
||||
* @property int $not_disturb
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
*/
|
||||
class UsersChatList extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users_chat_list';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'type' => 'integer', 'uid' => 'integer', 'friend_id' => 'integer', 'group_id' => 'integer', 'status' => 'integer', 'is_top' => 'integer', 'not_disturb' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property string $emoticon_ids
|
||||
*/
|
||||
class UsersEmoticon extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users_emoticon';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'user_id' => 'integer'];
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user1
|
||||
* @property int $user2
|
||||
* @property string $user1_remark
|
||||
* @property string $user2_remark
|
||||
* @property int $active
|
||||
* @property int $status
|
||||
* @property string $agree_time
|
||||
* @property \Carbon\Carbon $created_at
|
||||
*/
|
||||
class UsersFriend extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users_friends';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'user1' => 'integer', 'user2' => 'integer', 'active' => 'integer', 'status' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int $friend_id
|
||||
* @property int $status
|
||||
* @property string $remarks
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
*/
|
||||
class UsersFriendsApply extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users_friends_apply';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'user_id' => 'integer', 'friend_id' => 'integer', 'status' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property string $group_name
|
||||
* @property string $group_profile
|
||||
* @property int $status
|
||||
* @property string $avatar
|
||||
* @property \Carbon\Carbon $created_at
|
||||
*/
|
||||
class UsersGroup extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users_group';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'user_id' => 'integer', 'status' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
class UsersGroupMember extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users_group_member';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['id' => 'integer', 'group_id' => 'integer', 'user_id' => 'integer', 'group_owner' => 'integer', 'status' => 'integer', 'created_at' => 'datetime'];
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
class UsersGroupNotice extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users_group_notice';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
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'];
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
/**
|
||||
* 短信发送服务
|
||||
*
|
||||
* Class SmsCodeService
|
||||
* @package App\Services
|
||||
*/
|
||||
class SmsCodeService
|
||||
{
|
||||
/**
|
||||
* 短信验证码用途渠道
|
||||
*/
|
||||
const SMS_USAGE = [
|
||||
'user_register', // 注册账号
|
||||
'forget_password', // 找回密码验
|
||||
'change_mobile', // 修改手机
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取Redis连接
|
||||
*
|
||||
* @return mixed|\Redis
|
||||
*/
|
||||
private function redis()
|
||||
{
|
||||
return redis();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存key
|
||||
*
|
||||
* @param string $type 短信用途
|
||||
* @param string $mobile 手机号
|
||||
* @return string
|
||||
*/
|
||||
private function getKey(string $type, string $mobile)
|
||||
{
|
||||
return "sms_code:{$type}:{$mobile}";
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码是否正确
|
||||
*
|
||||
* @param string $type 发送类型
|
||||
* @param string $mobile 手机号
|
||||
* @param string $code 验证码
|
||||
* @return bool
|
||||
*/
|
||||
public function check(string $type, string $mobile, string $code)
|
||||
{
|
||||
$sms_code = $this->redis()->get($this->getKey($type, $mobile));
|
||||
|
||||
return $sms_code == $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @param string $usage 验证码用途
|
||||
* @param string $mobile 手机号
|
||||
* @return array|bool
|
||||
*/
|
||||
public function send(string $usage, string $mobile)
|
||||
{
|
||||
if (!$this->isUsages($usage)) {
|
||||
return [false, [
|
||||
'msg' => "[{$usage}]:此类短信验证码不支持发送",
|
||||
'data' => []
|
||||
]];
|
||||
}
|
||||
|
||||
$key = $this->getKey($usage, $mobile);
|
||||
|
||||
// 为防止刷短信行为,此处可进行过滤处理
|
||||
[$isTrue, $data] = $this->filter($usage, $mobile);
|
||||
if (!$isTrue) {
|
||||
return [false, $data];
|
||||
}
|
||||
|
||||
if (!$sms_code = $this->getCode($key)) {
|
||||
$sms_code = mt_rand(100000, 999999);
|
||||
}
|
||||
|
||||
// 设置短信验证码
|
||||
$this->setCode($key, $sms_code);
|
||||
|
||||
// ... 调取短信接口,建议异步任务执行 (暂无短信接口,省略处理)
|
||||
|
||||
return [true, [
|
||||
'msg' => 'success',
|
||||
'data' => ['type' => $usage, 'code' => $sms_code]
|
||||
]];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存的验证码
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCode(string $key)
|
||||
{
|
||||
return $this->redis()->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置验证码缓存
|
||||
*
|
||||
* @param string $key 缓存key
|
||||
* @param string $sms_code 验证码
|
||||
* @param float|int $exp 过期时间(默认15分钟)
|
||||
* @return mixed
|
||||
*/
|
||||
public function setCode(string $key, string $sms_code, $exp = 60 * 15)
|
||||
{
|
||||
return $this->redis()->setex($key, $exp, $sms_code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除验证码缓存
|
||||
*
|
||||
* @param string $usage 验证码用途
|
||||
* @param string $mobile 手机号
|
||||
* @return mixed
|
||||
*/
|
||||
public function delCode(string $usage, string $mobile)
|
||||
{
|
||||
return $this->redis()->del($this->getKey($usage, $mobile));
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信发送过滤验证
|
||||
*
|
||||
* @param string $usage 验证码用途
|
||||
* @param string $mobile 手机号
|
||||
* @return array
|
||||
*/
|
||||
public function filter(string $usage, string $mobile)
|
||||
{
|
||||
// ... 省略处理
|
||||
if (false) {
|
||||
return [false, [
|
||||
'msg' => '过滤原因...',
|
||||
'data' => []
|
||||
]];
|
||||
}
|
||||
|
||||
return [true, [
|
||||
'msg' => 'ok',
|
||||
'data' => []
|
||||
]];
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断验证码用途渠道是否注册
|
||||
*
|
||||
* @param string $usage
|
||||
* @return bool
|
||||
*/
|
||||
public function isUsages(string $usage)
|
||||
{
|
||||
return in_array($usage, self::SMS_USAGE);
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Service;
|
||||
|
||||
use App\Model\User;
|
||||
use App\Model\ArticleClass;
|
||||
|
||||
class UserService extends BaseService
|
||||
{
|
||||
|
@ -26,4 +27,33 @@ class UserService extends BaseService
|
|||
|
||||
return $user->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号注册逻辑
|
||||
*
|
||||
* @param array $data 用户数据
|
||||
* @return bool
|
||||
*/
|
||||
public function register(array $data)
|
||||
{
|
||||
try {
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
$data['created_at'] = date('Y-m-d H:i:s');
|
||||
$result = User::create($data);
|
||||
|
||||
// 创建用户的默认笔记分类
|
||||
ArticleClass::create([
|
||||
'user_id' => $result->id,
|
||||
'class_name' => '我的笔记',
|
||||
'is_default' => 1,
|
||||
'sort' => 1,
|
||||
'created_at' => time()
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
$result = false;
|
||||
DB::rollBack();
|
||||
}
|
||||
|
||||
return $result ? true : false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue