fix : coupon date
This commit is contained in:
@@ -16,6 +16,8 @@ use App\Model\UserCoupon;
|
||||
use Exception;
|
||||
use Hyperf\Crontab\Annotation\Crontab;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
#[Crontab(rule: "* * * * *", name: "UserCouponTask", singleton: true , callback: "execute", memo: "每秒执行优惠券过期")]
|
||||
class UserCouponTask
|
||||
@@ -32,12 +34,17 @@ class UserCouponTask
|
||||
#[Inject]
|
||||
protected UserCoupon $userCouponModel;
|
||||
|
||||
public function execute()
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function execute(): void
|
||||
{
|
||||
try {
|
||||
$this->userCouponModel
|
||||
->whereTime('validity_end_time', '>', date('Y-m-d H:i:s'))
|
||||
->where('status', CouponCode::COUPON_STATUS_UNUSED)
|
||||
->where('validity_end_time', '<', date('Y-m-d H:i:s'))
|
||||
->update(['status' => CouponCode::COUPON_STATUS_EXPIRE]);
|
||||
}catch (Exception $e){
|
||||
$this->log->error(__CLASS__.$e->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user