mobile_order_expired.php 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. use app\common\model\MobileOrder;
  3. use think\Db;
  4. use think\Log;
  5. use Workerman\Lib\Timer;
  6. use Workerman\Worker as WO;
  7. class MobileOrderExpired extends Com{
  8. public static function run()
  9. {
  10. $work=self::newWorker();
  11. $work->onWorkerStart=function ($conn){
  12. Timer::add(3,function (){
  13. $orders= MobileOrder::expired()->field('id')->select();
  14. foreach ($orders as $order){
  15. try {
  16. Db::startTrans();
  17. $order=MobileOrder::where('id',$order['id'])->lock(true)->find();
  18. $order->cancel();
  19. Db::commit();
  20. self::log("处理订单:{$order['id']},成功");
  21. }catch (\Exception $e){
  22. self::log("处理订单:{$order['id']},失败");
  23. Db::rollback();
  24. self::logError($e);
  25. }
  26. }
  27. });
  28. };
  29. }
  30. }
  31. MobileOrderExpired::run();