39 lines
992 B
PHP
39 lines
992 B
PHP
<?php
|
|
|
|
namespace app\controller\api;
|
|
|
|
|
|
use app\model\Account;
|
|
use app\model\AccountLevel;
|
|
use app\repository\AccountRepository;
|
|
use think\response\Json;
|
|
|
|
class Level extends Base
|
|
{
|
|
protected $noNeedLogin = [
|
|
|
|
];
|
|
|
|
public function index(): Json
|
|
{
|
|
$userId = $this->request->user['user_id'] ?? 0;
|
|
$user = Account::findById($userId);
|
|
if (empty($user)) {
|
|
return json(['code' => 6001, 'msg' => '未登录']);
|
|
}
|
|
$level = AccountRepository::getInstance()->getUserLevel($user["coin_total"]);
|
|
$nextLevel = AccountRepository::getInstance()->getUserNextLevel($level["value"]);
|
|
|
|
if (!empty($nextLevel)) {
|
|
$nextLevel["disparity"] = ( $nextLevel["value"] - $user['coin_total']);
|
|
}
|
|
return $this->json(0, "ok", [
|
|
"level" => $level,
|
|
"nextLevel" => $nextLevel,
|
|
"nickname" => $user['nickname'],
|
|
"headimgurl" => $user['headimgurl'],
|
|
]);
|
|
}
|
|
|
|
|
|
} |