如图:在filter选择日期TOD后,返回该日期所在的周一00:00:00到周日的23:59:59的值。
控制部分文件:
$grid->filter(function ($filter) {
$filter->disableIdFilter();
$filter->column(1/6,function ($filter){
$filter->equal('ordernation.tod','TOD')->date();
});
$filter->column(1/6, function ($filter) {
$filter->equal('exploitstyle.client_id','合同工厂')->select(PubFactory::getSelectOptions(['type'=>'0']));
});
$filter->column(1/6, function ($filter) {
$filter->equal('exploitstyle.brand_id','生产工厂')->select( PubFactory::getSelectOptions([]));
});
$filter->column(1/6, function ($filter) {
$filter->like('bulkstyle.bulk_no', '大货款号');
});
$filter->column(1/6, function ($filter) {
$filter->like('exploitstyle.exploit_no', '订单号');
});
});
$tod_date = isset(\request()['ordernation']['tod'])?\request()['ordernation']['tod']:null;//这步取日期很重要( ? : =〉如果 否则)
if ($tod_date){
$thisweek_b = date("Y-m-d H:i:s",mktime(00, 00 , 00,date("m",strtotime($tod_date)),date("d",strtotime($tod_date))-date("w",strtotime($tod_date))+1,date("Y",strtotime($tod_date)))); //获取本周一
$thisweek_e = date("Y-m-d H:i:s",mktime(23, 59 , 59,date("m",strtotime($tod_date)),date("d",strtotime($tod_date))-date("w",strtotime($tod_date))+7,date("Y",strtotime($tod_date)))); //获取下周一
}
else{
$thisweek_b = date("Y-m-d H:i:s",strtotime(Carbon::now()->subWeek(0)->startOfWeek()));//->timestamp;
$thisweek_e = date("Y-m-d H:i:s",strtotime(Carbon::now()->subWeek(0)->endOfWeek()));//->timestamp;
};
$grid->model()->whereHas('ordernation',function ($q) use($thisweek_b,$thisweek_e) {
//dump('0 :'.$thisweek_b.'--'.$thisweek_e);
$q->WhereBetween('tod', [$thisweek_b, $thisweek_e]);
});
//dump(\request()['ordernation']['tod']);
//dump(\request()->all());
$grid->model()->with(['exploitstyle','ordernation','pactPlant','plots']);
模型文件:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RyhBulkOrder extends Model
{
protected $table = 'ryh_bulk_order';
//合同工厂
public function pactPlant(){
return $this->belongsTo(PubFactory::class,'pact_plant','id');
}
//大货款式
public function bulkStyle(){
return $this->belongsTo(RyhBulkStyle::class,'bulk_id','id');
}
//开发款式
public function exploitstyle(){
return $this->belongsTo(RyhExploitStyle::class,'exploit_id','id');
}
//大货计划单挑
public function plots(){
return $this->belongsTo(RyhBulkPlot::class,'id','color_id');
}
//大货订单国家地区
public function ordernation(){
return $this->hasMany(RyhBulkOrderNation::class,'order_id','id');
}
}