|
@@ -4,20 +4,26 @@ use think\Db;
|
|
|
use think\Log;
|
|
|
use Workerman\Worker as WO;
|
|
|
|
|
|
-$work=new WO();
|
|
|
-$work->onWorkerStart=function ($conn){
|
|
|
- while (true){
|
|
|
- $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();
|
|
|
- }catch (\Exception $e){
|
|
|
- Log::error("关闭订单[$order->id]失败:{$e->getMessage()}");
|
|
|
+class MobileOrderExpired{
|
|
|
+ public static function run()
|
|
|
+ {
|
|
|
+ $work=new WO();
|
|
|
+ $work->onWorkerStart=function ($conn){
|
|
|
+ while (true){
|
|
|
+ $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();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Log::error("关闭订单[$order->id]失败:{$e->getMessage()}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sleep(3);
|
|
|
}
|
|
|
- }
|
|
|
- sleep(3);
|
|
|
+ };
|
|
|
}
|
|
|
-};
|
|
|
+}
|
|
|
+MobileOrderExpired::run();
|