| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace App\Task;
- use App\Model\CoinsOrderModel;
- use App\Model\VipOrderModel;
- use Hyperf\Crontab\Annotation\Crontab;
- use Hyperf\Di\Annotation\Inject;
- /**
- * @Crontab(name="expiredOrder", rule="/1 * * * *", callback="execute", memo="过期订单处理")
- */
- class ExpiredOrder
- {
- use \Hyperf\Di\Aop\ProxyTrait;
- use \Hyperf\Di\Aop\PropertyHandlerTrait;
- function __construct()
- {
- $this->__handlePropertyHandler(__CLASS__);
- }
- /**
- * @Inject()
- * @var \Hyperf\Contract\StdoutLoggerInterface
- */
- private $logger;
- public function execute()
- {
- $expiredTime = date('Y-m-d H:i:s', time() - 400);
- // vip订单
- $vipOrder = VipOrderModel::query()->where('created_at', '<', $expiredTime)->where('status', '3')->get(['id']);
- // 金币订单
- $coinsOrder = CoinsOrderModel::query()->where('created_at', '<', $expiredTime)->where('status', '3')->get(['id']);
- $updataData = ['status' => 2];
- if ($vipOrder->isNotEmpty()) {
- foreach ($vipOrder as $vipVal) {
- VipOrderModel::query()->where('id', $vipVal->id)->update($updataData);
- }
- }
- if ($coinsOrder->isNotEmpty()) {
- foreach ($coinsOrder as $coinsVal) {
- CoinsOrderModel::query()->where('id', $coinsVal->id)->update($updataData);
- }
- }
- }
- }
|