选择日期,返回该日期所在的周一0点到周日的24点

38 篇文章 1 订阅
35 篇文章 2 订阅

如图:在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');
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值