UserCoupon.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\task\model;
  10. use app\common\model\UserCoupon as UserCouponModel;
  11. /**
  12. * 用户优惠券模型
  13. * Class UserCoupon
  14. * @package app\task\model
  15. */
  16. class UserCoupon extends UserCouponModel
  17. {
  18. /**
  19. * 获取已过期的优惠券ID集
  20. * @return array
  21. */
  22. public function getExpiredCouponIds()
  23. {
  24. $time = time();
  25. return $this->where('is_expire', '=', 0)
  26. ->where('is_use', '=', 0)
  27. ->where(
  28. "IF ( `expire_type` = 20,
  29. (`end_time` + 86400) < {$time},
  30. ( `create_time` + (`expire_day` * 86400)) < {$time} )"
  31. )->column('user_coupon_id');
  32. }
  33. /**
  34. * 设置优惠券过期状态
  35. * @param $couponIds
  36. * @return false|int
  37. */
  38. public function setIsExpire($couponIds)
  39. {
  40. if (empty($couponIds)) {
  41. return false;
  42. }
  43. return $this->save(['is_expire' => 1], ['user_coupon_id' => ['in', $couponIds]]);
  44. }
  45. }