engineering/app/adminapi/logic/supervision_dangerous/SupervisionLargeMechanicalEquipmentLogic.php

188 lines
8.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\supervision_dangerous;
use app\common\model\supervision_dangerous\SupervisionLargeMechanicalEquipment;
use app\common\logic\BaseLogic;
use app\common\model\supervision_dangerous\SupervisionLargeMechanicalEquipmentMaintenanceRecord;
use app\common\model\supervision_project\SupervisionParticipatingUnits;
use app\common\model\supervision_project\SupervisionProject;
use think\facade\Db;
/**
* 大型机械设备及仪器台账逻辑
* Class SupervisionLargeMechanicalEquipmentLogic
* @package app\adminapi\logic\supervision_dangerous
*/
class SupervisionLargeMechanicalEquipmentLogic extends BaseLogic
{
/**
* @notes 添加大型机械设备及仪器台账
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/03/02 09:51
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$res = SupervisionLargeMechanicalEquipment::create([
'project_id' => $params['project_id'],
'sn' => data_unique_code('SBYQTZ'),
'name' => $params['name'],
'use_site' => $params['use_site'],
'entry_time' => !empty($params['entry_time']) ? strtotime($params['entry_time']) : 0,
'company_id' => $params['company_id'],
'approval_date' => !empty($params['approval_date']) ? strtotime($params['approval_date']) : 0,
'approval_result' => $params['approval_result'],
'approval_form_code' => $params['approval_form_code'],
'approval_type' => $params['approval_type'],
'first_audit_opinion' => $params['first_audit_opinion'],
'first_auditor' => $params['first_auditor'],
'first_audit_time' => !empty($params['first_audit_time']) ? strtotime($params['first_audit_time']) : 0,
'final_audit_opinion' => $params['final_audit_opinion'],
'final_audit_time' => !empty($params['final_audit_time']) ? strtotime($params['final_audit_time']) : 0,
'remark' => $params['remark'],
'annex' => $params['annex'] ? json_encode($params['annex']) : null
]);
if(!empty($params['maintenance_record'])){
foreach($params['maintenance_record'] as $v){
SupervisionLargeMechanicalEquipmentMaintenanceRecord::create([
'large_mechanical_equipment_id' => $res->id,
'reg_date' => !empty($v['reg_date']) ? strtotime($v['reg_date']) : 0,
'month_warranty_file' => $v['month_warranty_file'],
'maintenance_period' => !empty($v['maintenance_period']) ? strtotime($v['maintenance_period']) : 0,
'accessory_one_validity' => !empty($v['accessory_one_validity']) ? strtotime($v['accessory_one_validity']) : 0,
'accessory_two_validity' => !empty($v['accessory_two_validity']) ? strtotime($v['accessory_two_validity']) : 0,
]);
}
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑大型机械设备及仪器台账
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/03/02 09:51
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
SupervisionLargeMechanicalEquipment::where('id', $params['id'])->update([
'project_id' => $params['project_id'],
'name' => $params['name'],
'use_site' => $params['use_site'],
'entry_time' => !empty($params['entry_time']) ? strtotime($params['entry_time']) : 0,
'company_id' => $params['company_id'],
'approval_date' => !empty($params['approval_date']) ? strtotime($params['approval_date']) : 0,
'approval_result' => $params['approval_result'],
'approval_form_code' => $params['approval_form_code'],
'approval_type' => $params['approval_type'],
'first_audit_opinion' => $params['first_audit_opinion'],
'first_auditor' => $params['first_auditor'],
'first_audit_time' => !empty($params['first_audit_time']) ? strtotime($params['first_audit_time']) : 0,
'final_audit_opinion' => $params['final_audit_opinion'],
'final_audit_time' => !empty($params['final_audit_time']) ? strtotime($params['final_audit_time']) : 0,
'remark' => $params['remark'],
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
'update_time' => time()
]);
if(!empty($params['maintenance_record'])){
foreach($params['maintenance_record'] as $v){
if(!empty($v['id'])){
SupervisionLargeMechanicalEquipmentMaintenanceRecord::where('id',$v['id'])->update([
'large_mechanical_equipment_id' => $params['id'],
'reg_date' => !empty($v['reg_date']) ? strtotime($v['reg_date']) : 0,
'month_warranty_file' => $v['month_warranty_file'],
'maintenance_period' => !empty($v['maintenance_period']) ? strtotime($v['maintenance_period']) : 0,
'accessory_one_validity' => !empty($v['accessory_one_validity']) ? strtotime($v['accessory_one_validity']) : 0,
'accessory_two_validity' => !empty($v['accessory_two_validity']) ? strtotime($v['accessory_two_validity']) : 0,
'update_time' => time()
]);
}else{
SupervisionLargeMechanicalEquipmentMaintenanceRecord::create([
'large_mechanical_equipment_id' => $params['id'],
'reg_date' => !empty($v['reg_date']) ? strtotime($v['reg_date']) : 0,
'month_warranty_file' => $v['month_warranty_file'],
'maintenance_period' => !empty($v['maintenance_period']) ? strtotime($v['maintenance_period']) : 0,
'accessory_one_validity' => !empty($v['accessory_one_validity']) ? strtotime($v['accessory_one_validity']) : 0,
'accessory_two_validity' => !empty($v['accessory_two_validity']) ? strtotime($v['accessory_two_validity']) : 0,
]);
}
}
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除大型机械设备及仪器台账
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/03/02 09:51
*/
public static function delete(array $params): bool
{
$maintenance_record = SupervisionLargeMechanicalEquipmentMaintenanceRecord::where('large_mechanical_equipment_id',$params['id'])->findOrEmpty();
if(!$maintenance_record->isEmpty()){
self::setError('当前数据下存在机械维修保养记录,请先删除机械维修保养记录数据');
return false;
}
return SupervisionLargeMechanicalEquipment::destroy($params['id']);
}
/**
* @notes 获取大型机械设备及仪器台账详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/03/02 09:51
*/
public static function detail($params): array
{
$data = SupervisionLargeMechanicalEquipment::withoutField('create_time,update_time,delete_time')->findOrEmpty($params['id']);
$project = SupervisionProject::field('project_name')->where('id',$data['project_id'])->findOrEmpty();
$company = SupervisionParticipatingUnits::field('unit_name')->where('id',$data['company_id'])->findOrEmpty();
$data['project_name'] = $project['project_name'];
$data['company_name'] = $company['unit_name'];
$data['approval_type_text'] = $data->approval_type_text;
$data['first_audit_opinion_text'] = $data->first_audit_opinion_text;
$data['final_audit_opinion_text'] = $data->final_audit_opinion_text;
return $data->toArray();
}
}