19
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
namespace app\api\controller;
|
||||
use app\model\User as UserModel;
|
||||
use app\model\Collection as CollectionModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use support\think\Db;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 收藏
|
||||
*/
|
||||
class CollectionController extends BaseController{
|
||||
/**
|
||||
* 不需要鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedAuth = ['*'];
|
||||
|
||||
/**
|
||||
* 无需登录及鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedLogin = [];
|
||||
/**
|
||||
* @Apidoc\Title("列表")
|
||||
* @Apidoc\Method("GET")
|
||||
* @Apidoc\Query("content_type", type="string", require=false, desc="内容类型 enum('text', 'image', 'file', 'video', 'link','audio')")
|
||||
* @Apidoc\Query("kw", type="string", require=false, desc="关键字")
|
||||
* @Apidoc\Query("page", type="int", require=true, desc="页码",default=1)
|
||||
* @Apidoc\Query("limit", type="int", require=true, desc="分页大小",default=10)
|
||||
*/
|
||||
function list(Request $request): Response
|
||||
{
|
||||
$user = \support\Jwt::getUser();
|
||||
$page = (int)Input('page', 1);
|
||||
$content_type = Input('content_type');
|
||||
$kw = Input('kw');
|
||||
$limit = (int)Input('limit', 10);
|
||||
$query = CollectionModel::where('status', 1)
|
||||
->whereIn('user_id',$user->id)
|
||||
->order('created_at', 'desc');
|
||||
if($content_type){
|
||||
$query->where('content_type',$content_type);
|
||||
}
|
||||
if($kw){
|
||||
$query->whereLike('content','%'.$kw.'%');
|
||||
}
|
||||
|
||||
$list = $query->paginate([
|
||||
'list_rows' => $limit,
|
||||
'page' => $page,
|
||||
]);
|
||||
return $this->success('ok', $list);
|
||||
}
|
||||
/**
|
||||
* 创建收藏
|
||||
* @Apidoc\Param("content_type", type="string",require=true, desc="内容类型 enum('text', 'image', 'file', 'video', 'link','audio')")
|
||||
* @Apidoc\Param("content", type="string",require=true, desc="json结构化收藏内容本体")
|
||||
* @Apidoc\Param("tags", type="string",require=true, desc="用户自定义标签,多个用逗号隔开,或者使用数组")
|
||||
* @Apidoc\Param("is_pinned", type="int",require=true, desc="是否置顶")
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
function create(Request $request): Response
|
||||
{
|
||||
$user = \support\Jwt::getUser();
|
||||
$content = $request->post('content');
|
||||
$content_type = $request->post('content_type', '');
|
||||
$tags = $request->post('tags', '');
|
||||
$is_pinned = $request->post('is_pinned', 0);
|
||||
// 验证内容
|
||||
if (empty($content_type)) {
|
||||
return $this->fail(__('The field %field% must be not empty. ',['field'=>'content_type']));
|
||||
}
|
||||
if (empty($content)) {
|
||||
return $this->fail(__('The field %field% must be not empty. ',['field'=>'content']));
|
||||
}
|
||||
if(is_array($content)) {
|
||||
$content = json_encode($content);
|
||||
}
|
||||
// 创建朋友圈动态
|
||||
$collection = CollectionModel::create([
|
||||
'user_id' => $user->id,
|
||||
'content_type' => $content_type,
|
||||
'content' => $content,
|
||||
'tags' => $tags,
|
||||
'is_pinned' => $is_pinned
|
||||
]);
|
||||
|
||||
return $this->success('发布成功', ['collection' => $collection]);
|
||||
}
|
||||
}
|
||||
@@ -151,7 +151,7 @@ class CommonController extends BaseController{
|
||||
'role_id' => 1,
|
||||
'group_id' => 0,
|
||||
'region' => '86',
|
||||
'nickname' => input('nickname'),
|
||||
'nickname' => input('nickname','用户_'.substr($username,7)),
|
||||
'avatar' => '/static/avatar/'.rand(0,17).'.png',
|
||||
];
|
||||
if ($invite_code) {
|
||||
|
||||
@@ -395,7 +395,7 @@ class FriendCircleController extends BaseController{
|
||||
$res = request()->IM->friend->getFriendList(\support\Encrypt::userIDencode($user_id));
|
||||
$friendsInfo = $res['friendsInfo'];
|
||||
foreach($friendsInfo as $k=>$v){
|
||||
array_push($result,$v['friendUser']['userID']);
|
||||
array_push($result,\support\Encrypt::userIDDecode($v['friendUser']['userID']));
|
||||
}
|
||||
cache($cache_key,$result,3600);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,450 @@
|
||||
<?php
|
||||
namespace app\api\controller;
|
||||
use app\model\User as UserModel;
|
||||
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 support\think\Db;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 新朋友圈
|
||||
*/
|
||||
class MomentsController extends BaseController{
|
||||
/**
|
||||
* 不需要鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedAuth = ['*'];
|
||||
|
||||
/**
|
||||
* 无需登录及鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedLogin = [];
|
||||
public $user_display_fields = 'id,userID,nickname,avatar';
|
||||
/**
|
||||
* 朋友圈设置
|
||||
* @param string $userID 用户userID,可选,不填就查询自己
|
||||
* @return void
|
||||
*/
|
||||
function info(Request $request): Response{
|
||||
$userID = Input('userID');
|
||||
if($userID){
|
||||
$user_id = \support\Encrypt::userIDDecode($userID);
|
||||
$json= [
|
||||
'top_unread_items' =>[],
|
||||
'unread_item_ids' =>[],
|
||||
'unread_count' =>0,
|
||||
'settings' => Db::name('user_extend')->where('user_id',$user_id)->field('moments_allow_view_days,moments_banner')->findOrEmpty()
|
||||
];
|
||||
return $this->success('ok',$json);
|
||||
}else{
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
$userID = $user->userID;
|
||||
$res = $this->newcount($request);
|
||||
$response = $res->rawBody();
|
||||
$json = json_decode($response,true);
|
||||
$json['data']['settings'] = Db::name('user_extend')->where('user_id',$user->id)->field('moments_allow_view_days,moments_banner')->findOrEmpty();
|
||||
|
||||
$top_unread_items = FriendCircleModel::whereIn('id',$json['data']['unread_item_ids'])
|
||||
->with(['user' => function($query) {
|
||||
$query->field($this->user_display_fields);
|
||||
}])
|
||||
->order('id', 'desc')
|
||||
->limit(0,3)
|
||||
->select();
|
||||
$json['data']['top_unread_items'] = $top_unread_items ?: [];
|
||||
$res->withBody(json_encode($json));
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @Apidoc\Title("列表")
|
||||
* @Apidoc\Method("GET")
|
||||
* @Apidoc\Query("userID", type="string", require=false, desc="用户userID,不传则获取所有")
|
||||
* @Apidoc\Query("page", type="int", require=true, desc="页码",default=1)
|
||||
* @Apidoc\Query("limit", type="int", require=true, desc="分页大小",default=10)
|
||||
*/
|
||||
function list(Request $request): Response
|
||||
{
|
||||
$current_user = \support\Jwt::getUser();
|
||||
$current_user_id = $current_user ? $current_user->id : 0;
|
||||
$page = (int)Input('page', 1);
|
||||
$limit = (int)Input('limit', 10);
|
||||
$userID = Input('userID');
|
||||
$query = FriendCircleModel::where('status', 1)
|
||||
->with(['user' => function($query) {
|
||||
$query->field($this->user_display_fields);
|
||||
}])
|
||||
->order('created_at', 'desc');
|
||||
if($userID){
|
||||
// 如果指定了用户ID,只获取该用户的朋友圈
|
||||
$user_id = \support\Encrypt::userIDDecode($userID);
|
||||
$query->where('user_id',$user_id);
|
||||
}else{
|
||||
$current_userID = \support\Encrypt::userIDencode($current_user_id);
|
||||
$query->whereIn('user_id',$this->getFriendUserIds($current_userID));
|
||||
}
|
||||
|
||||
$list = $query->paginate([
|
||||
'list_rows' => $limit,
|
||||
'page' => $page,
|
||||
]);
|
||||
if(!$userID){
|
||||
cache('circle_last_read_id_'.$current_user_id,$list[0]['id']);
|
||||
}
|
||||
|
||||
|
||||
// 处理每条朋友圈数据
|
||||
$items = $list->items();
|
||||
$list->each(function($item) use ($current_user_id){
|
||||
// 获取点赞列表
|
||||
$likes = Db::name('friend_circle_like')->alias('f')
|
||||
->join('user u','u.id=f.user_id')
|
||||
->where('f.circle_id', $item->id)
|
||||
->field('f.*,u.userID,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 = 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)
|
||||
->with(['user' => function($query) {
|
||||
$query->field($this->user_display_fields);
|
||||
}, 'replyUser' => function($query) {
|
||||
$query->field($this->user_display_fields);
|
||||
}])
|
||||
->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->avatar = cdnurl($like->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('请先登录');
|
||||
}
|
||||
$user_id = $user->id;
|
||||
$circle_last_read_id = cache('circle_last_read_id_'.$user_id) ?: 0;
|
||||
$userID = \support\Encrypt::userIDencode($user_id);
|
||||
// 统计从上次查看时间到现在新增的朋友圈数量
|
||||
$unread_item_ids = FriendCircleModel::where('status', 1)
|
||||
->whereIn('user_id',$this->getFriendUserIds($userID))
|
||||
->where('id', '>', $circle_last_read_id)
|
||||
->order('id', 'desc')
|
||||
->column('id');
|
||||
|
||||
|
||||
return $this->success('ok', [
|
||||
'unread_count' => count($unread_item_ids),
|
||||
'unread_item_ids'=>$unread_item_ids
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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,'data' => $circle]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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_userID", type="string",require=false, desc="回复的用户userID(回复评论时使用)")
|
||||
*/
|
||||
function comment(Request $request): Response
|
||||
{
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
|
||||
$body = $request->post('body', '');
|
||||
$circle_id = (int)$request->post('id');
|
||||
$reply_userID = (int)$request->post('reply_userID');
|
||||
|
||||
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('朋友圈动态不存在');
|
||||
}
|
||||
|
||||
// 如果回复评论,检查被回复的用户是否存在
|
||||
$reply_user_id = 0;
|
||||
if ($reply_userID ) {
|
||||
$reply_user_id = \support\Encrypt::userIDDecode($reply_userID);
|
||||
}
|
||||
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();
|
||||
$comment->user = Db::name('user')->field($this->user_display_fields)->where('id',$comment->user_id)->find();
|
||||
$comment->replyUser=null;
|
||||
if($comment->reply_user_id){
|
||||
$comment->replyUser = Db::name('user')->field($this->user_display_fields)->where('id',$comment->reply_user_id)->find();
|
||||
}
|
||||
return $this->success('评论成功', $comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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]);
|
||||
}
|
||||
}
|
||||
protected function getFriendUserIds($userID):array{
|
||||
if (!$userID) {
|
||||
return [];
|
||||
}
|
||||
$cache_key = 'friend_id_list_'.$userID;
|
||||
$result = cache($cache_key) ?: [];
|
||||
if(count($result) === 0){
|
||||
$res = request()->IM->friend->getFriendList($userID);
|
||||
$friendsInfo = $res['friendsInfo'];
|
||||
foreach($friendsInfo as $k=>$v){
|
||||
array_push($result,\support\Encrypt::userIDDecode($v['friendUser']['userID']));
|
||||
}
|
||||
cache($cache_key,$result,3600);
|
||||
}
|
||||
$result[] = \support\Encrypt::userIDDecode($userID);
|
||||
return $result;
|
||||
}
|
||||
function delete(Request $request): Response{
|
||||
$id = $request->post('id');
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
if($id){
|
||||
FriendCircleModel::where('id',$id)->where('user_id',$user->id)->delete();
|
||||
}
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
/**
|
||||
* 设置朋友圈背景
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
function upload_bg(Request $request){
|
||||
return $this->setBanner($request);
|
||||
}
|
||||
/**
|
||||
* 设置朋友圈背景
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
function setBanner(Request $request){
|
||||
try {
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
$res = $this->_upload($request);
|
||||
if(is_string($res)){
|
||||
return $this->fail( $res);
|
||||
}
|
||||
|
||||
Db::name('user_extend')->where('user_id',$user->id)->save([
|
||||
'moments_banner' => $res[0]['file_name'],
|
||||
]);
|
||||
return $this->success(__('successful'),[
|
||||
'url'=>$res[0]['file_name']
|
||||
]);
|
||||
}catch (\Exception $e){
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,21 +31,23 @@ class TeamController extends BaseController{
|
||||
$user = \support\Jwt::getUserinfo();
|
||||
$user_id = $user['id'];
|
||||
$user= Hook('user.profile',$user);
|
||||
$team_ids = UserTeamModel::where('ancestor_id',$user_id)->where('depth','>',0)->column('descendant_id');
|
||||
//$team_ids = UserTeamModel::where('ancestor_id',$user_id)->where('depth','>',0)->column('descendant_id');
|
||||
|
||||
$result=[
|
||||
'total_count' => count($team_ids),//团队总人数
|
||||
'direct_total' => cache('team_direct_total_'.$user_id)??0,//直属团队人数
|
||||
'recharge_total' => cache('team_recharge_total_'.$user_id)??0,
|
||||
'withdrawl_total' => cache('team_withdrawl_total_'.$user_id)??0,
|
||||
'income_total' => cache('team_income_total_'.$user_id)??0,
|
||||
'today_income_total' => cache('user_today_income_total_'.$user_id)??0,
|
||||
'promotion_income_total' => cache('user_promotion_income_total_'.$user_id)??0,
|
||||
'consume_total' => Db::name('user_extend')->where('user_id',$user_id)->value('sales'),//cache('team_consume_total_'.$user_id)??0,//团队总业绩
|
||||
'user_sales_reward' => cache('user_sales_reward_'.$user_id)??0,//销售奖
|
||||
'user_output_reward' => cache('user_output_reward_'.$user_id)??0,//产值奖
|
||||
'user_withdrawl_reward' => cache('user_withdrawl_reward'.$user_id)??0,//提现奖
|
||||
'user' => $user[0],
|
||||
'level' => $user['level'],
|
||||
'total_count' => cache_get('team_user_count_'.$user_id),//团队总人数
|
||||
'direct_total' => cache_get('team_direct_total_'.$user_id),//直属团队人数
|
||||
'vip_total' => cache_get('team_vip_total_'.$user_id),//旗下会员总数
|
||||
// 'recharge_total' => cache('team_recharge_total_'.$user_id)??0,
|
||||
// 'withdrawl_total' => cache('team_withdrawl_total_'.$user_id)??0,
|
||||
// 'income_total' => cache('team_income_total_'.$user_id)??0,
|
||||
// 'today_income_total' => cache('user_today_income_total_'.$user_id)??0,
|
||||
// 'promotion_income_total' => cache('user_promotion_income_total_'.$user_id)??0,
|
||||
// 'consume_total' => cache('team_consume_total_'.$user_id)??0,//团队总业绩
|
||||
// 'user_sales_reward' => cache('user_sales_reward_'.$user_id)??0,//销售奖
|
||||
// 'user_output_reward' => cache('user_output_reward_'.$user_id)??0,//产值奖
|
||||
// 'user_withdrawl_reward' => cache('user_withdrawl_reward'.$user_id)??0,//提现奖
|
||||
'user' => $user[0],
|
||||
|
||||
];
|
||||
return $this->success(__('successful'),$result);
|
||||
@@ -120,7 +122,7 @@ class TeamController extends BaseController{
|
||||
->join('user_extend ue', 'u.id = ue.user_id')
|
||||
->where('u.parent_id', $user['id'])
|
||||
//->where('ue.active', 1)
|
||||
->field('u.id,u.userID, u.username,u.money,u.score,u.role_id, u.group,u.avatar, u.created_at')
|
||||
->field('u.id,u.userID, u.username,u.nickname,u.money,u.score,u.role_id,u.avatar, u.created_at')
|
||||
->order('u.created_at desc');
|
||||
if($kw){
|
||||
$model = $model->whereLike("u.username",'%'.$kw.'%');
|
||||
@@ -139,33 +141,22 @@ class TeamController extends BaseController{
|
||||
}else{
|
||||
$result = $model->paginate($limit);
|
||||
}
|
||||
$role_arr = [
|
||||
'0' => __('普通用户'),
|
||||
'1' => __('V1'),
|
||||
'2' => __('V2'),
|
||||
'3' => __('V3'),
|
||||
'4' => __('V4'),
|
||||
'5' => __('V5'),
|
||||
];
|
||||
$result = $result->toArray();
|
||||
foreach($result['data'] as $k=>$item){
|
||||
$result['data'][$k]['avatar'] = cdnurl($item['avatar'] ?: '/storage/avatar/default.png');
|
||||
$result['data'][$k]['recharge_total'] = cache('user_recharge_total_'.$item['id'])??0;
|
||||
$result['data'][$k]['withdrawl_total'] = cache('user_withdrawl_total_'.$item['id'])??0;
|
||||
$result['data'][$k]['withdrawl_reward'] = cache('user_withdrawl_reward_'.$item['id'])??0;
|
||||
$result['data'][$k]['income_total'] = cache('user_income_total_'.$item['id'])??0;
|
||||
$result['data'][$k]['consume_total'] = cache('user_consume_total_'.$item['id'])??0;
|
||||
$result['data'][$k]['play_count'] = cache('user_play_count_'.$item['id'])??0;
|
||||
//$result['data'][$k]['recharge_total'] = cache('user_recharge_total_'.$item['id'])??0;
|
||||
//$result['data'][$k]['withdrawl_total'] = cache('user_withdrawl_total_'.$item['id'])??0;
|
||||
//$result['data'][$k]['withdrawl_reward'] = cache('user_withdrawl_reward_'.$item['id'])??0;
|
||||
//$result['data'][$k]['income_total'] = cache('user_income_total_'.$item['id'])??0;
|
||||
//$result['data'][$k]['consume_total'] = cache('user_consume_total_'.$item['id'])??0;
|
||||
//$result['data'][$k]['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
|
||||
$result['data'][$k]['total_count'] = UserTeamModel::where('ancestor_id',$item['id'])->where('status',1)->where('depth','>',0)->count('descendant_id');
|
||||
$result['data'][$k]['direct_total'] = cache('team_direct_total_'.$item['id'])??0;
|
||||
$result['data'][$k]['role'] = isset($role_arr[$item['role_id']]) ? $role_arr[$item['role_id']] : __('普通用户');
|
||||
//$result['data'][$k]['questionnaire_count'] = WorkRecordModel::where('user_id',$item['id'])->count('id');
|
||||
//return $item;
|
||||
}
|
||||
return $this->success(__('successful'),$result);
|
||||
}
|
||||
/**
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
* @Apidoc\Title("改变用户等级")
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("id", type="string",require=false, desc="ID")
|
||||
|
||||
@@ -113,6 +113,11 @@ class ThaliController extends BaseController{
|
||||
if($quantity == 12){
|
||||
$price = $thali->year_price;
|
||||
}
|
||||
//新开通
|
||||
$isNew=false;
|
||||
if(is_null($user->role_id)){
|
||||
$isNew = true;
|
||||
}
|
||||
//升级
|
||||
$isUpgrade=true;
|
||||
//续费
|
||||
@@ -145,14 +150,15 @@ class ThaliController extends BaseController{
|
||||
\app\model\User::score($user->id,-$amount,\app\enum\BalanceType::PURCHASE_ROLE,json_encode(['role_id'=>$role_id,'quantity'=>$quantity,'role_name'=>$thali->title]));
|
||||
|
||||
cache('user_rights_'.$user->id,null);
|
||||
//Hook('user.roleup', $user);
|
||||
// $data = [
|
||||
// 'role_id' => $role_id,
|
||||
// 'user_id' => $user->id,
|
||||
// 'parent_id' => $user->parent_id,
|
||||
// 'amount' => $amount,
|
||||
// ];
|
||||
// Hook('role.buy', $data);
|
||||
if($isNew){
|
||||
Hook('user.role_up', $user);
|
||||
}
|
||||
$data = [
|
||||
'role_id' => $role_id,
|
||||
'user_id' => $user->id,
|
||||
'amount' => $amount,
|
||||
];
|
||||
Hook('user.role_buy', $data);
|
||||
return $this->success(__('successful'),$user);
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,8 @@ class UserController extends BaseController{
|
||||
* @Apidoc\Desc("GET为获取用户信息,POST为修改数据")
|
||||
* @Apidoc\Param("nickname", type="string",require=true, desc="昵称")
|
||||
*/
|
||||
public function profile(){
|
||||
public function profile()
|
||||
{
|
||||
$data = \support\Jwt::getUser();
|
||||
if(Request()->method() == 'POST'){
|
||||
$nickname = input('nickname');
|
||||
@@ -60,6 +61,7 @@ class UserController extends BaseController{
|
||||
}
|
||||
return $this->success(__('successful'));
|
||||
}
|
||||
$data = \support\Jwt::getUserInfo($data);
|
||||
$data= Hook('user.profile',$data);
|
||||
return $this->success(__('successful'),$data[0]);
|
||||
}
|
||||
@@ -147,6 +149,25 @@ class UserController extends BaseController{
|
||||
\support\Jwt::getUser()->save($data);
|
||||
return $this->success(__('successful'),$data);
|
||||
}
|
||||
/**
|
||||
* 设置个人banner
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("file", type="File", require=true, desc="文件")
|
||||
*/
|
||||
public function setBanner(Request $request)
|
||||
{
|
||||
$user_id = \support\Jwt\JwtToken::getCurrentId();
|
||||
//单文件上传
|
||||
$res = $this->_upload($request);
|
||||
if(is_string($res)){
|
||||
return $this->fail( $res);
|
||||
}
|
||||
$data = [
|
||||
'profile_banner' => $res[0]['file_name'],
|
||||
];
|
||||
Db::name('user_extend')->where('user_id',$user_id)->save($data);
|
||||
return $this->success(__('successful'),$data);
|
||||
}
|
||||
function realname(Request $request): Response
|
||||
{
|
||||
/**
|
||||
@@ -201,30 +222,15 @@ class UserController extends BaseController{
|
||||
}
|
||||
//$userIDs = array_map('\support\Encrypt::userIDDecode',$ids);
|
||||
//$res = $request->IM->user->getUsersInfo($userIDs);
|
||||
$list = Db::name('user')->
|
||||
whereIn('userID',$ids)
|
||||
$list = Db::name('user')->alias('u')
|
||||
->leftJoin('user_extend ue','ue.user_id=u.id')
|
||||
->field('u.*,ue.profile_banner')
|
||||
->whereIn('u.userID',$ids)
|
||||
->paginate(Input('limit',10));
|
||||
$list->each(function($user){
|
||||
$user['id'] = $user['userID'];
|
||||
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;
|
||||
$data = \support\Jwt::getUserInfo($user);
|
||||
$data= Hook('user.profile',$data);
|
||||
return $data[0];
|
||||
//$user->hidden(['password']);
|
||||
});
|
||||
|
||||
@@ -240,9 +246,12 @@ class UserController extends BaseController{
|
||||
{
|
||||
$keyword = Input('keyword');
|
||||
$searchtype = Input('searchtype');
|
||||
$fields = 'userID,avatar,username,nickname,avatar,sex,email,mobile,birthday,bio';
|
||||
$model = Db::name('user')->field($fields)->where('status',1);
|
||||
$model = $model->where('userID',$keyword);
|
||||
$fields = 'u.userID,u.avatar,u.username,u.nickname,u.avatar,u.sex,u.email,u.mobile,u.birthday,u.bio,ue.profile_banner';
|
||||
$model = Db::name('user')->alias('u')
|
||||
->join('user_extend ue','ue.user_id=u.id')
|
||||
->field($fields)
|
||||
->where('status',1);
|
||||
$model = $model->where('u.userID',$keyword);
|
||||
// if($searchtype =='id'){
|
||||
// $model = $model->where('id',$keyword);
|
||||
// }else{
|
||||
|
||||
Reference in New Issue
Block a user