fix : site
This commit is contained in:
@@ -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