8
This commit is contained in:
@@ -57,6 +57,7 @@ class CommonController extends BaseController{
|
||||
$config['recharge_status_list'] = \app\enum\RechargeStatus::toArray();
|
||||
$config['withdrawl_status_list'] = \app\enum\WithdrawlStatus::toArray();
|
||||
$config['server_status_list'] = \app\enum\ServerStatus::toArray();
|
||||
//$config['getFriendList'] = $request->IM->friend->getFriendList('100006');
|
||||
return $this->success(__('successful'), $config);
|
||||
}
|
||||
|
||||
@@ -144,20 +145,28 @@ class CommonController extends BaseController{
|
||||
// }else{
|
||||
// $extends['trade_password'] = \plugin\admin\app\common\Util::passwordHash($trade_password);
|
||||
// }
|
||||
|
||||
//邀请码
|
||||
if ($invite_code)
|
||||
{
|
||||
//$invite_code = 'TEAJXLEE';
|
||||
$extends = [
|
||||
'role_id' => 1,
|
||||
'group_id' => 0,
|
||||
'region' => '86',
|
||||
'nickname' => input('nickname'),
|
||||
'avatar' => '/static/img/avatar.png',
|
||||
];
|
||||
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['group_id'] = 2;
|
||||
$extends['role_id'] = 1;
|
||||
$extends['parent_id'] = 0;
|
||||
}else{
|
||||
$inviter_user = UserModel::where('invite_code',$invite_code)->field('group,id')->find();
|
||||
$inviter_user = UserModel::where('invite_code',$invite_code)->field('group_id,id')->find();
|
||||
if(!$inviter_user){
|
||||
return $this->error(__('Invalid invite code'));
|
||||
}
|
||||
@@ -166,12 +175,6 @@ class CommonController extends BaseController{
|
||||
}else{
|
||||
//return $this->error(__('Invalid invite code'));
|
||||
}
|
||||
$extends = [
|
||||
'role_id' => 1,
|
||||
'group_id' => 0,
|
||||
'nickname' => input('nickname'),
|
||||
'avatar' => '/static/img/avatar.png',
|
||||
];
|
||||
// validate(\app\validate\User::class)
|
||||
// ->scene('edit')
|
||||
// ->check([
|
||||
@@ -209,26 +212,28 @@ class CommonController extends BaseController{
|
||||
$email = input('email');
|
||||
$password = input('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');
|
||||
return $this->fail(__('Invalid username or password'));
|
||||
}
|
||||
$username = $mobile;
|
||||
}else if($type == 'email'){
|
||||
if (!$email ) {
|
||||
return $this->fail(__('Invalid username or password').'2');
|
||||
return $this->fail(__('Invalid username or password'));
|
||||
}
|
||||
$username = $email;
|
||||
}else{
|
||||
if (!$username ) {
|
||||
return $this->fail(__('Invalid username or password').'3');
|
||||
return $this->fail(__('Invalid username or password'));
|
||||
}
|
||||
}
|
||||
try{
|
||||
$user = \support\Jwt::login($username, $password,$type);
|
||||
if ($password) {
|
||||
//return $this->fail(__('Invalid username or password'));
|
||||
$user = \support\Jwt::login($username, $password,$type);
|
||||
}else{
|
||||
$user = \support\Jwt::login($username, $password,$type,'code');
|
||||
}
|
||||
if($user === false){
|
||||
return $this->fail(\support\Jwt::getError());
|
||||
}
|
||||
@@ -421,7 +426,8 @@ class CommonController extends BaseController{
|
||||
$key = 'captcha_'.$event.'_'.$mobile;
|
||||
$list = cache($key);
|
||||
$list = $list ?:[];
|
||||
$expris = 60;
|
||||
$expris = 300;
|
||||
|
||||
if(cache('?exp_'.$key)){
|
||||
if(cache('exp_'.$key)+$expris > time()){
|
||||
return $this->fail(__('Only one verification code can be sent within %second% seconds',['%second%'=>$expris]));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace app\api\controller;
|
||||
use app\model\FriendCircle;
|
||||
use Shopwwi\WebmanFilesystem\FilesystemFactory;
|
||||
use Shopwwi\WebmanFilesystem\Facade\Storage;
|
||||
use app\model\User as UserModel;
|
||||
@@ -33,17 +34,24 @@ class FriendCircleController extends BaseController{
|
||||
* @return void
|
||||
*/
|
||||
function info(Request $request): Response{
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
$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' => '',
|
||||
];
|
||||
$top_unread_items = FriendCircleModel::whereIn('id',$json['data']['unread_item_ids'])
|
||||
->with(['user' => function($query) {
|
||||
$query->field('id,nickname,avatar');
|
||||
}])
|
||||
->order('id', 'desc')
|
||||
->limit(0,3)
|
||||
->select();
|
||||
$json['data']['top_unread_items'] = $top_unread_items ?: [];
|
||||
$res->withBody(json_encode($json));
|
||||
return $res;
|
||||
}
|
||||
@@ -56,11 +64,14 @@ class FriendCircleController extends BaseController{
|
||||
*/
|
||||
function list(Request $request): Response
|
||||
{
|
||||
$current_user = \support\Jwt::getUser();
|
||||
$current_user_id = $current_user ? $current_user->id : 0;
|
||||
$page = (int)$request->get('page', 1);
|
||||
$limit = (int)$request->get('limit', 10);
|
||||
$user_id = $request->get('user_id', 0);
|
||||
|
||||
$query = FriendCircleModel::where('status', 1)
|
||||
->whereIn('user_id',$this->getFriendUserIds($current_user_id))
|
||||
->with(['user' => function($query) {
|
||||
$query->field('id,nickname,avatar');
|
||||
}])
|
||||
@@ -75,30 +86,33 @@ class FriendCircleController extends BaseController{
|
||||
'list_rows' => $limit,
|
||||
'page' => $page,
|
||||
]);
|
||||
cache('circle_last_read_id',$list[0]['id']);
|
||||
|
||||
$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')
|
||||
$likes = Db::name('friend_circle')->alias('f')
|
||||
->join('user u','u.id=f.user_id')
|
||||
->where('f.id', $item->id)
|
||||
->field('f.*,u.avatar,u.nickname')
|
||||
->order('f.created_at', 'desc')
|
||||
->limit(20)
|
||||
->select();
|
||||
|
||||
$likes = $likes ? $likes->toArray() : [];
|
||||
// 检查当前用户是否已点赞
|
||||
$is_liked = false;
|
||||
if ($current_user_id > 0) {
|
||||
$is_liked = FriendCircleLikeModel::where('circle_id', $item->id)
|
||||
->where('user_id', $current_user_id)
|
||||
->count() > 0;
|
||||
$is_liked = null !== array_find($likes,function($item)use($current_user_id){
|
||||
return $item['user_id'] == $current_user_id;
|
||||
});
|
||||
// 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)
|
||||
@@ -137,8 +151,8 @@ class FriendCircleController extends BaseController{
|
||||
|
||||
// 处理点赞用户头像
|
||||
foreach ($item->likes as $like) {
|
||||
if ($like->user && $like->user->avatar) {
|
||||
$like->user->avatar = cdnurl($like->user->avatar);
|
||||
if ($like->user) {
|
||||
$like->avatar = cdnurl($like->avatar);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,24 +183,19 @@ class FriendCircleController extends BaseController{
|
||||
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);
|
||||
}
|
||||
|
||||
$circle_last_read_id = cache('circle_last_read_id') ?: 0;
|
||||
// 统计从上次查看时间到现在新增的朋友圈数量
|
||||
$count = FriendCircleModel::where('status', 1)
|
||||
->where('created_at', '>', $last_see)
|
||||
->count();
|
||||
$unread_item_ids = FriendCircleModel::where('status', 1)
|
||||
->whereIn('user_id',$this->getFriendUserIds($user->id))
|
||||
->where('id', '>', $circle_last_read_id)
|
||||
->order('id', 'desc')
|
||||
->column('id');
|
||||
|
||||
return $this->success('ok', ['count' => $count]);
|
||||
|
||||
return $this->success('ok', [
|
||||
'unread_count' => count($unread_item_ids),
|
||||
'unread_item_ids'=>$unread_item_ids
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -301,8 +310,12 @@ class FriendCircleController extends BaseController{
|
||||
->where('status', 1)
|
||||
->count();
|
||||
$circle->save();
|
||||
|
||||
return $this->success('评论成功', ['id' => $comment->id]);
|
||||
$comment->user = Db::name('user')->where('id',$comment->user_id)->find();
|
||||
$comment->replyUser=null;
|
||||
if($comment->reply_user_id){
|
||||
$comment->replyUser = Db::name('user')->where('id',$comment->reply_user_id)->find();
|
||||
}
|
||||
return $this->success('评论成功', $comment);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -354,4 +367,19 @@ class FriendCircleController extends BaseController{
|
||||
return $this->success('点赞成功', ['is_liked' => true]);
|
||||
}
|
||||
}
|
||||
protected function getFriendUserIds($user_id):array{
|
||||
if (!$user_id) {
|
||||
return [];
|
||||
}
|
||||
$result = cache('friend_id_list') ?: [];
|
||||
if(count($result) === 0){
|
||||
$res = request()->IM->friend->getFriendList($user_id.'');
|
||||
$friendsInfo = $res['friendsInfo'];
|
||||
foreach($friendsInfo as $k=>$v){
|
||||
array_push($result,$v['friendUser']['userID']);
|
||||
}
|
||||
cache('friend_id_list',$result,3600);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace app\api\controller;
|
||||
use app\model\User as UserModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use taoser\facade\Validate;
|
||||
use support\think\Db;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 消息控制器
|
||||
*/
|
||||
class MessageController extends BaseController{
|
||||
/**
|
||||
* 购买产品
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("gift_id", type="string", require=true, desc="产品ID")
|
||||
* @Apidoc\Param("quantity", type="int", require=true, desc="数量")
|
||||
* @Apidoc\Param("trade_password", type="string", require=true, desc="交易密码")
|
||||
*/
|
||||
function delete(Request $request):Response{
|
||||
$im = $request->IM;
|
||||
$data = $im->message->sendBusinessNotification('system',100007,[
|
||||
'contentType' => 101,
|
||||
'textElem' => [
|
||||
'content' => '欢迎使用4'.Config('site.name')
|
||||
]
|
||||
],'group');
|
||||
return $this->success('ok');
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ class UserController extends BaseController{
|
||||
if($nickname){
|
||||
$save_data['nickname'] = $nickname;
|
||||
}
|
||||
if($gender){
|
||||
if($gender!=null){
|
||||
$save_data['sex'] = $gender;
|
||||
}
|
||||
if($faceURL){
|
||||
|
||||
Reference in New Issue
Block a user