OrderController.php 802 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace console\controllers;
  3. use common\models\GoodsUser;
  4. use common\models\Order;
  5. use yii\console\Controller;
  6. class OrderController extends Controller
  7. {
  8. /**
  9. * 取消过期订单
  10. */
  11. public function actionAutoCancelExpirationOrder()
  12. {
  13. $now = date("Y-m-d H:i:s");
  14. $goodsUserIds = [];
  15. $orderIds = [];
  16. $orders = Order::find()->where(['status' => 1])->andWhere(["<","expiration_time",$now])->all();
  17. foreach ($orders as $order){
  18. /** @var Order $order */
  19. $goodsUserIds[] = $order->id;
  20. $orderIds[] = $order->goods_users_id;
  21. }
  22. Order::updateAll(['status' => 3], ['id' => $orderIds]);
  23. GoodsUser::updateAll(['status' => 2], ['id' => $goodsUserIds]);
  24. echo "ok"."\n";
  25. }
  26. }