fix : site
This commit is contained in:
@@ -84,7 +84,7 @@ class SiteCache
|
||||
if ($info->status == SiteCode::SITE_DISABLE || $info->is_del == SiteCode::SITE_DEL) return;
|
||||
|
||||
$this->redis->hMset($siteKey, [
|
||||
'id' => $info->id,
|
||||
'site_id' => $info->id,
|
||||
'name' => $info->name,
|
||||
'kitchen_id' => $info->kitchen_id,
|
||||
'city_id' => $info->city_id,
|
||||
|
||||
@@ -83,6 +83,28 @@ class UserController extends AbstractController
|
||||
return (new SiteService)->del();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: 'site/set_default',methods: 'post')]
|
||||
#[Scene(scene: 'set_default_site')]
|
||||
public function setDefaultSite()
|
||||
{
|
||||
return (new SiteService)->setDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'site/get_default',methods: 'GET')]
|
||||
#[Scene(scene: 'get_default_site')]
|
||||
public function getDefaultSite()
|
||||
{
|
||||
return (new SiteService)->getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -117,6 +139,6 @@ class UserController extends AbstractController
|
||||
|
||||
public function updateProfile()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,16 @@ class UserSite extends Model
|
||||
* @param int $userId
|
||||
* @return BuildsQueries|Builder|\Hyperf\Database\Model\Model|object|null
|
||||
*/
|
||||
public function getUserNoDefaultIdByUserId(int $userId)
|
||||
public function getUserNoDefaultIdByUserId(int $userId): \Hyperf\Database\Model\Model|Builder|BuildsQueries|null
|
||||
{
|
||||
return $this->where('user_id', $userId)->where('is_default',SiteCode::USER_NO_DEFAULT)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @return BuildsQueries|Builder|\Hyperf\Database\Model\Model|object|null
|
||||
*/
|
||||
public function getUserDefaultInfoByUserId(int $userId)
|
||||
{
|
||||
return $this->where('user_id', $userId)->where('is_default',SiteCode::USER_NO_DEFAULT)->first();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class MyPageService extends BaseService
|
||||
|
||||
$adminInfo = $this->adminUserModel->getAdminInfoByBindUserId($this->userId);
|
||||
|
||||
return [
|
||||
$res = [
|
||||
'id' => $this->userId,
|
||||
'nickname' => $userInfo->nickname,
|
||||
'avatar' => $this->getOssObjectById($userInfo->avatar_id) ?? '',
|
||||
@@ -47,6 +47,8 @@ class MyPageService extends BaseService
|
||||
'invite_num' => 0,
|
||||
'role_id' => (!empty($adminInfo) && $adminInfo->role_id > 0) ? $adminInfo->role_id : 0,
|
||||
];
|
||||
|
||||
return $this->return->success('success', $res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,13 +50,13 @@ class SiteService extends BaseService
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$siteIds = $this->userSiteModel->where('user_id', $this->userId)->select(['id','is_default'])->get();
|
||||
$siteIds = $this->userSiteModel->where('user_id', $this->userId)->select(['id','site_id','is_default'])->get();
|
||||
|
||||
if (empty($siteIds)) $this->return->success('success', ['list' => []]);
|
||||
|
||||
$siteIds = $siteIds->toArray();
|
||||
foreach ($siteIds as &$siteId) {
|
||||
$siteId = array_merge($siteId,$this->siteCache->getSiteInfo($siteId['id']));
|
||||
$siteId['info'] = $this->siteCache->getSiteInfo($siteId['site_id']);
|
||||
}
|
||||
|
||||
return $this->return->success('success', ['list' => $siteIds]);
|
||||
@@ -119,4 +119,46 @@ class SiteService extends BaseService
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function setDefault(): array
|
||||
{
|
||||
$id = (int)$this->request->input('site_id');
|
||||
|
||||
$info = $this->userSiteModel->getInfoByUserIdAndId($this->userId,$id);
|
||||
|
||||
if ($info->is_default == SiteCode::USER_DEFAULT) throw new ErrException('该地址已经是默认地址');
|
||||
|
||||
$updateInfo = $this->userSiteModel->getUserDefaultInfoByUserId($this->userId);
|
||||
if (!empty($updateInfo)) {
|
||||
if ($updateInfo->id == $id) throw new ErrException('该地址已经是默认地址');
|
||||
|
||||
$updateInfo->is_default = SiteCode::USER_NO_DEFAULT;
|
||||
|
||||
if(!$updateInfo->save()) throw new ErrException('修改失败-修改联动数据失败');
|
||||
}
|
||||
|
||||
$info->is_default = SiteCode::USER_DEFAULT;
|
||||
if (!$info->save()) throw new ErrException('修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getDefault(): array
|
||||
{
|
||||
$info = $this->userSiteModel->getUserDefaultInfoByUserId($this->userId);
|
||||
if (empty($info)) return $this->return->success();
|
||||
|
||||
$info = $info->toArray();
|
||||
$info['info'] = $this->siteCache->getSiteInfo($info['site_id']);
|
||||
|
||||
return $this->return->success('success', $info);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user