上次提问的时间区间查询,控制文件里重新定了函数dateselect
模型文件源码
/**
*区间查询
*/
public function dateselect()
{
$where = [];
$search = "";
$params = $this->request->request();
//print_r($params['dates']);
$startTime = strtotime($params['dates']." 00:00:00");
$endTime = strtotime($params['dates']." 23:59:59");
//echo $starTime."~".$endTime; str_split()
$field = "yifei_wushui_yinzi.id,yifei_wushui_yinzi.fenlei_id,yifei_wushui_yinzi.value,yifei_wushui_yinzi.user_id,yifei_wushui_yinzi.status,yifei_wushui_yinzi.createtime,yifei_wushui_leibie.id,yifei_wushui_leibie.pid,yifei_wushui_leibie.name,yifei_wushui_leibie.min_point,yifei_wushui_leibie.max_point,yifei_wushui_leibie.yiju,yifei_wushui_leibie.status,equipment_staff.id,equipment_staff.user_id,equipment_staff.nickname,equipment_staff.department_id,equipment_staff.workno,equipment_staff.ispw,equipment_staff.position,equipment_staff.openid,equipment_staff.app_mode,equipment_staff.duty";
$where['yifei_wushui_yinzi.createtime'] = ['between', [$startTime, $endTime]];
$item = Db('yifei_wushui_yinzi')->alias('yifei_wushui_yinzi');
$item->join('yifei_wushui_leibie', 'yifei_wushui_leibie.id=yifei_wushui_yinzi.fenlei_id', 'left');
$item->join('equipment_staff', 'equipment_staff.user_id=yifei_wushui_yinzi.user_id', 'left');
$item->where($where)->where($this->buildwheres($search));
if (!empty($field)) {
$item->field($field);
}
$list = $item->select();
$this->success('数据列表', $list);
}
接口数据
{
"code": 1,
"msg": "数据列表",
"time": "1723814989",
"data": [
{
"id": 336,
"fenlei_id": 4,
"value": "{\"value1\":\"9.8854\"}",
"user_id": 337,
"status": "正常",
"createtime": 1723608399,
"pid": 1,
"name": "流量",
"min_point": 0,
"max_point": 0,
"yiju": null,
"nickname": "医废专员",
"department_id": 4,
"workno": "9939",
"ispw": 0,
"position": "医废专员",
"openid": "",
"app_mode": "0",
"duty": null
},
{
"id": 336,
"fenlei_id": 2,
"value": "{\"value1\":\"12.312\"}",
"user_id": 337,
"status": "正常",
"createtime": 1723608415,
"pid": 1,
"name": "氨氮",
"min_point": 0,
"max_point": 15,
"yiju": "GB18466-2005排放标准",
"nickname": "医废专员",
"department_id": 4,
"workno": "9939",
"ispw": 0,
"position": "医废专员",
"openid": "",
"app_mode": "0",
"duty": null
},
{
"id": 336,
"fenlei_id": 1,
"value": "{\"value1\":\"5.481\"}",
"user_id": 337,
"status": "正常",
"createtime": 1723608424,
"pid": 1,
"name": "COD",
"min_point": 0,
"max_point": 60,
"yiju": "GB18466-2005排放标准",
"nickname": "医废专员",
"department_id": 4,
"workno": "9939",
"ispw": 0,
"position": "医废专员",
"openid": "",
"app_mode": "0",
"duty": null
},
{
"id": 336,
"fenlei_id": 6,
"value": "{\"value1\":\"0\",\"value2\":\"0\",\"value3\":\"0\",\"value4\":\"0.0329\"}",
"user_id": 337,
"status": "正常",
"createtime": 1723608458,
"pid": 1,
"name": "总氯",
"min_point": 0,
"max_point": 0.5,
"yiju": "GB18466-2005排放标准",
"nickname": "医废专员",
"department_id": 4,
"workno": "9939",
"ispw": 0,
"position": "医废专员",
"openid": "",
"app_mode": "0",
"duty": null
}
]
}
怎么样才能把createtime时间戳格式化为2024-08-16 19:36:12 这种
value格式化为json格式呀
模型文件里加了
public function getValueAttr($value)
{
return json_decode($value,true);
}
public function getCreatetimeAttr($value)
{
return date('Y-m-d H:i:s', $value);
}
没有啥用
请登录后查看评论内容