Files
heping-api/app/controller/Share.php
2022-09-19 16:31:40 +08:00

67 lines
2.1 KiB
PHP

<?php
namespace app\controller;
use think\facade\Db;
class Share
{
public function ranking(): \think\response\Json
{
$lastIndex = lastindex();
if($lastIndex == 0){
$where = "id > 0";
}else{
$where = "id < ".$lastIndex;
}
$result['lastIndex'] = 0;
$list = Db::name("app_users")->where($where)->order("share_count desc,id desc")->limit(env("PAGE_COUNT"))->select()->toArray();
foreach($list as $vo){
$result['lastIndex'] = $vo['id'];
$result['data'][] = [
"id"=>$vo['id'],
"nickname"=>$vo['nickname'],
"count"=>$vo['share_count'],
"avatar"=>$vo['avatar']
];
}
if (count($list) < env("PAGE_COUNT")) {
$result["lastIndex"] = 0;
}
return show(SUCCESS_MESSAGE.'!',SUCCESS_CODE,$result);
}
public function UserShareList(){
if(empty($GLOBALS['data']['data']['shiyou_id'])){
return show("请上传用户信息!", ERROR_CODE,[]);
}
$shiYou_id =$GLOBALS['data']['data']['shiyou_id'];
$lastIndex = lastindex();
if($lastIndex == 0){
$where = "id > 0";
}else{
$where = "id < ".$lastIndex;
}
$users = [];
$result['lastIndex'] = 0;
$list = Db::name("app_user_relation")->where("parent_id",$shiYou_id)->where($where)->select()->toArray();
if(empty($list)){
$users = getAllUsersMessage($list,"user_id","id,nickname,avatar");
}
foreach ($list as $vo) {
$result['lastIndex'] = $vo['id'];
$result["list"][] = [
"id"=>$vo['user_id'],
"ickname"=>$users[$vo['user_id']]['nickname'],
"avatar"=>$users[$vo['user_id']]['avatar'],
"data"=>date("Y-m-d",$vo['create_time'])
];
}
if (count($list) < env("PAGE_COUNT")) {
$result["lastIndex"] = 0;
}
return show(SUCCESS_MESSAGE.'!',SUCCESS_CODE,$result);
}
}