mobile_order_settle.no 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. use app\common\model\MobileOrder;
  3. use think\Db;
  4. use Workerman\Lib\Timer;
  5. class MobileOrderSettle extends Com{
  6. public static function run()
  7. {
  8. $work=self::newWorker();
  9. $work->onWorkerStart=function ($conn){
  10. Timer::add(30,function (){
  11. $orders= MobileOrder::filterWillOver()->limit(100)->select();
  12. foreach ($orders as $order){
  13. try {
  14. Db::startTrans();
  15. $order->makeOver();
  16. user_log('MobileOrderSettle',"结算订单{$order['id']}成功");
  17. Db::commit();
  18. }catch (\Exception $e){
  19. Db::rollback();
  20. if($e->getMessage()=='该笔订单已结算成功'){
  21. user_log('MobileOrderSettle',["订单{$order['id']}结算失败",'当成功处理']);
  22. $order->makeOver(false);
  23. }
  24. user_log('MobileOrderSettle',["订单{$order['id']}结算失败",$e->getMessage(),$e->getFile(),$e->getLine()]);
  25. }
  26. }
  27. });
  28. };
  29. }
  30. }
  31. MobileOrderSettle::run();