UserCoupon.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\timer\model;
  13. use app\common\model\UserCoupon as UserCouponModel;
  14. /**
  15. * 用户优惠券模型
  16. * Class UserCoupon
  17. * @package app\timer\model
  18. */
  19. class UserCoupon extends UserCouponModel
  20. {
  21. // 是否允许全局查询store_id
  22. protected bool $isGlobalScopeStoreId = false;
  23. /**
  24. * 获取已过期的优惠券ID集
  25. * @param int $storeId
  26. * @return array
  27. */
  28. public function getExpiredCouponIds(int $storeId): array
  29. {
  30. $time = time();
  31. return $this->where('is_expire', '=', 0)
  32. ->where('is_use', '=', 0)
  33. ->where('end_time', '<=', time())
  34. ->where('store_id', '=', $storeId)
  35. ->column('user_coupon_id');
  36. }
  37. /**
  38. * 设置优惠券过期状态
  39. * @param array $couponIds
  40. * @return bool
  41. */
  42. public function setIsExpire(array $couponIds): bool
  43. {
  44. if (empty($couponIds)) {
  45. return false;
  46. }
  47. return $this->updateBase(['is_expire' => 1], [['user_coupon_id', 'in', $couponIds]]);
  48. }
  49. }