1234567891011121314151617181920212223242526272829303132 |
- <?php
- use app\common\model\MobileOrder;
- use think\Db;
- use think\Log;
- use Workerman\Lib\Timer;
- use Workerman\Worker as WO;
- class MobileOrderExpired extends Com{
- public static function run()
- {
- $work=self::newWorker();
- $work->onWorkerStart=function ($conn){
- Timer::add(3,function (){
- $orders= MobileOrder::expired()->field('id')->select();
- foreach ($orders as $order){
- try {
- Db::startTrans();
- $order=MobileOrder::where('id',$order['id'])->lock(true)->find();
- $order->cancel();
- Db::commit();
- self::log("处理订单:{$order['id']},成功");
- }catch (\Exception $e){
- self::log("处理订单:{$order['id']},失败");
- Db::rollback();
- self::logError($e);
- }
- }
- });
- };
- }
- }
- MobileOrderExpired::run();
|