我需要从当前日期减去30分钟,我尝试将其作为cronjob进行运行,以每5分钟运行一次cronjob项目,并且它执行时不需要
我使用的查询
use Carbon\Carbon;
$query1=mysqli_query($con,"select bookings.id as b_id,stocks.*
from bookings,stocks
where bookings.chasis_no=stocks.frame_no
and stocks.stock_status=3
and stocks.status=0
and bookings.status=0
and bookings.created_at <= Carbon::now()->subMiutes(10)")
or die("Query failed:".mysqli_error($con));
Cronjob
*/5 * * * * /usr/bin/php /var/www/html/amhonda/public/booking_cancel.php
答案 0 :(得分:0)
您没有从碳中获取日期值,您正在将函数调用硬编码到查询中。因此,例如,将carbon调用的输出连接到查询上
use Carbon\Carbon;
$query1=mysqli_query($con,"select bookings.id as b_id,stocks.*
from bookings,stocks
where bookings.chasis_no=stocks.frame_no
and stocks.stock_status=3
and stocks.status=0
and bookings.status=0
and bookings.created_at <= '" . Carbon::now()->subMinutes(10) ."'")
or die("Query failed:".mysqli_error($con));
还请注意,我在复写电话中修正了错字
答案 1 :(得分:0)
要从PHP当前时间减去30分钟,您可以执行以下操作:
echo date('Y-m-d H:i:s', strtotime('-30 minutes'));
答案 2 :(得分:0)
我试图在laravel应用程序中进行操作,但计划的工作不起作用,所以我尝试在laravel中使用php进行核心php操作,但通过laravel在cron中使用wget来解决
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Admin\Stock;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;
use Carbon\Carbon;
class CroneController extends Controller
{
public function booking_status_3in_hour()//for cron,executing after every one hour
{
$new = Carbon::now()->subHours(1)->toDateTimeString();
// return $new;
// $current_time = Carbon::now()->toDateTimeString();
$data=DB::table('bookings')
->select('bookings.id as b_id', 'stocks.*')
->join('stocks', 'stocks.frame_no', '=', 'bookings.chasis_no')
->where([['stocks.stock_status','=','3'],['stocks.status','=','0']])
->where([['bookings.status','0'],['bookings.created_at','<=',Carbon::now()->subMinutes(10)]])->get();
// return $data;
if($data)
{
foreach ($data as $value)
{
// return $value->id;
DB::table('stocks')
->where('id', $value->id)
->update([
'status'=>'-1']
);
DB::table('bookings')
->where('id', $value->b_id)
->update([
'status'=>'-1',
'cancel_remark'=>'Cancel due to no payment'
]
);
DB::table('stocks')->insert(
array(
'frame_no' => $value->frame_no,
'engine_no' => $value->engine_no,
'free_service_coupen_no' => $value->free_service_coupen_no,
'physical_status' => $value->physical_status,
'model_variant' => $value->model_variant,
'model_name' => $value->model_name,
'product_name' => $value->product_name,
'color' => $value->color,
'manufacturing_date' => $value->manufacturing_date,
'model_code' => $value->model_code,
'color_code' => $value->color_code,
'stock_status' => '0',
'transfer_remarks' => $value->transfer_remarks,
'transfer_time' => $value->transfer_time,
'transfer_type' => $value->transfer_type,
'stock_location' => $value->stock_location,
'created_user' => $value->created_user
)
);
}
// $this->booking canceled
}
}
}
cron
*/5 * * * * wget http://000.000.000.0:000/booking_status_3in_hour