ver. 0.290: ShopCoupon + ShopOrder frontend migration to Domain + Controllers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -188,6 +188,73 @@ class CouponRepository
|
||||
return (bool)$this->db->delete('pp_shop_coupon', ['id' => $couponId]);
|
||||
}
|
||||
|
||||
public function findByName(string $name)
|
||||
{
|
||||
$name = trim($name);
|
||||
if ($name === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$coupon = $this->db->get('pp_shop_coupon', '*', ['name' => $name]);
|
||||
if (!is_array($coupon)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$coupon['id'] = (int)($coupon['id'] ?? 0);
|
||||
$coupon['status'] = (int)($coupon['status'] ?? 0);
|
||||
$coupon['used'] = (int)($coupon['used'] ?? 0);
|
||||
$coupon['one_time'] = (int)($coupon['one_time'] ?? 0);
|
||||
$coupon['type'] = (int)($coupon['type'] ?? 0);
|
||||
$coupon['include_discounted_product'] = (int)($coupon['include_discounted_product'] ?? 0);
|
||||
$coupon['used_count'] = (int)($coupon['used_count'] ?? 0);
|
||||
|
||||
return (object)$coupon;
|
||||
}
|
||||
|
||||
public function isAvailable($coupon)
|
||||
{
|
||||
if (!$coupon) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = is_object($coupon) ? ($coupon->id ?? 0) : ($coupon['id'] ?? 0);
|
||||
$status = is_object($coupon) ? ($coupon->status ?? 0) : ($coupon['status'] ?? 0);
|
||||
$used = is_object($coupon) ? ($coupon->used ?? 0) : ($coupon['used'] ?? 0);
|
||||
|
||||
if (!(int)$id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(int)$status) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !(int)$used;
|
||||
}
|
||||
|
||||
public function markAsUsed(int $couponId)
|
||||
{
|
||||
if ($couponId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->db->update('pp_shop_coupon', [
|
||||
'used' => 1,
|
||||
'date_used' => date('Y-m-d H:i:s'),
|
||||
], ['id' => $couponId]);
|
||||
}
|
||||
|
||||
public function incrementUsedCount(int $couponId)
|
||||
{
|
||||
if ($couponId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->db->update('pp_shop_coupon', [
|
||||
'used_count[+]' => 1,
|
||||
], ['id' => $couponId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user