fix : user site
This commit is contained in:
66
app/Service/Api/User/UpdateProfileService.php
Normal file
66
app/Service/Api/User/UpdateProfileService.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\User;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Api\GetUserInfoTrait;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
|
||||
class UpdateProfileService extends BaseService
|
||||
{
|
||||
use GetUserInfoTrait;
|
||||
use OssTrait;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected mixed $userInfo;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$this->userInfo = $this->getUserInfo($this->userId);
|
||||
if (empty($this->userInfo)) throw new ErrException('用户异常');
|
||||
|
||||
if (!empty($this->request->input('avatar_id'))) $this->updateAvatar();
|
||||
|
||||
if (!empty($this->request->input('nickname'))) $this->updateNickname();
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function updateNickname(): void
|
||||
{
|
||||
$this->userInfo->nickname = $this->request->input('nickname');
|
||||
|
||||
if (!$this->userInfo->save()) throw new ErrException('更新昵称失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function updateAvatar(): void
|
||||
{
|
||||
$avatar_id = $this->request->input('avatar_id');
|
||||
|
||||
$this->updateOssObjects([$avatar_id]);
|
||||
if ($this->userInfo->avatar_id > 0) $this->updateOssObjectsDisable([$this->userInfo->avatar_id]);
|
||||
$this->userInfo->avatar_id = $this->request->input('avatar_id');
|
||||
|
||||
if (!$this->userInfo->save()) throw new ErrException('更新头像失败');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user