4
This commit is contained in:
@@ -5,6 +5,7 @@ use support\Response;
|
||||
use Shopwwi\WebmanFilesystem\FilesystemFactory;
|
||||
use Shopwwi\WebmanFilesystem\Facade\Storage;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
use taoser\facade\Validate;
|
||||
/**
|
||||
* 基础控制器
|
||||
* @Apidoc\NotParse()
|
||||
@@ -62,14 +63,48 @@ class BaseController
|
||||
*/
|
||||
function upload(Request $request)
|
||||
{
|
||||
try{
|
||||
$user = \support\Jwt::getUser();
|
||||
}catch(\Exception $e){
|
||||
$user = ['id'=>0];
|
||||
}
|
||||
$savePath = $request->post('savePath','files');
|
||||
|
||||
$validate = Validate::rule('savePath', 'alphaNum');
|
||||
$data = ['savePath' => $savePath];
|
||||
if (!$validate->check($data)) {
|
||||
return $this->fail( '参数错误:'.$validate->getError());
|
||||
}
|
||||
$savePath = trim($savePath,'/');
|
||||
$savePath = 'upload/'.$savePath.'/'.$user['id'];
|
||||
\support\Log::alert('savePath:'.$savePath);
|
||||
$mimetype = explode(',',Config('site.upload_mimetype'));
|
||||
$maxsize = Config('site.upload_maxsize')*1024*1024;
|
||||
//多文件上传
|
||||
$files = $request->file();
|
||||
try {
|
||||
$result = Storage::adapter('public')
|
||||
->path('upload/files')
|
||||
->size(1024*1024*10)
|
||||
->extYes(['image/jpeg','image/png'])
|
||||
->uploads($files,0,1024*1024*100,false);
|
||||
->path($savePath)
|
||||
->size($maxsize)
|
||||
->extYes($mimetype)
|
||||
->uploads($files,0,$maxsize * count($files),false);
|
||||
$save_datas = [];
|
||||
foreach($result as $k=>$fileinfo){
|
||||
$save_datas[] = [
|
||||
'user_id' => $user['id'],
|
||||
'category' => 'default',
|
||||
'title' => $fileinfo->origin_name,
|
||||
'path' => $fileinfo->file_name,
|
||||
'size' => $fileinfo->size,
|
||||
'mime_type' => $fileinfo->mime_type,
|
||||
'extension' => $fileinfo->extension,
|
||||
'height' => $fileinfo->file_height,
|
||||
'width' => $fileinfo->file_width,
|
||||
'sha1' => sha1_file(public_path($fileinfo->file_name)),
|
||||
'use_count' => 0,
|
||||
];
|
||||
}
|
||||
\app\model\Files::insertAll($save_datas);
|
||||
return $this->success(__('successful'),$result);
|
||||
}catch (\Exception $e){
|
||||
return $this->error($e->getMessage());
|
||||
|
||||
@@ -12,6 +12,7 @@ use Shopwwi\WebmanFilesystem\FilesystemFactory;
|
||||
use Shopwwi\WebmanFilesystem\Facade\Storage;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
use think\facade\Db;
|
||||
/**
|
||||
* 公共接口
|
||||
*/
|
||||
@@ -34,7 +35,7 @@ class CommonController extends BaseController{
|
||||
*
|
||||
* @Apidoc\Query("version", type="string", require=true, desc="版本号")
|
||||
*/
|
||||
public function init()
|
||||
public function init(Request $request)
|
||||
{
|
||||
$lang = input('lang','en-US');
|
||||
locale( $lang);
|
||||
@@ -42,9 +43,9 @@ class CommonController extends BaseController{
|
||||
$disallowFields = [
|
||||
'api_token','reward_time_limit',
|
||||
'mail_type','mail_smtp_host','mail_smtp_port','mail_smtp_user','mail_smtp_pass','mail_verify_type','mail_from',
|
||||
'attachmentcategory','categorytype','cdkey_category','configgroup','flagtype',
|
||||
'attachment_category','categorytype','cdkey_category','configgroup','flagtype',
|
||||
'languages','forbiddenip','fixedpage','admin_login_captcha',
|
||||
'mimetype','multipart','multiple','chunksize','classname','thumbstyle','previewtpl','timeout','maxsize','container',
|
||||
'upload_mimetype','upload_multipart','upload_multiple','upload_thumbstyle','upload_previewtpl','upload_timeout','upload_maxsize',
|
||||
'yeji_jicha_reward','suanli_rate','agent_expirs_retention','allow_currencys','allow_balance_log',
|
||||
'agent_commission_total_rate','agent_commission_layer_rate','differential_commission_total_rate'
|
||||
];
|
||||
@@ -58,13 +59,30 @@ class CommonController extends BaseController{
|
||||
$config['server_status_list'] = \app\enum\ServerStatus::toArray();
|
||||
return $this->success(__('successful'), $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* test
|
||||
* @Apidoc\Query("lang", type="string",require=true, desc="邮箱")
|
||||
* @Apidoc\Method ("GET")
|
||||
* 验证是否升级
|
||||
*/
|
||||
function test(){
|
||||
return $this->error(__('Invalid parameters'));
|
||||
public function checkUpgrade(Request $request)
|
||||
{
|
||||
$field = 'id,type,force,source,version,content';
|
||||
$verUpdate = new \app\model\Version;
|
||||
$version = Input('version');
|
||||
$platform = Input('platform');
|
||||
$version_wgt = Input('version_wgt');
|
||||
|
||||
// 查询整包、外链数据
|
||||
$update_data = $verUpdate->where(['type'=>['in', '0,2'], 'status'=>1, 'version'=>['>', $version], 'platform'=>$platform])->field($field)->order('id desc')->find();
|
||||
if($update_data) {
|
||||
return $this->success('',$update_data);
|
||||
}
|
||||
|
||||
// 查询WGT数据
|
||||
$update_wgt_data = $verUpdate->where(['type'=>1, 'status'=>1, 'version_wgt'=>['>', $version_wgt], 'platform'=>$platform])->field($field)->order('id desc')->find();
|
||||
if($update_wgt_data) {
|
||||
return $this->success('',$update_wgt_data);
|
||||
}
|
||||
return $this->success('',[]);
|
||||
}
|
||||
/**
|
||||
* 注册会员
|
||||
@@ -84,65 +102,72 @@ class CommonController extends BaseController{
|
||||
$username = input('username');
|
||||
$mobile = input('mobile');
|
||||
$invite_code = input('invite_code');
|
||||
if ($email && !Validate::is($email, "email")) {
|
||||
return $this->error(__('Email is incorrect'));
|
||||
$type = input('type');
|
||||
if (!in_array($type,Config('site.user_register_way')) ) {
|
||||
return $this->error(__('Unknown register way'));
|
||||
}
|
||||
if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
|
||||
return $this->error(__('Mobile is incorrect'));
|
||||
}
|
||||
if(Config('site.user_register_way') == 'mobile'){
|
||||
if (!$mobile) {
|
||||
return $this->error(__('Invalid parameters'));
|
||||
}
|
||||
$username = $mobile;
|
||||
captcha_verfiy('mobile','register',$mobile);
|
||||
}else if(Config('site.user_register_way') == 'email'){
|
||||
if (!$email) {
|
||||
return $this->error(__('Invalid parameters'));
|
||||
}
|
||||
if ($email && !Validate::is($email, "email")) {
|
||||
if ($type == 'email') {
|
||||
if(!$email || !Validate::is($email, "email")){
|
||||
return $this->error(__('Email is incorrect'));
|
||||
}
|
||||
$username = $email;
|
||||
captcha_verfiy('email','register',$email);
|
||||
}else{
|
||||
if (!$username) {
|
||||
return $this->error(__('Invalid parameters'));
|
||||
unset($mobile);
|
||||
//captcha_verfiy('email','register',$email,false);
|
||||
}
|
||||
if ($type == 'mobile') {
|
||||
if(!$mobile || !Validate::regex($mobile, "^1\d{10}$")){
|
||||
return $this->error(__('Mobile is incorrect'));
|
||||
}
|
||||
$username = $mobile;
|
||||
unset($email);
|
||||
//captcha_verfiy('mobile','register',$mobile,false);
|
||||
}
|
||||
if ($type == 'username') {
|
||||
if(!$email || !Validate::is($email, "email")){
|
||||
return $this->error(__('Username is incorrect'));
|
||||
}
|
||||
}
|
||||
if (!$password) {
|
||||
return $this->error(__('Invalid parameters'));
|
||||
}
|
||||
$extends = [
|
||||
'role_id' => 0,
|
||||
'group' => 0,
|
||||
'avatar' => '/static/img/avatar.png',
|
||||
];
|
||||
// if (!$trade_password) {
|
||||
// return $this->error(__('Invalid trade password'));
|
||||
// }else{
|
||||
// $extends['trade_password'] = \plugin\admin\app\common\Util::passwordHash($trade_password);
|
||||
// }
|
||||
//邀请码
|
||||
if(!$invite_code){
|
||||
return $this->error(__('Invalid invite code'));
|
||||
}
|
||||
if(strlen($invite_code) == 12){
|
||||
//系统生产的一次性推荐吗
|
||||
$inviteModel = \app\model\Invitecode::where('code',$invite_code)->find();
|
||||
if(!$inviteModel){
|
||||
return $this->error(__('错误的邀请码'));
|
||||
if ($invite_code)
|
||||
{
|
||||
if(strlen($invite_code) == 12){
|
||||
//系统生产的一次性推荐吗
|
||||
$inviteModel = \app\model\Invitecode::where('code',$invite_code)->find();
|
||||
if(!$inviteModel){
|
||||
return $this->error(__('错误的邀请码'));
|
||||
}
|
||||
$extends['group'] = 2;
|
||||
$extends['role_id'] = 1;
|
||||
$extends['parent_id'] = 0;
|
||||
}else{
|
||||
$inviter_user = UserModel::where('invite_code',$invite_code)->field('group,id')->find();
|
||||
if(!$inviter_user){
|
||||
return $this->error(__('Invalid invite code'));
|
||||
}
|
||||
$extends['parent_id'] = $inviter_user['id'];
|
||||
}
|
||||
$extends['group'] = 2;
|
||||
$extends['role_id'] = 1;
|
||||
$extends['parent_id'] = 0;
|
||||
}else{
|
||||
$inviter_user = UserModel::where('invite_code',$invite_code)->field('group,id')->find();
|
||||
if(!$inviter_user){
|
||||
return $this->error(__('Invalid invite code'));
|
||||
}
|
||||
$extends['parent_id'] = $inviter_user['id'];
|
||||
//return $this->error(__('Invalid invite code'));
|
||||
}
|
||||
$extends = [
|
||||
'role_id' => 0,
|
||||
'group_id' => 0,
|
||||
'avatar' => '/static/img/avatar.png',
|
||||
];
|
||||
// validate(\app\validate\User::class)
|
||||
// ->scene('edit')
|
||||
// ->check([
|
||||
// 'name' => 'thinkphp',
|
||||
// 'email' => 'thinkphp@qq.com',
|
||||
// ]);
|
||||
try {
|
||||
$user = \support\Jwt::register($username, $password, $email, $mobile, $extends);
|
||||
if($inviteModel){
|
||||
@@ -150,8 +175,15 @@ class CommonController extends BaseController{
|
||||
$inviteModel->save();
|
||||
}
|
||||
$data = ['userinfo' => $user];
|
||||
// if ($type == 'email') {
|
||||
// captcha_verfiy('email','register',$email,true);
|
||||
// }else if ($type == 'mobile') {
|
||||
// captcha_verfiy('mobile','register',$mobile,true);
|
||||
// }else{
|
||||
// captcha_verfiy('image','register',$mobile,true);
|
||||
// }
|
||||
return $this->success(__('Sign up successful'), $data);
|
||||
} catch (\Throwable $e) {
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -163,12 +195,30 @@ class CommonController extends BaseController{
|
||||
*/
|
||||
public function login(Request $request){
|
||||
$username = input('username');
|
||||
$mobile = input('mobile');
|
||||
$email = input('email');
|
||||
$password = input('password');
|
||||
if (!$username || !$password) {
|
||||
return $this->fail(__('Invalid username or password'));
|
||||
$type = input(param: 'type');
|
||||
if (!$password) {
|
||||
return $this->fail(__('Invalid username or password').'0');
|
||||
}
|
||||
if($type == 'mobile'){
|
||||
if (!$mobile ) {
|
||||
return $this->fail(__('Invalid username or password').'1');
|
||||
}
|
||||
$username = $mobile;
|
||||
}else if($type == 'email'){
|
||||
if (!$email ) {
|
||||
return $this->fail(__('Invalid username or password').'2');
|
||||
}
|
||||
$username = $email;
|
||||
}else{
|
||||
if (!$username ) {
|
||||
return $this->fail(__('Invalid username or password').'3');
|
||||
}
|
||||
}
|
||||
try{
|
||||
$user = \support\Jwt::login($username, $password,'username');
|
||||
$user = \support\Jwt::login($username, $password,$type);
|
||||
if($user === false){
|
||||
return $this->fail(\support\Jwt::getError());
|
||||
}
|
||||
@@ -218,15 +268,15 @@ class CommonController extends BaseController{
|
||||
$user = false;
|
||||
}
|
||||
if($user){
|
||||
captcha_verfiy('mobile','reset_trade_pwd',$user->mobile);
|
||||
captcha_verfiy('mobile','reset_pwd',$user->mobile);
|
||||
}
|
||||
}else{
|
||||
if ($email && Validate::is($email, "email")) {
|
||||
captcha_verfiy('email','reset_trade_pwd',$email);
|
||||
captcha_verfiy('email','reset_pwd',$email);
|
||||
$user = UserModel::getByEmail($email);
|
||||
}
|
||||
if ($mobile && Validate::regex($mobile, "^1\d{10}$")) {
|
||||
captcha_verfiy('mobile','reset_trade_pwd',$mobile);
|
||||
captcha_verfiy('mobile','reset_pwd',$mobile);
|
||||
$user = UserModel::getByMobile($mobile);
|
||||
}
|
||||
}
|
||||
@@ -309,6 +359,7 @@ class CommonController extends BaseController{
|
||||
* @Apidoc\Param("email", type="string",require=true, desc="邮箱,可选")
|
||||
*/
|
||||
public function captcha(Request $request){
|
||||
$debug = true;
|
||||
$request->input('type');
|
||||
$type = $request->input('type');
|
||||
$event = $request->input('event');
|
||||
@@ -331,17 +382,19 @@ class CommonController extends BaseController{
|
||||
return $this->fail(__('Only one verification code can be sent within %second% seconds',['%second%'=>$expris]));
|
||||
}
|
||||
}
|
||||
$code =\support\Random::numeric(4);
|
||||
$code =\support\Random::numeric(6);
|
||||
$list[$code] = time();
|
||||
cache($key,$list);
|
||||
cache('exp_'.$key,time());
|
||||
addJob([
|
||||
'email' => $email,
|
||||
'title' => __("Mt email code"),
|
||||
'event' => $event,
|
||||
'code' => $code
|
||||
],'Email');
|
||||
return $this->success(__('Email sent successfully'));
|
||||
// addJob([
|
||||
// 'email' => $email,
|
||||
// 'title' => __("Mt email code"),
|
||||
// 'event' => $event,
|
||||
// 'code' => $code
|
||||
// ],'Email');
|
||||
return $this->success(__('Email sent successfully'),[
|
||||
'code'=> $debug ? $code : ''
|
||||
]);
|
||||
}elseif($type == 'mobile'){
|
||||
$mobile = $request->input('mobile');
|
||||
if(!$mobile){
|
||||
@@ -364,7 +417,7 @@ class CommonController extends BaseController{
|
||||
return $this->fail(__('Only one verification code can be sent within %second% seconds',['%second%'=>$expris]));
|
||||
}
|
||||
}
|
||||
$code =\support\Random::numeric(4);
|
||||
$code =\support\Random::numeric(6);
|
||||
$list[$code] = time();
|
||||
cache($key,$list);
|
||||
cache('exp_'.$key,time());
|
||||
@@ -373,7 +426,9 @@ class CommonController extends BaseController{
|
||||
'event' => $event,
|
||||
'code' => $code
|
||||
],'Sms');
|
||||
return $this->success(__('SMS sent successfully'));
|
||||
return $this->success(__('SMS sent successfully'),[
|
||||
'code'=> $debug ? $code : ''
|
||||
]);
|
||||
}else{
|
||||
//TODO 图像验证码没有唯一的KEY
|
||||
$key = 'captcha_'.$event.'_';
|
||||
@@ -406,13 +461,14 @@ class CommonController extends BaseController{
|
||||
*/
|
||||
public function verify_captcha(Request $request): Response
|
||||
{
|
||||
$type = $request->input('type');
|
||||
$email = $request->post('email');
|
||||
$mobile = $request->input('mobile');
|
||||
$event = $request->post('event');
|
||||
try {
|
||||
if($email){
|
||||
if($type == 'email'){
|
||||
$result = captcha_verfiy('email', $event , $email,false);
|
||||
}elseif($mobile){
|
||||
}elseif($type == 'mobile'){
|
||||
$result = captcha_verfiy('mobile', $event , $mobile,false);
|
||||
}else{
|
||||
$result = captcha_verfiy('image', $event , '',false);
|
||||
@@ -425,24 +481,4 @@ class CommonController extends BaseController{
|
||||
}
|
||||
return $this->success(__('successful'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("上传")
|
||||
* @Apidoc\Method("POST")
|
||||
*/
|
||||
function upload(Request $request)
|
||||
{
|
||||
//多文件上传
|
||||
$files = $request->file();
|
||||
try {
|
||||
$result = Storage::adapter('public')
|
||||
->path('upload/files')
|
||||
->size(1024*1024*10)
|
||||
->extYes(['image/jpeg','image/png'])
|
||||
->uploads($files,0,1024*1024*100,false);
|
||||
return $this->success(__('successful'),$result);
|
||||
}catch (\Exception $e){
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
<?php
|
||||
namespace app\api\controller;
|
||||
use Shopwwi\WebmanFilesystem\FilesystemFactory;
|
||||
use Shopwwi\WebmanFilesystem\Facade\Storage;
|
||||
use app\model\User as UserModel;
|
||||
use app\model\Realname as RealnameModel;
|
||||
use app\model\FriendCircle as FriendCircleModel;
|
||||
use app\model\FriendCircleLike as FriendCircleLikeModel;
|
||||
use app\model\FriendCircleComment as FriendCircleCommentModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use taoser\facade\Validate;
|
||||
use support\think\Db;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 朋友圈
|
||||
*/
|
||||
class FriendCircleController extends BaseController{
|
||||
/**
|
||||
* 不需要鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedAuth = ['*'];
|
||||
|
||||
/**
|
||||
* 无需登录及鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedLogin = [];
|
||||
/**
|
||||
* 朋友圈设置
|
||||
* @return void
|
||||
*/
|
||||
function info(Request $request): Response{
|
||||
$res = $this->newcount($request);
|
||||
$response = $res->rawBody();
|
||||
$json = json_decode($response,true);
|
||||
$json['data']['settings'] = [
|
||||
'bg' => '',
|
||||
];
|
||||
$json['data']['last_unread_item'] = [
|
||||
'user_id' => '1',
|
||||
'avatar' => '',
|
||||
'nickname' => '',
|
||||
];
|
||||
$res->withBody(json_encode($json));
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* @Apidoc\Title("列表")
|
||||
* @Apidoc\Method("GET")
|
||||
* @Apidoc\Query("page", type="int", require=true, desc="页码",default=1)
|
||||
* @Apidoc\Query("limit", type="int", require=true, desc="分页大小",default=10)
|
||||
* @Apidoc\Query("user_id", type="int", require=false, desc="用户ID,不传则获取所有")
|
||||
*/
|
||||
function list(Request $request): Response
|
||||
{
|
||||
$page = (int)$request->get('page', 1);
|
||||
$limit = (int)$request->get('limit', 10);
|
||||
$user_id = $request->get('user_id', 0);
|
||||
|
||||
$query = FriendCircleModel::where('status', 1)
|
||||
->with(['user' => function($query) {
|
||||
$query->field('id,nickname,avatar');
|
||||
}])
|
||||
->order('created_at', 'desc');
|
||||
|
||||
// 如果指定了用户ID,只获取该用户的朋友圈
|
||||
if ($user_id > 0) {
|
||||
$query->where('user_id', $user_id);
|
||||
}
|
||||
|
||||
$list = $query->paginate([
|
||||
'list_rows' => $limit,
|
||||
'page' => $page,
|
||||
]);
|
||||
|
||||
$current_user = \support\Jwt::getUser();
|
||||
$current_user_id = $current_user ? $current_user->id : 0;
|
||||
|
||||
// 处理每条朋友圈数据
|
||||
$items = $list->items();
|
||||
$list->each(function($item) use ($current_user_id){
|
||||
// 获取点赞列表
|
||||
$likes = FriendCircleLikeModel::where('circle_id', $item->id)
|
||||
->with(['user' => function($query) {
|
||||
$query->field('id,nickname,avatar');
|
||||
}])
|
||||
->order('created_at', 'desc')
|
||||
->limit(20)
|
||||
->select();
|
||||
|
||||
// 检查当前用户是否已点赞
|
||||
$is_liked = false;
|
||||
if ($current_user_id > 0) {
|
||||
$is_liked = FriendCircleLikeModel::where('circle_id', $item->id)
|
||||
->where('user_id', $current_user_id)
|
||||
->count() > 0;
|
||||
}
|
||||
|
||||
// 获取评论列表(最新10条)
|
||||
$comments = FriendCircleCommentModel::where('circle_id', $item->id)
|
||||
->where('status', 1)
|
||||
->with(['user' => function($query) {
|
||||
$query->field('id,nickname,avatar');
|
||||
}, 'replyUser' => function($query) {
|
||||
$query->field('id,nickname,avatar');
|
||||
}])
|
||||
->order('created_at', 'asc')
|
||||
->limit(10)
|
||||
->select();
|
||||
|
||||
// 格式化数据
|
||||
$item->is_liked = $is_liked;
|
||||
$item->likes = $likes;
|
||||
$item->comments = $comments;
|
||||
|
||||
// 处理图片URL
|
||||
if (!empty($item->files)) {
|
||||
$files = is_array($item->files) ? $item->files : json_decode($item->files, true);
|
||||
if (is_array($files)) {
|
||||
$item->files = array_map(function($file) {
|
||||
return cdnurl($file);
|
||||
}, $files);
|
||||
} else {
|
||||
$item->files = [];
|
||||
}
|
||||
} else {
|
||||
$item->files = [];
|
||||
}
|
||||
|
||||
// 处理用户头像
|
||||
if ($item->user && $item->user->avatar) {
|
||||
$item->user->avatar = cdnurl($item->user->avatar);
|
||||
}
|
||||
|
||||
// 处理点赞用户头像
|
||||
foreach ($item->likes as $like) {
|
||||
if ($like->user && $like->user->avatar) {
|
||||
$like->user->avatar = cdnurl($like->user->avatar);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理评论用户头像
|
||||
foreach ($item->comments as $comment) {
|
||||
if ($comment->user && $comment->user->avatar) {
|
||||
$comment->user->avatar = cdnurl($comment->user->avatar);
|
||||
}
|
||||
if ($comment->replyUser && $comment->replyUser->avatar) {
|
||||
$comment->replyUser->avatar = cdnurl($comment->replyUser->avatar);
|
||||
}
|
||||
}
|
||||
return $item;
|
||||
});
|
||||
|
||||
return $this->success('ok', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("最近更新的数量")
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("last_see", type="string",require=false, desc="最近查看的时间戳")
|
||||
*/
|
||||
function newcount(Request $request): Response
|
||||
{
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
|
||||
$last_see = $request->post('last_see');
|
||||
if (empty($last_see)) {
|
||||
$last_see = cache('last_see_' . $user->id);
|
||||
}
|
||||
|
||||
if (empty($last_see)) {
|
||||
$last_see = time() - 86400; // 默认24小时前
|
||||
} else {
|
||||
// 保存最后查看时间
|
||||
cache('last_see_' . $user->id, $last_see);
|
||||
}
|
||||
|
||||
// 统计从上次查看时间到现在新增的朋友圈数量
|
||||
$count = FriendCircleModel::where('status', 1)
|
||||
->where('created_at', '>', $last_see)
|
||||
->count();
|
||||
|
||||
return $this->success('ok', ['count' => $count]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("发布朋友圈")
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("body", type="string",require=false, desc="内容")
|
||||
* @Apidoc\Param("files", type="string",require=false, desc="图片列表(JSON数组)")
|
||||
*/
|
||||
function create(Request $request): Response
|
||||
{
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
|
||||
$body = $request->post('content', '');
|
||||
$files = $request->post('files', '');
|
||||
$address = $request->post('address', '');
|
||||
$releaseType = $request->post('releaseType', '');
|
||||
// 验证内容
|
||||
if (empty($body)) {
|
||||
return $this->fail('什么内容都木有啊');
|
||||
}
|
||||
|
||||
|
||||
// 处理图片列表
|
||||
$files_array = [];
|
||||
if (!empty($files)) {
|
||||
if (is_string($files)) {
|
||||
$files_array = json_decode($files, true);
|
||||
} elseif (is_array($files)) {
|
||||
$files_array = $files;
|
||||
}
|
||||
|
||||
if (!is_array($files_array)) {
|
||||
return $this->fail('图片列表格式错误');
|
||||
}
|
||||
|
||||
// 限制图片数量
|
||||
if (count($files_array) > 9) {
|
||||
return $this->fail('最多只能上传9张图片');
|
||||
}
|
||||
}
|
||||
|
||||
// 创建朋友圈动态
|
||||
$circle = FriendCircleModel::create([
|
||||
'user_id' => $user->id,
|
||||
'releaseType' => $releaseType,
|
||||
'body' => $body,
|
||||
'files' => $files_array,
|
||||
'address' => $address,
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
return $this->success('发布成功', ['id' => $circle->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("发表评论")
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("body", type="string",require=true, desc="内容")
|
||||
* @Apidoc\Param("id", type="int",require=true, desc="朋友圈动态ID")
|
||||
* @Apidoc\Param("reply_user_id", type="int",require=false, desc="回复的用户ID(回复评论时使用)")
|
||||
*/
|
||||
function comment(Request $request): Response
|
||||
{
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
|
||||
$body = $request->post('body', '');
|
||||
$circle_id = (int)$request->post('id', 0);
|
||||
$reply_user_id = (int)$request->post('reply_user_id', 0);
|
||||
|
||||
if (empty($body)) {
|
||||
return $this->fail('评论内容不能为空');
|
||||
}
|
||||
|
||||
if ($circle_id <= 0) {
|
||||
return $this->fail('朋友圈动态ID错误');
|
||||
}
|
||||
|
||||
// 检查朋友圈动态是否存在
|
||||
$circle = FriendCircleModel::where('id', $circle_id)
|
||||
->where('status', 1)
|
||||
->find();
|
||||
|
||||
if (!$circle) {
|
||||
return $this->fail('朋友圈动态不存在');
|
||||
}
|
||||
|
||||
// 如果回复评论,检查被回复的用户是否存在
|
||||
if ($reply_user_id > 0) {
|
||||
$reply_user = UserModel::where('id', $reply_user_id)->find();
|
||||
if (!$reply_user) {
|
||||
return $this->fail('被回复的用户不存在');
|
||||
}
|
||||
}
|
||||
|
||||
// 创建评论
|
||||
$comment = FriendCircleCommentModel::create([
|
||||
'circle_id' => $circle_id,
|
||||
'user_id' => $user->id,
|
||||
'reply_user_id' => $reply_user_id,
|
||||
'body' => $body,
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
// 更新朋友圈评论数
|
||||
$circle->comment_count = FriendCircleCommentModel::where('circle_id', $circle_id)
|
||||
->where('status', 1)
|
||||
->count();
|
||||
$circle->save();
|
||||
|
||||
return $this->success('评论成功', ['id' => $comment->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("点赞")
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("id", type="int",require=true, desc="朋友圈动态ID")
|
||||
*/
|
||||
function like(Request $request): Response
|
||||
{
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
|
||||
$circle_id = (int)$request->post('id', 0);
|
||||
|
||||
if ($circle_id <= 0) {
|
||||
return $this->fail('朋友圈动态ID错误');
|
||||
}
|
||||
|
||||
// 检查朋友圈动态是否存在
|
||||
$circle = FriendCircleModel::where('id', $circle_id)
|
||||
->where('status', 1)
|
||||
->find();
|
||||
|
||||
if (!$circle) {
|
||||
return $this->fail('朋友圈动态不存在');
|
||||
}
|
||||
|
||||
// 检查是否已点赞
|
||||
$like = FriendCircleLikeModel::where('circle_id', $circle_id)
|
||||
->where('user_id', $user->id)
|
||||
->find();
|
||||
|
||||
if ($like) {
|
||||
// 取消点赞
|
||||
$like->delete();
|
||||
$circle->like_count = max(0, $circle->like_count - 1);
|
||||
$circle->save();
|
||||
return $this->success('取消点赞成功', ['is_liked' => false]);
|
||||
} else {
|
||||
// 添加点赞
|
||||
FriendCircleLikeModel::create([
|
||||
'circle_id' => $circle_id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
$circle->like_count = $circle->like_count + 1;
|
||||
$circle->save();
|
||||
return $this->success('点赞成功', ['is_liked' => true]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace app\api\controller;
|
||||
use app\model\User as UserModel;
|
||||
use app\model\UserRemark as UserRemarkModel;
|
||||
use app\model\GroupRemark as GroupRemarkModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use taoser\facade\Validate;
|
||||
use support\think\Db;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
/**
|
||||
* 好友相关
|
||||
*/
|
||||
class FriendController extends BaseController{
|
||||
/**
|
||||
* 不需要鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedAuth = ['*'];
|
||||
|
||||
/**
|
||||
* 无需登录及鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedLogin = [];
|
||||
/**
|
||||
* @Apidoc\Title("搜索用户")
|
||||
* @Apidoc\Method("GET")
|
||||
* @Apidoc\Param("nickname", type="string",require=true, desc="昵称")
|
||||
*/
|
||||
function search(Request $request): Response
|
||||
{
|
||||
$keyword = Input('keyword');
|
||||
$searchtype = Input('searchtype');
|
||||
if($searchtype =='id'){
|
||||
}else{
|
||||
|
||||
}
|
||||
return $this->success('ok');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ use Shopwwi\WebmanFilesystem\Facade\Storage;
|
||||
use app\model\User as UserModel;
|
||||
use app\model\Realname as RealnameModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use taoser\facade\Validate;
|
||||
use support\think\Db;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
@@ -34,14 +35,25 @@ class UserController extends BaseController{
|
||||
$data = \support\Jwt::getUser();
|
||||
if(Request()->method() == 'POST'){
|
||||
$nickname = input('nickname');
|
||||
//$username = input('username');
|
||||
//$password = input('password');
|
||||
if(!$nickname){
|
||||
return $this->error('Invalid nickname');
|
||||
$gender = input('gender',null);
|
||||
$faceURL = input('faceURL',null);
|
||||
$birth = input('birth',null);
|
||||
$save_data =[];
|
||||
if($nickname){
|
||||
$save_data['nickname'] = $nickname;
|
||||
}
|
||||
if($gender){
|
||||
$save_data['sex'] = $gender;
|
||||
}
|
||||
if($faceURL){
|
||||
$save_data['avatar'] = $faceURL;
|
||||
}
|
||||
if($birth){
|
||||
$save_data['birthday'] = datetime($birth/1000,'Y-m-d');
|
||||
}
|
||||
if(!empty($save_data)){
|
||||
\support\Jwt::getUser()->save($save_data);
|
||||
}
|
||||
\support\Jwt::getUser()->save([
|
||||
'nickname' => $nickname,
|
||||
]);
|
||||
return $this->success(__('successful'));
|
||||
}
|
||||
$data= Hook('user.profile',$data);
|
||||
@@ -137,7 +149,8 @@ class UserController extends BaseController{
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
function realname(Request $request){
|
||||
function realname(Request $request): Response
|
||||
{
|
||||
/**
|
||||
* @var UserModel $user
|
||||
*/
|
||||
@@ -178,4 +191,61 @@ class UserController extends BaseController{
|
||||
return $this->success('ok',$user);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* find
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("userIDs", type="array", require=true, desc="userIDs")
|
||||
*/
|
||||
function find(Request $request): Response
|
||||
{
|
||||
$userIDs = Input('userIDs');
|
||||
//$res = $request->IM->user->getUsersInfo($userIDs);
|
||||
$list = Db::name('user')->
|
||||
whereIn('id',$userIDs)
|
||||
->paginate(Input('limit',10));
|
||||
$list->each(function($user){
|
||||
unset($user['password']);
|
||||
unset($user['trade_password']);
|
||||
//unset($user['avatar']);
|
||||
unset($user['online']);
|
||||
unset($user['token']);
|
||||
unset($user['prev_time']);
|
||||
unset($user['loginfailure']);
|
||||
unset($user['successions']);
|
||||
unset($user['maxsuccessions']);
|
||||
unset($user['currency1']);
|
||||
unset($user['currency2']);
|
||||
unset($user['currency3']);
|
||||
unset($user['currency4']);
|
||||
unset($user['currency5']);
|
||||
unset($user['currency6']);
|
||||
unset($user['currency7']);
|
||||
unset($user['currency8']);
|
||||
unset($user['currency9']);
|
||||
return $user;
|
||||
//$user->hidden(['password']);
|
||||
});
|
||||
|
||||
return $this->success('ok',$list);
|
||||
}
|
||||
/**
|
||||
* search
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("keyword", type="string", require=true, desc="关键字")
|
||||
* @Apidoc\Param("searchtype", type="string", require=true, desc="搜索类型")
|
||||
*/
|
||||
function search(Request $request): Response
|
||||
{
|
||||
$keyword = Input('keyword');
|
||||
$searchtype = Input('searchtype');
|
||||
$fields = 'id,avatar,username,nickname,avatar,sex,email,mobile,birthday,bio';
|
||||
$model = Db::name('user')->field($fields)->where('status',1);
|
||||
if($searchtype =='id'){
|
||||
$model = $model->where('id',$keyword);
|
||||
}else{
|
||||
$model = $model->whereLike('username','%'.$keyword.'%');
|
||||
}
|
||||
$list = $model->paginate(Input('limit',10));
|
||||
return $this->success('ok',$list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user