作者 jinglong
1 个管道 的构建 通过 耗费 25 秒

增加日检记录接口

... ... @@ -716,4 +716,17 @@ return array (
'version_number.require' => '版本号不能为空',
]
],
//日检记录
'ins_record' => [
'rule' => [
'date_time' => 'require|number',
'project_id' => 'require|number',
],
'msg' => [
'date_time.require' => '时间不能为空',
'date_time.number' => '时间必须为数字',
'project_id.require' => '项目id不能为空',
'project_id.number' => '项目id必须为数字',
]
],
);
\ No newline at end of file
... ...
... ... @@ -2324,4 +2324,22 @@ class CommonController extends RestBaseController
return $res;
}
//根据时间搜索获取日检记录id
public function getInsRecord($table,$data){
$time = date('Y-m-d',$data['date_time']);
$startTime = strtotime($time);
$endTime = $startTime+86400;
$res = Db::name($table)
->alias('i')
->join('project p','i.project_id = p.id','LEFT')
->where('i.project_id',$data['project_id'])
->where('i.create_time', '>=', $startTime)
->where('i.create_time', '<=', $endTime)
->field('i.id')
->group("i.project_id,DATE_FORMAT(FROM_UNIXTIME(i.create_time),'%Y-%m-%d')")
->order('i.id desc')
->find();
return $res;
}
}
... ...
... ... @@ -261,4 +261,34 @@ class InspectionController extends RestBaseController
}
}
/**
* @title 日检记录
* @description 接口说明
* @author 开发者
* @url /api/home/inspection/insRecord
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:date_time type:int require:1 default: other desc:时间
* @param name:project_id type:int require:1 default: other desc:项目id
*
* @return id:报表id
*/
public function insRecord(){
if($this->request->isGet()){
$data = $this->request->get();
$rule = config('site.ins_record');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$common = new CommonController();
$res = $common->getInsRecord('inspect',$data);
$this->success('成功',$res);
}else{
$this->error('请求方式错误');
}
}
}
... ...