|
|
@@ -124,48 +124,44 @@ class User extends BaseController
|
|
|
*/
|
|
|
public function getInviterRanking(Request $request)
|
|
|
{
|
|
|
- $time = $request->param('time', time());
|
|
|
- $times = explode(" - ", $time);
|
|
|
- if (sizeof($times) == 2) {
|
|
|
- $count = (new UserModel)->where('parent_uid', $request->user['uid'])->where('regtime', '>=', $times[0])->where('regtime', '<', $times[1])->count();
|
|
|
- } else {
|
|
|
- $count = (new UserModel)->where('parent_uid', $request->user['uid'])->count();
|
|
|
- }
|
|
|
- $uids = (new UserModel)->where('parent_uid', $request->user['uid'])->column('uid');
|
|
|
- $InfoAudit = new InfoAudit();
|
|
|
- $list = [];
|
|
|
- if ($count == 0) {
|
|
|
- $list = (new UserModel)
|
|
|
- ->where('uid', '<>', $request->user['uid'])
|
|
|
- ->orderRaw('RAND()')
|
|
|
- ->field('uid, nickname, avatar')
|
|
|
- ->select()
|
|
|
- ->toArray();
|
|
|
- foreach ($list as &$v) {
|
|
|
- $v['count'] = (new UserModel)->where('parent_uid', $v['uid'])->count();
|
|
|
- $other = new \app\api\controller\Pub($this->app, $request);
|
|
|
- $res = $other->getShowTemplateItem($v['uid']);
|
|
|
- $v['template'] = $res['inviter_ranking'] ?? '';
|
|
|
- }
|
|
|
- } else {
|
|
|
- $list = (new UserModel)
|
|
|
- ->where('parent_uid', 'in', $uids)
|
|
|
- ->group('parent_uid')
|
|
|
- ->field('parent_uid AS uid, COUNT(*) AS count')
|
|
|
- ->order('count', 'DESC')
|
|
|
- ->select()
|
|
|
- ->toArray();
|
|
|
- foreach ($list as &$v) {
|
|
|
- $user = (new UserModel)->where('uid', $v['uid'])->field('nickname, avatar')->find();
|
|
|
- $v['nickname'] = $user['nickname'];
|
|
|
- $v['avatar'] = $user['avatar'];
|
|
|
- $other = new \app\api\controller\Pub($this->app, $request);
|
|
|
- $res = $other->getShowTemplateItem($v['uid']);
|
|
|
- $v['template'] = $res['inviter_ranking'] ?? '';
|
|
|
- }
|
|
|
+ $time = $request->param('time');
|
|
|
+ $times = $request->param('times');
|
|
|
+
|
|
|
+ $users = (new UserModel())
|
|
|
+ ->where('parent_uid', '<>', 0)
|
|
|
+ ->where('regtime', '>=', $time)
|
|
|
+ ->where('regtime', '<=', $times)
|
|
|
+ ->field('parent_uid as uid, count(*) as invite_count')
|
|
|
+ ->group('parent_uid')
|
|
|
+ ->order('invite_count', 'desc')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $rankList = [];
|
|
|
+ foreach ($users as $key => $value) {
|
|
|
+ $userInfo = (new UserModel)->where('uid', $value['uid'])->find();
|
|
|
+ $auth = (new InfoAudit)->where('uid', $value['uid'])->find();
|
|
|
+ $other = new \app\api\controller\Pub($this->app, $request);
|
|
|
+ $template = $other->getShowTemplateItem($value['uid']);
|
|
|
+ $user_work_type_title = (new UserWorkType)->where('id', $auth['user_work_type_id'])->find();
|
|
|
+ $rankList[] = [
|
|
|
+ 'rank' => $key + 1,
|
|
|
+ 'uid' => $value['uid'],
|
|
|
+ 'nickname' => $userInfo['nickname'],
|
|
|
+ 'avatar' => $userInfo['avatar'],
|
|
|
+ 'invite_count' => $value['invite_count'],
|
|
|
+ 'template' => $template['inviter_ranking'] ?? '',
|
|
|
+ 'is_type_audit' => $auth && $auth['status'] == 1 ? 1 : 0,
|
|
|
+ 'ancestral_place' => $auth ? $auth['ancestral_place'] : '',
|
|
|
+ 'auth_info' => $auth ? $auth->toArray() : [],
|
|
|
+ 'user_work_type_id' => $user_work_type_title['title'],
|
|
|
+ ];
|
|
|
}
|
|
|
- $auth = $request->user->auth;
|
|
|
- return json(['count' => $count, 'list' => $list, 'auth' => $auth]);
|
|
|
+
|
|
|
+ $rankList = array_values(array_filter($rankList, function ($item) {
|
|
|
+ return !empty($item['ancestral_place']);
|
|
|
+ }));
|
|
|
+
|
|
|
+ return app('json')->success($rankList);
|
|
|
}
|
|
|
|
|
|
|