123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace app\cron;
- use think\Db;
- use yunwuxin\cron\Task;
- //商城取消未支付订单
- class ShopOrder extends Task
- {
- public function configure()
- {
- $this->everyMinute(); //每分钟执行一次
- }
- /**
- * 执行任务
- * @return mixed
- */
- protected function execute()
- {
- try{
- $list = Db::name('g_orders')
- ->where('status',0)
- ->select();
- foreach ($list as $k=>$v){
- if(strtotime($v['create_time']) < (time()-30*60)){
- Db::name('g_orders')
- ->where('id',$v['id'])
- ->update([
- 'status'=>3,
- 'cancel_time'=>getTime()
- ]);
- $goods = Db::name('g_order_goods')
- ->where('order_id',$v['id'])
- ->select();
- foreach ($goods as $k1=>$v1){
- Db::name('g_goods')
- ->where('id',$v1['goods_id'])
- ->setInc('stock',$v1['nums']);
- }
- }
- }
- }catch (\Exception $e){
- trace($e->getMessage());
- }
- }
- }
|