AutoCancel.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/14
  6. * Time: 上午10:09
  7. */
  8. namespace app\frontend\modules\order\services;
  9. use app\common\models\Order;
  10. use app\common\models\order\OrderOperationLog;
  11. use app\frontend\modules\order\services\behavior\OrderClose;
  12. class AutoCancel
  13. {
  14. //自动关闭
  15. public static function autoCancel()
  16. {
  17. $orders = Order::waitPay()->get();
  18. if ($orders) {
  19. self::query($orders);
  20. }
  21. }
  22. private static function query($orders)
  23. {
  24. foreach ($orders as $order)
  25. {
  26. $close_class = new OrderClose($order);
  27. if ($close_class->closeable()) {
  28. $close_class->close();
  29. //插入操作日志记录
  30. $log = [
  31. 'order_id' => $order->id,
  32. 'type' => '7',
  33. 'before_operation_status' => '0',
  34. 'after_operation_status' => '-1',
  35. 'operator' => 'php',
  36. 'operation_time' => time()
  37. ];
  38. OrderOperationLog::insertOrderOperationLog($log);
  39. }
  40. }
  41. }
  42. }