UserCoupon.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 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\console\model;
  13. use app\common\model\UserCoupon as UserCouponModel;
  14. /**
  15. * 用户优惠券模型
  16. * Class UserCoupon
  17. * @package app\console\model
  18. */
  19. class UserCoupon extends UserCouponModel
  20. {
  21. // 是否允许全局查询store_id
  22. protected $isGlobalScopeStoreId = false;
  23. /**
  24. * 获取已过期的优惠券ID集
  25. * @param int $storeId
  26. * @return array
  27. */
  28. public function getExpiredCouponIds(int $storeId)
  29. {
  30. $time = time();
  31. return $this->where('is_expire', '=', 0)
  32. ->where('is_use', '=', 0)
  33. ->where("IF ( `expire_type` = 20,
  34. (`end_time` + 86400) < {$time},
  35. ( `create_time` + (`expire_day` * 86400)) < {$time} )")
  36. ->where('store_id', '=', $storeId)
  37. ->column('user_coupon_id');
  38. }
  39. /**
  40. * 设置优惠券过期状态
  41. * @param array $couponIds
  42. * @return false|int
  43. */
  44. public function setIsExpire(array $couponIds)
  45. {
  46. if (empty($couponIds)) {
  47. return false;
  48. }
  49. return $this->updateBase(['is_expire' => 1], [['user_coupon_id', 'in', $couponIds]]);
  50. }
  51. }