1234567891011121314151617181920212223242526272829303132 |
- <?php
- use app\common\model\MobileOrder;
- use think\Db;
- use Workerman\Lib\Timer;
- class MobileOrderSettle extends Com{
- public static function run()
- {
- $work=self::newWorker();
- $work->onWorkerStart=function ($conn){
- Timer::add(30,function (){
- $orders= MobileOrder::filterWillOver()->limit(100)->select();
- foreach ($orders as $order){
- try {
- Db::startTrans();
- $order->makeOver();
- user_log('MobileOrderSettle',"结算订单{$order['id']}成功");
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- if($e->getMessage()=='该笔订单已结算成功'){
- user_log('MobileOrderSettle',["订单{$order['id']}结算失败",'当成功处理']);
- $order->makeOver(false);
- }
- user_log('MobileOrderSettle',["订单{$order['id']}结算失败",$e->getMessage(),$e->getFile(),$e->getLine()]);
- }
- }
- });
- };
- }
- }
- MobileOrderSettle::run();
|