diff --git a/app/Constants/ConfigCode.php b/app/Constants/ConfigCode.php index 7016f0d..3868815 100644 --- a/app/Constants/ConfigCode.php +++ b/app/Constants/ConfigCode.php @@ -11,6 +11,7 @@ class ConfigCode const string ORDER_CANCEL_TIME_KEY = 'OrderCancelTime'; // 订单取消时间(下单后自动取消) const string SUNDRY_UNIT_PRICE = 'SundryUnitPrice'; // 附加费单价 (服务费) const string SUNDRY_PRICE_COMPUTE_TYPE = 'SundryPriceComputeType'; // 附加费计算方式 1 仅自选计算(默认值) 2 仅套餐计算 3 套餐+自选计算 + const string NUMBER_OF_USER_ADDRESS_POOLS = 'NumberOfUserAddressPools'; // 用户可以设置的送达地址的数量 /** * @var string CouponConfiguration|优惠券配置 @@ -28,6 +29,7 @@ class ConfigCode self::ORDER_CANCEL_TIME_KEY => 5, self::SUNDRY_UNIT_PRICE => '3', self::SUNDRY_PRICE_COMPUTE_TYPE => 1, + self::NUMBER_OF_USER_ADDRESS_POOLS => 10, //CouponConfiguration self::COUPONS_FOR_NEWCOMERS => '0', self::NEWBIE_COUPON_VALIDITY => '0', diff --git a/app/Controller/Api/UserController.php b/app/Controller/Api/UserController.php index 7123fd4..9825c60 100644 --- a/app/Controller/Api/UserController.php +++ b/app/Controller/Api/UserController.php @@ -40,7 +40,7 @@ class UserController extends AbstractController * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - #[RequestMapping(path: 'site/list',methods: 'post')] + #[RequestMapping(path: 'site/list',methods: 'GET')] #[Scene(scene: 'site_list')] public function userSiteList() { diff --git a/app/Model/UserSite.php b/app/Model/UserSite.php index a073fae..2626248 100644 --- a/app/Model/UserSite.php +++ b/app/Model/UserSite.php @@ -48,6 +48,16 @@ class UserSite extends Model return $this->find($id); } + /** + * @param int $userId + * @param int $siteId + * @return Collection + */ + public function getInfoByUserIdAndSiteId(int $userId, int $siteId): Collection + { + return $this->where('user_id', $userId)->where('site_id', $siteId)->first(); + } + /** * @param int $userId * @return array diff --git a/app/Service/Api/User/SiteService.php b/app/Service/Api/User/SiteService.php index 0097a0e..cd7fab2 100644 --- a/app/Service/Api/User/SiteService.php +++ b/app/Service/Api/User/SiteService.php @@ -11,7 +11,9 @@ declare(strict_types=1); namespace App\Service\Api\User; use App\Cache\Redis\Api\SiteCache; +use App\Cache\Redis\Common\ConfigCache; use App\Constants\Common\SiteCode; +use App\Constants\ConfigCode; use App\Exception\ErrException; use App\Model\UserSite; use App\Service\Api\BaseService; @@ -35,6 +37,12 @@ class SiteService extends BaseService #[Inject] protected SiteCache $siteCache; + /** + * @var ConfigCache + */ + #[Inject] + protected ConfigCache $configCache; + /** * @return array * @throws ContainerExceptionInterface @@ -67,6 +75,9 @@ class SiteService extends BaseService if (in_array($id, $siteIds)) throw new ErrException('已添加该地点'); + $poolNumber = $this->configCache->getConfigValue(ConfigCode::NUMBER_OF_USER_ADDRESS_POOLS); + if (count($siteIds) >= $poolNumber) throw new ErrException('已达到地址最大添加数量,请删除后再添加'); + $insertModel = new UserSite(); $insertModel->user_id = $this->userId; @@ -87,9 +98,9 @@ class SiteService extends BaseService */ public function del(): array { - $id = (int)$this->request->input('id'); + $id = (int)$this->request->input('site_id'); - $info = $this->userSiteModel->getInfoById($id); + $info = $this->userSiteModel->getInfoByUserIdAndSiteId($this->userId,$id); Db::transaction(function () use ($info) { if ($info->is_default == SiteCode::USER_DEFAULT) {