修复分类锁的bug
This commit is contained in:
@@ -112,11 +112,16 @@ class GoodsService
|
||||
*
|
||||
* @param int $groupID 分类id
|
||||
* @param string $password 访问密码
|
||||
* @return bool
|
||||
* @return array
|
||||
*/
|
||||
public function verifyGroupPassword(int $groupID, string $password): bool
|
||||
public function verifyGroupPassword(int $groupID, string $password): array
|
||||
{
|
||||
$group = GoodsGroup::query()
|
||||
->with(['goods' => function($query) {
|
||||
$query->withCount(['carmis' => function($query) {
|
||||
$query->where('status', Carmis::STATUS_UNSOLD);
|
||||
}])->where('is_open', Goods::STATUS_OPEN)->orderBy('ord', 'DESC');
|
||||
}])
|
||||
->where('is_open', GoodsGroup::STATUS_OPEN)
|
||||
->where('id', $groupID)
|
||||
->first();
|
||||
@@ -127,7 +132,7 @@ class GoodsService
|
||||
|
||||
if (!$this->isGroupPasswordProtected($group)) {
|
||||
$this->grantGroupAccess($group->id);
|
||||
return true;
|
||||
return $this->formatGroupForResponse($group);
|
||||
}
|
||||
|
||||
if (!hash_equals((string) $group->group_pwd, (string) $password)) {
|
||||
@@ -135,7 +140,24 @@ class GoodsService
|
||||
}
|
||||
|
||||
$this->grantGroupAccess($group->id);
|
||||
return true;
|
||||
return $this->formatGroupForResponse($group);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化分类接口返回数据
|
||||
*
|
||||
* @param GoodsGroup $group 分类模型
|
||||
* @return array
|
||||
*/
|
||||
private function formatGroupForResponse(GoodsGroup $group): array
|
||||
{
|
||||
$data = $group->toArray();
|
||||
foreach ($data['goods'] as &$goods) {
|
||||
$goods['picture_url'] = picture_ulr($goods['picture']);
|
||||
}
|
||||
unset($goods);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,6 +174,22 @@ class GoodsService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消当前会话访问指定分类的授权
|
||||
*
|
||||
* @param int $groupID 分类id
|
||||
* @return void
|
||||
*/
|
||||
public function forgetGroupAccess(int $groupID): void
|
||||
{
|
||||
$groupIDs = session('dujiaoka_group_pwd_access', []);
|
||||
$groupIDs = array_values(array_filter($groupIDs, function ($id) use ($groupID) {
|
||||
return (int) $id !== $groupID;
|
||||
}));
|
||||
|
||||
session(['dujiaoka_group_pwd_access' => $groupIDs]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权当前会话访问分类
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user