engineering/app/adminapi/logic/supervision_work/SupervisionSideStationLogic.php
2024-02-27 15:17:14 +08:00

225 lines
9.0 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_work;
use app\common\model\auth\Admin;
use app\common\model\supervision_project\SupervisionParticipatingUnits;
use app\common\model\supervision_project\SupervisionProject;
use app\common\model\supervision_work\SupervisionCheckItem;
use app\common\model\supervision_work\SupervisionSideStation;
use app\common\logic\BaseLogic;
use app\common\model\supervision_work\SupervisionSideStationProblem;
use app\common\model\supervision_work\SupervisionSideStationResult;
use think\facade\Db;
/**
* 工程监理--旁站登记逻辑
* Class SupervisionSideStationLogic
* @package app\adminapi\logic\supervision_work
*/
class SupervisionSideStationLogic extends BaseLogic
{
/**
* @notes 添加工程监理--旁站登记
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/27 13:58
*/
public static function add(array $params,$admin_id): bool
{
Db::startTrans();
try {
$res = SupervisionSideStation::create([
'project_id' => $params['project_id'],
'side_station_code' => data_unique_code('PZ'),
'side_station_type' => $params['side_station_type'],
'check_item_id' => $params['check_item_id'],
'position' => $params['position'],
'company_id' => $params['company_id'],
'start_time' => !empty($params['start_time']) ? strtotime($params['start_time']) : 0,
'end_time' => !empty($params['end_time']) ? strtotime($params['end_time']) : 0,
'workers' => $params['workers'],
'managers' => $params['managers'],
'situation' => $params['situation'],
'side_station_result' => $params['side_station_result'],
'side_station_user' => $params['side_station_user'],
'check_item_detail_ids' => $params['check_item_detail_ids'] ? json_encode($params['check_item_detail_ids']) : null,
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
'create_user' => $admin_id
]);
if(!empty($params['side_result'])){
foreach($params['side_result'] as $v){
SupervisionSideStationResult::create([
'side_station_id' => $res->id,
'check_type' => $v['check_type'],
'check_content' => $v['check_content'],
'must_check' => $v['must_check'],
'check_result' => $v['check_result']
]);
}
}
if(!empty($params['side_problem'])){
foreach($params['side_problem'] as $v){
SupervisionSideStationProblem::create([
'side_station_id' => $res->id,
'problem_cate' => $v['problem_cate'],
'problem_description' => $v['problem_description'],
'problem_name' => $v['problem_name'],
]);
}
}
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/02/27 13:58
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
SupervisionSideStation::where('id', $params['id'])->update([
'project_id' => $params['project_id'],
'side_station_type' => $params['side_station_type'],
'check_item_id' => $params['check_item_id'],
'position' => $params['position'],
'company_id' => $params['company_id'],
'start_time' => !empty($params['start_time']) ? strtotime($params['start_time']) : 0,
'end_time' => !empty($params['end_time']) ? strtotime($params['end_time']) : 0,
'workers' => $params['workers'],
'managers' => $params['managers'],
'situation' => $params['situation'],
'side_station_result' => $params['side_station_result'],
'side_station_user' => $params['side_station_user'],
'check_item_detail_ids' => $params['check_item_detail_ids'] ? json_encode($params['check_item_detail_ids']) : null,
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
'update_time' => time(),
]);
if(!empty($params['side_result'])){
foreach($params['side_result'] as $v){
if(!empty($v['id'])){
SupervisionSideStationResult::where('id',$v['id'])->update([
'side_station_id' => $params['id'],
'check_type' => $v['check_type'],
'check_content' => $v['check_content'],
'must_check' => $v['must_check'],
'check_result' => $v['check_result'],
'update_time' => time(),
]);
}else{
SupervisionSideStationResult::create([
'side_station_id' => $params['id'],
'check_type' => $v['check_type'],
'check_content' => $v['check_content'],
'must_check' => $v['must_check'],
'check_result' => $v['check_result']
]);
}
}
}
if(!empty($params['side_problem'])){
foreach($params['side_problem'] as $v){
if(!empty($v['id'])){
SupervisionSideStationProblem::where('id',$v['id'])->update([
'side_station_id' => $params['id'],
'problem_cate' => $v['problem_cate'],
'problem_description' => $v['problem_description'],
'problem_name' => $v['problem_name'],
'update_time' => time(),
]);
}else{
SupervisionSideStationProblem::create([
'side_station_id' => $params['id'],
'problem_cate' => $v['problem_cate'],
'problem_description' => $v['problem_description'],
'problem_name' => $v['problem_name'],
]);
}
}
}
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/02/27 13:58
*/
public static function delete(array $params): bool
{
$side_station_result = SupervisionSideStationResult::where('side_station_id',$params['id'])->findOrEmpty();
if(!$side_station_result->isEmpty()){
self::setError('该旁站内容下存在旁站结果数据,请先删除旁站结果数据');
return false;
}
$side_station_problem = SupervisionSideStationProblem::where('side_station_id',$params['id'])->findOrEmpty();
if(!$side_station_problem->isEmpty()){
self::setError('该旁站内容下存在旁站问题数据,请先删除旁站问题数据');
return false;
}
return SupervisionSideStation::destroy($params['id']);
}
/**
* @notes 获取工程监理--旁站登记详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/27 13:58
*/
public static function detail($params): array
{
$data = SupervisionSideStation::withoutField('update_time,delete_time')->findOrEmpty($params['id']);
$project = SupervisionProject::field('project_name')->where('id',$data['project_id'])->findOrEmpty();
$check_item = SupervisionCheckItem::field('node_name')->where('id',$data['check_item_id'])->findOrEmpty();
$company = SupervisionParticipatingUnits::field('unit_name')->where('id',$data['company_id'])->findOrEmpty();
$check_item_detail = SupervisionCheckItem::where('id','in',$data['check_item_detail_ids'])->column('node_name');
$create_user = Admin::field('name')->where('id',$data['create_user'])->findOrEmpty();
$data['project_name'] = $project['project_name'];
$data['check_item_name'] = $check_item['node_name'];
$data['company_name'] = $company['unit_name'];
$data['check_item_detail_name'] = implode(',',$check_item_detail);
$data['create_user_name'] = $create_user['name'];
$data['side_station_type_text'] = $data->side_station_type_text;
$data['side_station_result_text'] = $data->side_station_result_text;
return $data->toArray();
}
}