quanwei
2025-11-03 ef5d748e3e3331bd20d4065c33e7867c2637d1db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
 
namespace app\job\model\plus\fans;
 
use app\common\model\plus\coupon\UserCoupon as UserCouponModel;
 
/**
 * 用户优惠券模型
 */
class UserCoupon extends UserCouponModel
{
    /**
     * 获取已过期的优惠券ID集
     */
    public function getExpiredCouponIds()
    {
        $time = time();
        return $this->where('is_expire', '=', 0)
            ->where('is_use', '=', 0)
            ->where(
                "IF ( `expire_type` = 20,
                    (`end_time` + 86400) < {$time},
                    ( `create_time` + (`expire_day` * 86400)) < {$time} )"
            )->column('user_coupon_id');
    }
 
    /**
     * 设置优惠券过期状态
     */
    public function setIsExpire($couponIds)
    {
        if (empty($couponIds)) {
            return false;
        }
        return $this->where('user_coupon_id', 'in', $couponIds)->save(['is_expire' => 1]);
    }
 
}