| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Goods;
- use App\Models\Order;
- use App\Models\OrderItem;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- class CheckOrderExpire extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'check:orderExpire';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '检查订单到期未支付';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- $date = date('Y-m-d H:i:s', time() - 900);//15分钟
- Order::where('order_status', 1)
- ->where('created_at', '<=', $date)
- ->chunkById(100,function ($list){
- foreach ($list as $item){
- DB::beginTransaction();
- try {
- //取消订单
- Order::where('id',$item->{'id'})->update(['order_status'=>3]);
- DB::commit();
- }catch (\Exception $e){
- DB::rollBack();
- }
- }
- });
- return true;
- }
- }
|