0, 'createtime' => ['lt',$canceltime], ]; Db::startTrans(); $list = Db::name('order')->where($where)->limit(20)->lock(true)->select(); if(empty($list)){ echo 'empty'; Db::rollback(); exit; } foreach($list as $key => $order){ $update = [ 'status' => 10, 'cancle_time' => time(), ]; //修改订单状态 $order_id = $order['id']; $order_rs = Db::name('order')->where('id',$order_id)->update($update); if($order_rs === false){ Db::rollback(); echo '保存失败'; exit; } //车票还回去 $order_road = Db::name('order_road')->where('order_id',$order_id)->lock(true)->select(); foreach($order_road as $key => $road){ $chufabanci = Db::name('product_chufabanci')->where('id',$road['chufabanci_id'])->lock(true)->find(); if(!empty($chufabanci)){ $update = [ 'ticket_remain' => $chufabanci['ticket_remain'] + $road['ticket_number'], ]; $rs_ticket = Db::name('product_chufabanci')->where('id',$road['chufabanci_id'])->update($update); if($rs_ticket === false){ Db::rollback(); echo '保存失败'; exit; } } } } Db::commit(); echo '取消成功'; exit; } /////////////////////////////////////////下面都是工具方法//////////////////////////////////////////////// }