作者 景龙
1 个管道 的构建 通过 耗费 30 秒

新增年检相关接口

... ... @@ -447,7 +447,7 @@ return array (
],
'data_type' => [
'rule' => [
'id' => 'require|number',
'id' => 'require|number',
'type' => 'require|number',
],
'msg' => [
... ... @@ -471,10 +471,16 @@ return array (
],
'add_spot' => [
'rule' => [
'test_id' =>'require|number',
'spot_name' => 'require',
'project_id' =>'require|number'
],
'msg' => [
'spot_name.require' => '年检点名称不能为空',
'test_id.require' => '检测id不能为空',
'test_id.number' => '检测id必须是数字',
'spot_name.require' => '巡检点名称不能为空',
'project_id.require' => '项目id不能为空',
'project_id.number' => '项目id必须是数字',
]
],
'comment' => [
... ... @@ -488,7 +494,7 @@ return array (
'id.number' => '列表id必须是数字',
'service_id.require' => '服务id不能为空',
'service_id.number' => '服务id必须是数字',
'comment.require' => '评论内容不能为空',
'comment.require' => '评论内容不能为空',
]
],
'subject_post' => [
... ... @@ -529,4 +535,32 @@ return array (
'images.array' => '拜访图片必须为数组',
]
],
'add_year_test' => [
'rule' => [
'test_time' => 'require|number',
'address' => 'require',
'remark' => 'require',
],
'msg' => [
'test_time.require' => '检测时间不能为空',
'test_time.number' => '检测时间必须为数字',
'address.require' => '检测地点不能为空',
'remark.require' => '检测备注不能为空',
]
],
'test_status' => [
'rule' => [
'spot_id' => 'require|number',
'status' => 'require|number',
// 'images' => 'require|array',
],
'msg' => [
'spot_id.require' => '检测点id不能为空',
'spot_id.number' => '检测点id必须为数字',
'status.require' => '检测状态不能为空',
'status.number' => '检测状态必须为数字',
'images.require' => '检测图片不能为空',
'images.array' => '检测图片必须为数组',
]
],
);
\ No newline at end of file
... ...
... ... @@ -423,6 +423,35 @@ class CommonController extends RestBaseController
return $res;
}
//根据检测id获取巡检列表
public function getSpotList($where){
$res = Db::name('spot')
->where($where)
->field('id,spot_name')
->select()
->toArray();
//查询检测已巡检的数据
foreach($res as &$value){
$status = $this->getYearsList($value['id'],'status');
if($status){
$value['status'] = $status['status'];
}else{
$value['status'] = 2;
}
}
return $res;
}
//根据检测点id获取检测列表
public function getYearsList($spot_id,$field){
$res = Db::name('years')
->where('spot_id',$spot_id)
->field($field)
->find();
return $res;
}
//获取巡检列表
public function getInsList($years = ''){
$identity = $this->user['identity'];
... ... @@ -815,6 +844,48 @@ class CommonController extends RestBaseController
return ceil($count/$limit);
}
//获取年检检测点列表
public function getTestList($page){
//获取登录人所在的项目
$limit = config('site.limit');
$user = $this->getUserIdentity();
$res = Db::name('test')
->where(['project_id'=>$user['project_id']])
->field('id,project_id,test_time,address,remark')
->page($page,$limit)
->order('id desc')
->select()
->toArray();
foreach($res as &$value){
$company_name = $this->getACompanyName($value['project_id']);
$value['company_name'] = $company_name;
}
return $res;
}
//查询年检检测点总页数
public function getTestPage(){
$user = $this->getUserIdentity();
$count = Db::name('test')
->where(['project_id'=>$user['project_id']])
->count();
$limit = config('site.limit');
return ceil($count/$limit);
}
//根据项目id获取甲方公司名称
public function getACompanyName($project_id){
//获取甲方id,乙方id
$company_name = '';
$project = $this->getProject(['id'=>$project_id],'id,a_cid,b_cid,name');
if($project){
//甲方公司
$a_company = $this->getCompany(['id'=>$project['a_cid']],'id,company_name');
$company_name = !empty($a_company['company_name'])?$a_company['company_name']:'';
}
return $company_name;
}
//获取改造列表
public function getReformList($page,$where){
//获取登录人所在的项目
... ...
... ... @@ -13,6 +13,7 @@ use think\Validate;
use cmf\controller\RestBaseController;
use app\portal\model\YearsModel;
use app\portal\model\SpotModel;
use app\portal\model\TestModel;
/**
* @title 年检
*/
... ... @@ -20,33 +21,39 @@ class YearsController extends RestBaseController
{
/**
* @title 添加年检点
* @title 添加检测
* @description 接口说明
* @author 开发者
* @url /api/home/years/addSpot
* @url /api/home/years/addYearTest
* @method POST
*
* @header name:token require:1 default: desc:header
* @param name:spot_name type:string require:1 default: other desc:年检点名称
*
* @return spot_id:年检点id
* @param name:test_time type:inter require:1 default: other desc:检测点时间
* @param name:address type:string require:1 default: other desc:检测点地点
* @param name:remark type:string require:1 default: other desc:检测点备注
*/
public function addSpot(){
if($this->request->post()){
public function addYearTest(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.add_spot');
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.add_year_test');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getUserIdentity();
$data['p_id'] = $user['project_id'];
$data['project_id'] = $user['project_id'];
$data['create_time'] = time();
$spotModel = new SpotModel();
$res = $spotModel->create($data);
$test = new TestModel();
$res = $test->create($data);
if($res){
$this->success('成功',['spot_id'=>$res->id]);
$this->success('成功');
}else{
$this->error('失败');
}
... ... @@ -56,124 +63,159 @@ class YearsController extends RestBaseController
}
/**
* @title 年检列表
* @title 检测列表
* @description 接口说明
* @author 开发者
* @url /api/home/years/insList
* @url /api/home/years/testList
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @return id:项目id
* @return project_name:项目名称
* @return point: @
* @point id:巡检点id spot_name:年检名称 status:年检状态(0:已检查,1:故障,2:未完成)
* @return is_finish: 未完成数量
* @param name:page type:inter require:1 default: other desc:分页页码
* @return data: @
* @data id:年检检测id project_id:项目id test_time:检测时间 address:检测地点 remark:检测备注 company_name:检测甲方公司
* @return page:当前页数
* @return total_page:总页数
*/
public function insList(){
public function testList(){
if($this->request->isGet()){
$page = $this->request->get('page');
$rule = config('site.pages');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page])) {
$this->error($validate->getError());
}
$common = new CommonController();
$arr = $common->getInsList(1);
$this->success('成功',$arr);
$res = $common->getTestList($page);
//查询总页数
$total_page = $common->getTestPage();
$this->success('成功',['data'=>$res,'page'=>intval($page),'total_page'=>$total_page]);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 添加年检页面
* @title 检测详情
* @description 接口说明
* @author 开发者
* @url /api/home/years/insAdd
* @url /api/home/years/testDetail
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:int require:1 default: other desc:年检点id
* @param name:id type:inter require:1 default: other desc:年检检测id
*
* @return spot_id:年检点id
* @return spot_name:年检点名称
* @return id:年检检测id
* @return project_id:项目id
* @return project_name:项目名称
* @return test_time:检测时间
* @return address:检测地点
* @return remark:检测备注
* @return company_name:检测甲方公司
* @return spot:年检点@
* @spot id:检测点id spot_name:检测点名称 status:检测点状态(0:正常,1:故障,2:未检测)
*/
public function insAdd(){
public function testDetail(){
if($this->request->isGet()){
$id = $this->request->get('id');
$rule = config('site.ins_add');
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
//查询年检名称
$arr = Db::name('spot')
->alias('po')
->join('project p','po.p_id = p.id','LEFT')
->where('po.id',$id)
->field('po.id spot_id,po.spot_name,p.id project_id,p.name project_name')
$res = Db::name('test')
->where('id',$id)
->field('id,project_id,test_time,address,remark')
->find();
$this->success('成功',$arr);
if($res){
$common = new CommonController();
$company_name = $common->getACompanyName($res['project_id']);
$res['company_name'] = $company_name;
//获取巡检点
$spot = $common->getSpotList(['test_id'=>$res['id'],'project_id'=>$res['project_id']]);
$res['spot'] = $spot;
}
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 添加年检提交
* @title 添加检测点
* @description 接口说明
* @author 开发者
* @url /api/home/years/insAddPost
* @url /api/home/years/addSpot
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:spot_id type:int require:1 default: other: desc:年检点id
* @param name:project_id type:int require:1 default: other: desc:项目id
* @param name:status type:int require:1 default: other desc:年检点状态(0:已检查,1:故障)
* @param name:create_time type:int require:1 default: other desc:年检时间
* @param name:images type:array require:1 default: other desc:年检图片(二维数组形式)
* @param name:test_id type:string require:1 default: other desc:检测id
* @param name:spot_name type:string require:1 default: other desc:检测点名称
* @param name:project_id type:string require:1 default: other desc:项目id
*/
public function insAddPost(){
if($this->request->isPost()){
public function addSpot(){
if($this->request->post()){
$data = $this->request->post();
$rule = config('site.years_post');
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.add_spot');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data['create_time'] = time();
$spotModel = new SpotModel();
$res = $spotModel->create($data);
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
$data['uid'] = $this->userId;
//获取甲方,乙方
$common = new CommonController();
//处理图片+时间格式,序列化存入数据库中
//绝对路径转相对路径
$data['images'] = $common->relationUrl($data['images']);
$party = $common->getUserIdentity();
/**
* @title 删除检测点
* @description 接口说明
* @author 开发者
* @url /api/home/years/deleteSpot
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:string require:1 default: other desc:检测点id
*/
public function deleteSpot(){
if($this->request->get()){
$id = $this->request->get('id');
$where = [
'project_id'=>$data['project_id'],
'spot_id'=>$data['spot_id'],
'party'=>$party['party']
];
//查询是否已添加巡检
$result = Db::name('years')
->where($where)
->whereTime('create_time','year')
->find();
if($result){
$this->error('您已提交过年检点信息!');
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$data['party'] = $party['party'];
$yearsModel = new YearsModel();
// $keys = ['images','file_time'];
// $images = $common->array_merge_more($keys, $data['images'], $data['file_time']);
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$res = $yearsModel->create($data);
$spotModel = new SpotModel();
$res = $spotModel->where('id',$id)->delete();
if($res){
$this->success('您的年检点信息添加成功!');
$this->success('成功');
}else{
$this->error('失败');
}
... ... @@ -183,26 +225,23 @@ class YearsController extends RestBaseController
}
/**
* @title 编辑年检页面
* @title 检测点详情
* @description 接口说明
* @author 开发者
* @url /api/home/years/insEdit
* @url /api/home/years/spotDetail
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:int require:1 default: other desc:年检点id
* @param name:id type:inter require:1 default: other desc:检测点id
*
* @return spot_id:年检点id
* @return spot_name:年检点名称
* @return project_id:项目id
* @return project_name:项目名称
* @return status:年检点状态(0:已检查,1:故障)
* @return images:年检图片@
* @return id:检测点id
* @return spot_name:检测点名称
* @return status:检测点状态(0:正常,1:故障,2:未检测)
* @return images:检测点图片@
* @images image_url:图片路径 file_time:图片时间
* @return create_time:年检时间
*/
public function insEdit(){
public function spotDetail(){
if($this->request->isGet()){
$id = $this->request->get('id');
$rule = config('site.ins_add');
... ... @@ -210,63 +249,114 @@ class YearsController extends RestBaseController
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getIdentity();
//查询年检名称
$res = Db::table('xf_spot')
->alias('po')
->join('xf_years','po.id = xf_years.spot_id','LEFT')
->join('xf_project p','po.p_id = p.id','LEFT')
->whereTime('xf_years.create_time','year')
->where(['xf_years.party'=>$user['party'],'po.id'=>$id])
->field('po.id spot_id,po.spot_name,p.id project_id,p.name project_name,xf_years.status,xf_years.images,xf_years.create_time')
//查询年检名称,状态
$res = Db::name('spot')
->where(['id'=>$id])
->field('id,test_id,spot_name')
->find();
//相对路径转绝对路径
if($res['images']){
$arr = [];
if($res){
$arr['id'] = $res['id'];
$arr['spot_name'] = $res['spot_name'];
$arr['status'] = 2;
$arr['images'] = [];
//查询检测时间
$common = new CommonController();
$res['images'] = $common->absolutionUrl($res['images']);
//根据检测时间查看是否检测巡检点
$years = $common->getYearsList($id,'status,images');
if($years){
$arr['status'] = $years['status'];
$arr['images'] = $common->absolutionUrl($years['images']);
}
}
$this->success('成功',$res);
$this->success('成功',$arr);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 编辑巡检提交
* @title 添加检测点状态
* @description 接口说明
* @author 开发者
* @url /api/home/years/insEditPost
* @url /api/home/years/addTestStatus
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:spot_id type:int require:1 default: other: desc:年检点id
* @param name:project_id type:int require:1 default: other: desc:项目id
* @param name:status type:int require:1 default: other desc:年检点状态(0:已检查,1:故障)
* @param name:create_time type:int require:1 default: other desc:年检时间
* @param name:images type:array require:1 default: other desc:年检图片(二维数组形式)
*
* @param name:spot_id type:inter require:1 default: other desc:检测点id
* @param name:status type:inter require:1 default: other desc:检测点状态(0:正常,1:故障)
* @param name:images type:array require:1 default: other desc:检测点图片(二维数组形式)
*/
public function insEditPost(){
public function addTestStatus(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.years_post');
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.test_status');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
//绝对路径转相对路径
$common = new CommonController();
$images = $common->relationUrl($data['images']);
$arr['images'] = $images;
$data['images'] = $images;
$data['uid'] = $this->userId;
$data['create_time'] = time();
$years = new YearsModel();
$res = $years->create($data);
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 修改检测点状态
* @description 接口说明
* @author 开发者
* @url /api/home/years/editTestStatus
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:spot_id type:inter require:1 default: other desc:检测点id
* @param name:status type:inter require:1 default: other desc:检测点状态(0:正常,1:故障)
* @param name:images type:array require:1 default: other desc:检测点图片(二维数组形式)
*/
public function editTestStatus(){
if($this->request->isPost()){
$data = $this->request->post();
$arr['status'] = $data['status'];
$arr['create_time'] = $data['create_time'];
$yearsModel = new YearsModel();
$user = $common->getIdentity();
$yearsModel->where(['spot_id'=>$data['spot_id'],'party'=>$user['party']])->whereTime('create_time','year')->update($arr);
$this->success('保存成功!');
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.test_status');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
//绝对路径转相对路径
$images = $common->relationUrl($data['images']);
$years = new YearsModel();
$res = $years->where(['spot_id'=>$data['spot_id']])->update(['status'=>$data['status'],'images'=>$images]);
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\model;
use think\Model;
class TestModel extends Model
{
protected $type = [
'more' => 'array',
];
}
\ No newline at end of file
... ...
... ... @@ -185,7 +185,7 @@
<div class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a href="javascript:void(0);" class="navbar-brand" style="min-width: 200px;text-align: center;">恒瑞消防</a>
<a href="javascript:void(0);" class="navbar-brand" style="min-width: 200px;text-align: center;">恒瑞消防后台管理</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
... ...