v7.0.0 release
This commit is contained in:
1 parent
0e7fa04b03
commit
c4ea9a6cd1
3582 files changed
+626189
-160151
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace Modules\Sirsoft\Ecommerce\Repositories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Modules\Sirsoft\Ecommerce\Models\Cart;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\CartRepositoryInterface;
|
||||
|
||||
@@ -55,7 +56,7 @@ class CartRepository implements CartRepositoryInterface
|
||||
public function findByUserId(int $userId): Collection
|
||||
{
|
||||
return $this->model
|
||||
->with(['product.images', 'productOption'])
|
||||
->with(['product.images', 'product.additionalOptions.values', 'product.shippingPolicy.countrySettings', 'productOption'])
|
||||
->where('user_id', $userId)
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
@@ -67,7 +68,7 @@ class CartRepository implements CartRepositoryInterface
|
||||
public function findByCartKeyWithoutUser(string $cartKey): Collection
|
||||
{
|
||||
return $this->model
|
||||
->with(['product.images', 'productOption'])
|
||||
->with(['product.images', 'product.additionalOptions.values', 'product.shippingPolicy.countrySettings', 'productOption'])
|
||||
->where('cart_key', $cartKey)
|
||||
->whereNull('user_id')
|
||||
->orderBy('created_at', 'desc')
|
||||
@@ -97,13 +98,36 @@ class CartRepository implements CartRepositoryInterface
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function findAllByUserAndOption(int $userId, int $productOptionId): Collection
|
||||
{
|
||||
return $this->model
|
||||
->where('user_id', $userId)
|
||||
->where('product_option_id', $productOptionId)
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function findAllByCartKeyAndOption(string $cartKey, int $productOptionId): Collection
|
||||
{
|
||||
return $this->model
|
||||
->where('cart_key', $cartKey)
|
||||
->whereNull('user_id')
|
||||
->where('product_option_id', $productOptionId)
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function findByIds(array $ids): Collection
|
||||
{
|
||||
return $this->model
|
||||
->with(['product.images', 'productOption'])
|
||||
->with(['product.images', 'product.additionalOptions.values', 'product.shippingPolicy.countrySettings', 'productOption'])
|
||||
->whereIn('id', $ids)
|
||||
->get();
|
||||
}
|
||||
@@ -160,4 +184,58 @@ class CartRepository implements CartRepositoryInterface
|
||||
{
|
||||
return $this->model->where('cart_key', $cartKey)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function sumQuantityByProduct(int $productId, ?int $userId, ?string $cartKey, ?int $excludeCartId = null): int
|
||||
{
|
||||
$query = $this->model->where('product_id', $productId);
|
||||
|
||||
if ($userId !== null) {
|
||||
$query->where('user_id', $userId);
|
||||
} elseif ($cartKey !== null) {
|
||||
$query->where('cart_key', $cartKey)->whereNull('user_id');
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($excludeCartId !== null) {
|
||||
$query->where('id', '!=', $excludeCartId);
|
||||
}
|
||||
|
||||
return (int) $query->sum('quantity');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function pruneExpiredItems(int $days, ?int $limit = null): int
|
||||
{
|
||||
// 만료 비활성 정책 — days < 1 이면 한 건도 삭제하지 않음 (전체 삭제 사고 차단)
|
||||
if ($days < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$threshold = Carbon::now()->subDays($days);
|
||||
|
||||
// limit 미지정 시 단일 delete (정각/직전 보존 위해 '<' 비교)
|
||||
if ($limit === null) {
|
||||
return $this->model->where('updated_at', '<', $threshold)->delete();
|
||||
}
|
||||
|
||||
// limit 지정 시 대상 id 를 청크 조회 후 위임 삭제 (대량 삭제 안전)
|
||||
$ids = $this->model
|
||||
->where('updated_at', '<', $threshold)
|
||||
->orderBy('id')
|
||||
->limit($limit)
|
||||
->pluck('id')
|
||||
->all();
|
||||
|
||||
if (empty($ids)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $this->deleteByIds($ids);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user