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

修改培训演习逻辑

... ... @@ -360,22 +360,25 @@ return array (
'confirm_images' => 'require|array',
],
'msg' => [
'id.require' => '培训单id不能为空',
'id.number' => '培训单id必须为数字',
'id.require' => '列表id不能为空',
'id.number' => '列表id必须为数字',
'confirm_images.require' => '验收照片不能为空',
'confirm_images.array' => '验收照片必须为数组',
]
],
//乙方确认完成演习单
'check_exercise' => [
'rule' => [
'id' => 'require|number',
'confirm_images' => 'require|array',
'u_ids' => 'require',
],
'msg' => [
'id.require' => '演习单id不能为空',
'id.number' => '演习单id必须为数字',
'confirm_images.require' => '验收照片不能为空',
'confirm_images.array' => '验收照片必须为数组',
'u_ids.require' => '指派完成甲方人员不能为空',
]
],
... ... @@ -451,20 +454,26 @@ return array (
'u_id.number' => '指派人员必须是数字',
]
],
//甲方发起演习
'exercise_post' => [
'rule' => [
'title' => 'require',
'project_id' => 'require|number',
'exercise_time' => 'require|number',
'address' => 'require',
'remark' => 'require',
'u_id' => 'require|number',
],
'msg' => [
'title.require' => '培训表头名称不能为空',
'project_id.require' => '项目id不能为空',
'project_id.number' => '项目id必须是数字',
'exercise_time.require' => '演习时间不能为空',
'exercise_time.number' => '演习时间必须为数字',
'address.require' => '演习地点不能为空',
'remark.require' => '演习备注不能为空',
'u_id.require' => '指派人员不能为空',
'u_id.number' => '指派人员必须是数字',
]
],
'improve_check_post' => [
... ...
... ... @@ -12,6 +12,7 @@ use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
use app\portal\model\ExerciseModel;
use app\portal\model\ConfirmImageModel;
/**
* @title 演习
*/
... ... @@ -29,16 +30,16 @@ class ExerciseController extends RestBaseController
*
* @param name:page type:inter require:1 default: other desc:分页页码
* @param name:project_id type:inter require:1 default: other desc:项目id
* @param name:status type:inter require:1 default: other desc:切换状态(-1:全部,1:待领导确认(乙方领导(确认,驳回)),2:进行中,3:已完成)
* @param name:status type:inter require:1 default: other desc:切换状态(-1:全部 0:待确认,1:进行中,2:已完成)
* @return data:演习列表@
* @data id:演习id uid:甲方提交人id status:培训状态(0:甲方提交申请,1:乙方领导驳回,2:乙方领导确认,3:完成 ) user_login:甲方发起人 b_leader:乙方确认领导 project_name:项目名称 exercise_time:演习时间 address:演习地点
* @data id:演习id uid:甲方提交人id status:培训状态(0:待乙方确认,1:进行中,2:已完成 ) user_login:甲方发起人 b_staff:乙方确认员工 project_name:项目名称 exercise_time:演习时间 address:演习地点 confirm:是否有确认按钮(0:无,1:有) finish:是否有确认完成按钮(0:无,1:有)
* @return page:当前页数
* @return total_page:总页数
*/
public function exerciseList(){
if($this->request->isGet()){
$page = $this->request->get('page');
$status = $this->request->get('status');//切换状态(-1:全部,1:待领导确认(-1:全部,1:待领导确认(乙方领导(确认,驳回)),2:进行中,3:已完成)
$status = $this->request->get('status');//切换状态(-1:全部,0:待确认,1:进行中,2:已完成)
$project_id = $this->request->get('project_id');
$limit = config('site.limit');
... ... @@ -47,24 +48,18 @@ class ExerciseController extends RestBaseController
if (!$validate->check(['page'=>$page,'status'=>$status,'project_id'=>$project_id])) {
$this->error($validate->getError());
}
//显示甲方发起人,乙方确认领导,项目名称,培训演习时间
$common = new CommonController();
$project = $common->getUserIdentity();
//如果不是甲乙方员工,则没有权限操作
if($project['identity'] != config('site.a_staff') && $project['identity'] != config('site.b_staff')){
$this->error('无权操作');
}
if($status == 1){
$where = ['project_id' => $project_id, 'status' => 0];
}else if($status == 2 || $status == 3){
$where = ['project_id' => $project_id, 'status' => $status];
}else{
if($status == -1){
$where = ['project_id' => $project_id];
}else{
$where = ['project_id' => $project_id, 'status' => $status];
}
$res = Db::name('exercise')
->where($where)
->page($page,$limit)
->field('id,uid,status,b_leader,exercise_time,address')
->field('id,uid,status,h_uid,exercise_time,address,confirm_uid')
->order('id desc')
->select()
->toArray();
... ... @@ -77,9 +72,29 @@ class ExerciseController extends RestBaseController
$user = $common->getUserById(['id'=>$value['uid']]);
$value['user_login'] = isset($user['user_login'])&&!empty($user['user_login'])?$user['user_login']:'';
//查看乙方确认领导
$leader = $common->getUserById(['id'=>$value['b_leader']]);
$value['b_leader'] = isset($leader['user_login'])&&!empty($leader['user_login'])?$leader['user_login']:'';
//是否有确认按钮
$value['confirm'] = 0;
if($value['status'] == 0 && $value['h_uid'] == $this->userId){
$value['confirm'] = 1;
}
//是否有确认完成按钮
$value['finish'] = 0;
if($value['status'] == 1){
if($value['h_uid'] == $this->userId && empty($value['confirm'])){
$value['finish'] = 1;
}else{
$u_ids = $common->getUnFinishUid(['type'=>0,'c_id'=>$value['id'],'is_image'=>1]);
if(in_array($this->userId,$u_ids)){
$value['finish'] = 1;
}else{
$value['finish'] = 0;
}
}
}
//查看乙方确认员工
$staff = $common->getUserById(['id'=>$value['h_uid']]);
$value['b_staff'] = isset($staff['user_login'])&&!empty($staff['user_login'])?$staff['user_login']:'';
$value['project_name'] = $project_name['project_name'];
}
$this->success('成功',['data'=>$res,'page'=>intval($page),'total_page'=>$total_page]);
... ... @@ -97,10 +112,12 @@ class ExerciseController extends RestBaseController
*
* @header name:token require:1 default: desc:header
*
* @param name:title type:string require:1 default: other desc:表头信息
* @param name:exercise_time type:int require:1 default: other desc:演习时间
* @param name:project_id type:int require:1 default: other desc:项目id
* @param name:address type:string require:1 default: other desc:演习地点
* @param name:remark type:string require:1 default: other desc:演习备注
* @param name:u_id type:inter require:1 default: other desc:指派乙方员工id
*/
public function applyExercise(){
if($this->request->isPost()){
... ... @@ -119,12 +136,17 @@ class ExerciseController extends RestBaseController
$data['uid'] = $this->userId;
$data['create_time'] = time();
$data['number'] = $common->genOrderSn();
//指派乙方人员uid
$data['h_uid'] = $data['u_id'];
unset($data['u_id']);
$exerciseModel = new ExerciseModel();
$res = $exerciseModel->create($data);
if($res){
//极光推送
//甲方发起,提醒乙方领导
$user_ids = $common->getLeaderA($data['project_id'],'b_cid');
//甲方发起,提醒指派乙方员工
$user_ids = [$data['h_uid']];
$content = config('site.exercise_content_add_a');
$registration_id = $common->getPushUsers($user_ids);
... ... @@ -134,6 +156,11 @@ class ExerciseController extends RestBaseController
$common->pushMessage($registration_id,$content,$title);
}
//记录参与人员id
$join_uid['project_id'] = $data['project_id'];
$join_uid['create_time'] = $data['create_time'];
$common->createInsUid($join_uid,6);
$this->success('演习信息提交成功');
}else{
$this->error('失败');
... ... @@ -144,80 +171,37 @@ class ExerciseController extends RestBaseController
}
/**
* @title 甲方重新发起申请显示(被驳回)
* @title 乙方演习确认
* @description 接口说明
* @author 开发者
* @url /api/home/exercise/reEditExercise
* @url /api/home/exercise/confirmB
* @method GET
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:inter require:1 default: other desc:月检id
* @return id:演习列表id
* @return exercise_time:演习时间
* @return address:演习地点
* @return remark:演习备注
* @return advice_time:驳回建议时间
* @param name:id type:inter require:1 default: other desc:演习id
*/
public function reEditExercise(){
public function confirmB(){
if($this->request->isGet()){
$id = $this->request->get('id');
$id = $this->request->get('id');//演习列表id
$rule = config('site.data');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['id'=>$id])) {
$this->error($validate->getError());
}
$common = new CommonController();
$field = 'id,exercise_time,address,remark,advice_time';
$res = $common->getExerciseById(['id'=>$id,'status'=>1],$field);
$this->success('成功',$res);
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方重新发起申请提交(被驳回)
* @description 接口说明
* @author 开发者
* @url /api/home/exercise/reApplyExercise
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:id type:int require:1 default: other desc:演习id
* @param name:exercise_time type:int 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 reApplyExercise(){
if($this->request->isPost()){
$data = $this->request->post();
$common = new CommonController();
$user = $common->getIdentity();
//如果是乙方,则没有权限操作
if($user['party'] == 1){
//如果是甲方,则没有权限操作
if($user['party'] == 0){
$this->error('无权操作');
}
$rule = config('site.re_exercise_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$arr['uid'] = $this->userId;
$arr['status'] = 0;
$arr['exercise_time'] = $data['exercise_time'];
$arr['address'] = $data['address'];
$arr['remark'] = $data['remark'];
$exerciseModel = new ExerciseModel();
$res = $exerciseModel->where(['id'=>$data['id'],'status'=>1])->update($arr);
$res = $exerciseModel->where(['id'=>$id,'status'=>0])->update(['status'=>1,'b_confirm_time'=>time()]);
if($res){
//极光推送
//甲方重新发起,提醒乙方领导
$project = $common->getProjectId('exercise',['id'=>$data['id']],'id,project_id');
$user_ids = $common->getLeaderA($project['project_id'],'b_cid');
$content = config('site.train_content_again_a');
//极光推送,推送发起甲方员工
$user_ids = $common->getLaunchUid('exercise',$id);
$content = config('site.exercise_content_confirm_a');
$registration_id = $common->getPushUsers($user_ids);
if($registration_id){
... ... @@ -226,8 +210,7 @@ class ExerciseController extends RestBaseController
$common->pushMessage($registration_id,$content,$title);
}
$this->success('演习信息重新提交成功');
$this->success('成功!');
}else{
$this->error('失败');
}
... ... @@ -247,6 +230,7 @@ class ExerciseController extends RestBaseController
* @param name:id type:inter require:1 default: other desc:列表id
*
* @return id:演习列表id
* @return title:培训表头信息
* @return exercise_time:演习时间
* @return address:演习地点
* @return images:完善图片@
... ... @@ -268,7 +252,7 @@ class ExerciseController extends RestBaseController
if($user['identity'] != config('site.a_staff') && $user['identity'] != config('site.b_staff')){
$this->error('无权操作');
}
$field = 'id,exercise_time,address,images,number,project_id';
$field = 'id,exercise_time,title,address,images,number,project_id';
$res = $common->getExerciseById(['id'=>$id,'status'=>2],$field);
if($res){
//查询培训演习项目
... ... @@ -313,11 +297,15 @@ class ExerciseController extends RestBaseController
$this->error('无权操作');
}
$exerciseModel = new ExerciseModel();
$images = $common->relationUrl($data['images']);
$res = $exerciseModel->where(['id'=>$data['id'],'status'=>2])->update(['images'=>$images]);
$res = $exerciseModel->where(['id'=>$data['id'],'status'=>1])->update(['images'=>$images]);
if($res){
//记录参与人员id
$project = $common->getLaunchUid('exercise',$data['id']);
$join_uid['project_id'] = $project['project_id'];
$join_uid['create_time'] = time();
$common->createInsUid($join_uid,6);
$this->success('成功');
}else{
$this->error('失败');
... ... @@ -328,17 +316,18 @@ class ExerciseController extends RestBaseController
}
/**
* @title 乙方员工完成演习单
* @title 乙方员工完成演习单
* @description 接口说明
* @author 开发者
* @url /api/home/exercise/finishExercise
* @url /api/home/exercise/finishExerciseB
* @method POST
*
* @header name:token require:1 default: desc:header
* @param name:id type:inter require:1 default: other desc:列表id
* @param name:confirm_images type:file require:1 default: other desc:验收照片(二维数组形式)
* @param name:u_ids type:string require:1 default: other desc:甲方被演习人员字符串逗号拼接("2,4,5,8")
*/
public function finishExercise(){
public function finishExerciseB(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.check_exercise');
... ... @@ -349,34 +338,97 @@ class ExerciseController extends RestBaseController
$common = new CommonController();
$user = $common->getIdentity();
//如果不是甲乙方员工,则无权操作
if($user['identity'] != config('site.a_staff') && $user['identity'] != config('site.b_staff')){
//如果不是乙方员工,则无权操作
if($user['identity'] != config('site.b_staff')){
$this->error('无权操作');
}
$exerciseModel = new ExerciseModel();
$confirm_images = $common->relationUrl($data['confirm_images']);
$arr = [
'confirm_uid'=>$this->userId,
'finish_time'=>time(),
'status'=>3,
'confirm_images'=>$confirm_images
'confirm_images'=>$confirm_images,
'confirm_uid'=>$this->userId
];
$res = $exerciseModel->where(['id'=>$data['id'],'status'=>2])->update($arr);
$res = $exerciseModel->where(['id'=>$data['id'],'status'=>1])->update($arr);
if($res){
//推送
//甲方确认完成,提醒甲乙方领导
$project = $common->getProjectId('exercise',['id'=>$data['id']],'id,project_id');
$user_ids = $common->getLeadersId($project['project_id']);
$content = config('site.exercise_content_finish');
//记录参与人员id
$project = $common->getLaunchUid('exercise',$data['id']);
$join_uid['project_id'] = $project['project_id'];
$join_uid['create_time'] = time();
$common->createInsUid($join_uid,6);
$registration_id = $common->getPushUsers($user_ids);
if($registration_id){
$common = new CommonController();
$title = config('site.title');
$common->pushMessage($registration_id,$content,$title);
//指派甲方人员
$u_ids = explode(',',$data['u_ids']);
$user['c_id'] = $data['id'];
$user['create_time'] = time();
$user['type'] = 1;
$confirmModel = new ConfirmImageModel();
foreach ($u_ids as $value) {
$user['uid'] = $value;
$confirmModel->create($user);
}
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
/**
* @title 甲方员工完成演习单
* @description 接口说明
* @author 开发者
* @url /api/home/exercise/finishTrainA
* @method POST
*
* @header name:token require:1 default: desc:header
* @param name:id type:inter require:1 default: other desc:列表id
* @param name:confirm_images type:file require:1 default: other desc:验收照片(二维数组形式)
*/
public function finishTrainA(){
if($this->request->isPost()){
$data = $this->request->post();
$rule = config('site.check_train_a');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$common = new CommonController();
$user = $common->getIdentity();
//如果不是甲方员工,则无权操作
if($user['identity'] != config('site.a_staff')){
$this->error('无权操作');
}
$confirm_images = $common->relationUrl($data['confirm_images']);
$arr = [
'confirm_images'=>$confirm_images,
'is_image' => 0,
];
$confirmModel = new ConfirmImageModel();
$res = $confirmModel->where(['c_id'=>$data['id'],'type'=>1,'uid'=>$this->userId])->update($arr);
if($res){
//记录参与人员id
$project = $common->getLaunchUid('train',$data['id']);
$join_uid['project_id'] = $project['project_id'];
$join_uid['create_time'] = time();
$common->createInsUid($join_uid,6);
//查询培训单 甲方员工是否全部完成
//已完成
$finish_count = $common->getFinishCount(['type'=>1,'c_id'=>$data['id'],'is_image'=>0]);
//所有
$count = $common->getFinishCount(['type'=>1,'c_id'=>$data['id']]);
if($finish_count == $count){
//全部甲方员已完成,更新状态已完成
$exerciseModel = new ExerciseModel();
$exerciseModel->where(['id'=>$data['id'],'status'=>1])->update(['status'=>2,'finish_time'=>time()]);
//推送系统指定人员
}
$this->success('成功');
}else{
... ...
... ... @@ -643,6 +643,17 @@ class ReformController extends RestBaseController
];
$res = $reformModel->where(['id'=>$data['id'],'status'=>2])->update($arr);
if($res){
//创建最后维修流程
$step_name = config('site.a_reform_step')[5];
$common->repairStep($data['id'],$step_name,1);
//记录参与人员id
$project = $common->getLaunchUid('reform',$data['id']);
$join_uid['project_id'] = $project['project_id'];
$join_uid['create_time'] = time();
$common->createInsUid($join_uid,4);
//极光推送,推送甲乙方领导
$project = $common->getProjectId('reform',['id'=>$data['id']],'id,project_id');
$user_ids = $common->getLeadersId($project['project_id']);
... ... @@ -655,16 +666,6 @@ class ReformController extends RestBaseController
$common->pushMessage($registration_id,$content,$title);
}
//创建最后维修流程
$step_name = config('site.a_reform_step')[5];
$common->repairStep($data['id'],$step_name,1);
//记录参与人员id
$project = $common->getLaunchUid('reform',$data['id']);
$join_uid['project_id'] = $project['project_id'];
$join_uid['create_time'] = time();
$common->createInsUid($join_uid,4);
$this->success('成功');
}else{
$this->error('失败');
... ...
... ... @@ -645,19 +645,6 @@ class RepairController extends RestBaseController
];
$res = $repairModel->where(['id'=>$data['id'],'status'=>2])->update($arr);
if($res){
//极光推送,推送甲乙方领导
$project = $common->getProjectId('repair',['id'=>$data['id']],'id,project_id');
$user_ids = $common->getLeadersId($project['project_id']);
$content = config('site.repair_content_finish');
$registration_id = $common->getPushUsers($user_ids);
if($registration_id){
$common = new CommonController();
$title = config('site.title');
$common->pushMessage($registration_id,$content,$title);
}
//创建最后维修流程
$step_name = config('site.a_step')[5];
$common->repairStep($data['id'],$step_name);
... ... @@ -668,6 +655,8 @@ class RepairController extends RestBaseController
$join_uid['create_time'] = time();
$common->createInsUid($join_uid,3);
//极光推送,推送系统指定人员
$this->success('成功');
}else{
$this->error('失败');
... ...
... ... @@ -32,7 +32,7 @@ class TrainController extends RestBaseController
* @param name:project_id type:inter require:1 default: other desc:项目id
* @param name:status type:inter require:1 default: other desc:切换状态(-1:全部,0:待确认,1:进行中,2:已完成)
* @return data:培训列表@
* @data id:培训id uid:甲方提交人id status:培训状态(0:待乙方确认,1:进行中,2:已完成 ) user_login:甲方发起人 b_staff:乙方确认员工 project_name:项目名称 train_time:培训时间 address:培训地点 confirm:是否有确认按钮(0:无,1:有)
* @data id:培训id uid:甲方提交人id status:培训状态(0:待乙方确认,1:进行中,2:已完成 ) user_login:甲方发起人 b_staff:乙方确认员工 project_name:项目名称 train_time:培训时间 address:培训地点 confirm:是否有确认按钮(0:无,1:有) finish:是否有确认完成按钮(0:无,1:有)
* @return page:当前页数
* @return total_page:总页数
*/
... ... @@ -91,8 +91,8 @@ class TrainController extends RestBaseController
}
}
//查看乙方确认员工
$leader = $common->getUserById(['id'=>$value['h_uid']]);
$value['b_staff'] = isset($leader['user_login'])&&!empty($leader['user_login'])?$leader['user_login']:'';
$staff = $common->getUserById(['id'=>$value['h_uid']]);
$value['b_staff'] = isset($staff['user_login'])&&!empty($staff['user_login'])?$staff['user_login']:'';
$value['project_name'] = $project_name['project_name'];
}
$this->success('成功',['data'=>$res,'page'=>intval($page),'total_page'=>$total_page]);
... ... @@ -323,7 +323,7 @@ class TrainController extends RestBaseController
* @header name:token require:1 default: desc:header
* @param name:id type:inter require:1 default: other desc:列表id
* @param name:confirm_images type:file require:1 default: other desc:验收照片(二维数组形式)
* @param name:u_ids type:string require:1 default: other desc:甲方被培训人员("2,4,5,8")
* @param name:u_ids type:string require:1 default: other desc:甲方被培训人员字符串逗号拼接("2,4,5,8")
*/
public function finishTrainB(){
if($this->request->isPost()){
... ... @@ -420,7 +420,10 @@ class TrainController extends RestBaseController
if($finish_count == $count){
//全部甲方员已完成,更新状态已完成
$trainModel = new TrainModel();
$trainModel->where(['id'=>$data['id'],'status'=>1])->update(['status'=>2]);
$trainModel->where(['id'=>$data['id'],'status'=>1])->update(['status'=>2,'finish_time'=>time()]);
//推送系统指定人员
}
$this->success('成功');
... ...