baTable 如何筛选 date 范围

我的数据库字段不是datetime类型,是string

我的配置如下

{
    label: '年月',
    prop: 'ym',
    render: 'datetime',
    comSearchRender:'date',
    operator: 'RANGE',
    sortable: 'custom',
    width: 160,
    timeFormat: 'yyyymm',
}

得到请求参数是

search[0][field]=ym&search[0][val]=2024-06-02+00:00:00,2024-06-08+23:59:59&search[0][operator]=RANGE&search[0][render]=datetime

因为带了[render]=datetime最终条件是

[
    "ym",
    "BETWEEN",
    [
        1717257600,
        1717862399
    ]
]

我如何才能让条件变为下面这样

[
    "ym",
    "BETWEEN",
    [
        '202401',
        '202406'
    ]
]
3个回答默认排序 投票数排序
YANG001
YANG001
这家伙很懒,什么也没写~
2月前

方案一:从前台方面,在operator=RANGE的前提下,只要render不是datetime,就可以渲染为数字范围输入框,你就可以直接输入你想要的数字区间了
方案二:重写服务端对应控制器的index方法,在查询条件组装出来之后直接对条件进行修改即可

liuxiansen
liuxiansen
这家伙很懒,什么也没写~
2月前

把时间戳用date转一下. date('Ym', 1717257600)

liuxiansen
liuxiansen
这家伙很懒,什么也没写~
2月前
        list($where, $alias, $limit, $order) = $this->queryBuilder();

        foreach ($where as $key=>$value){
            $is_date_condition = $value[0] == 'goods_combo.sale_start_time';
            $is_date_condition = $is_date_condition || $value[0] == 'goods_combo.sale_stop_time';
            if( $is_date_condition == false ){ continue ; }
            $value[2][0] = date('Y-m-d H:i:s', $value[2][0]);
            $value[2][1] = date('Y-m-d H:i:s', $value[2][1]);
            $where[$key] = $value;
        }
        
        $res = $this->model
            ->withJoin($this->withJoinTable, $this->withJoinType)
            ->alias($alias)
            ->where($where)
            ->order($order)
            ->paginate($limit);
请先登录
0
1
0
3