0
0

ShopOrder.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\cron;
  3. use think\Db;
  4. use yunwuxin\cron\Task;
  5. //商城取消未支付订单
  6. class ShopOrder extends Task
  7. {
  8. public function configure()
  9. {
  10. $this->everyMinute(); //每分钟执行一次
  11. }
  12. /**
  13. * 执行任务
  14. * @return mixed
  15. */
  16. protected function execute()
  17. {
  18. try{
  19. $list = Db::name('g_orders')
  20. ->where('status',0)
  21. ->select();
  22. foreach ($list as $k=>$v){
  23. if(strtotime($v['create_time']) < (time()-30*60)){
  24. Db::name('g_orders')
  25. ->where('id',$v['id'])
  26. ->update([
  27. 'status'=>3,
  28. 'cancel_time'=>getTime()
  29. ]);
  30. $goods = Db::name('g_order_goods')
  31. ->where('order_id',$v['id'])
  32. ->select();
  33. foreach ($goods as $k1=>$v1){
  34. Db::name('g_goods')
  35. ->where('id',$v1['goods_id'])
  36. ->setInc('stock',$v1['nums']);
  37. }
  38. }
  39. }
  40. }catch (\Exception $e){
  41. trace($e->getMessage());
  42. }
  43. }
  44. }