222 lines
8.7 KiB
PHP
222 lines
8.7 KiB
PHP
<?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\SupervisionAccept;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\supervision_work\SupervisionAcceptProblem;
|
||
use app\common\model\supervision_work\SupervisionAcceptResult;
|
||
use app\common\model\supervision_work\SupervisionCheckItem;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 工程监理--验收登记逻辑
|
||
* Class SupervisionAcceptLogic
|
||
* @package app\adminapi\logic\supervision_work
|
||
*/
|
||
class SupervisionAcceptLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加工程监理--验收登记
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/02/27 15:23
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = SupervisionAccept::create([
|
||
'project_id' => $params['project_id'],
|
||
'accept_code' => data_unique_code('YS'),
|
||
'accept_type' => $params['accept_type'],
|
||
'check_item_id' => $params['check_item_id'],
|
||
'accept_content' => $params['accept_content'],
|
||
'accept_position' => $params['accept_position'],
|
||
'accept_time' => !empty($params['accept_time']) ? strtotime($params['accept_time']) : 0,
|
||
'company_id' => $params['company_id'],
|
||
'accept_result' => $params['accept_result'],
|
||
'check_item_detail_ids' => $params['check_item_detail_ids'] ? json_encode($params['check_item_detail_ids']) : null,
|
||
'remark' => $params['remark'],
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
'create_user' => $admin_id
|
||
]);
|
||
if(!empty($params['accept_check_result'])){
|
||
foreach($params['accept_check_result'] as $v){
|
||
SupervisionAcceptResult::create([
|
||
'accept_id' => $res->id,
|
||
'check_type' => $v['check_type'],
|
||
'check_content' => $v['check_content'],
|
||
'check_problem' => $v['check_problem'],
|
||
'must_check' => $v['must_check'],
|
||
'check_result' => $v['check_result']
|
||
]);
|
||
}
|
||
}
|
||
if(!empty($params['accept_check_problem'])){
|
||
foreach($params['accept_check_problem'] as $v){
|
||
SupervisionAcceptProblem::create([
|
||
'accept_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 15:23
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
SupervisionAccept::where('id', $params['id'])->update([
|
||
'project_id' => $params['project_id'],
|
||
'accept_type' => $params['accept_type'],
|
||
'check_item_id' => $params['check_item_id'],
|
||
'accept_content' => $params['accept_content'],
|
||
'accept_position' => $params['accept_position'],
|
||
'accept_time' => !empty($params['accept_time']) ? strtotime($params['accept_time']) : 0,
|
||
'company_id' => $params['company_id'],
|
||
'accept_result' => $params['accept_result'],
|
||
'check_item_detail_ids' => $params['check_item_detail_ids'] ? json_encode($params['check_item_detail_ids']) : null,
|
||
'remark' => $params['remark'],
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
'update_time' => time(),
|
||
]);
|
||
if(!empty($params['accept_check_result'])){
|
||
foreach($params['accept_check_result'] as $v){
|
||
if(!empty($v['id'])){
|
||
SupervisionAcceptResult::where('id',$v['id'])->update([
|
||
'accept_id' => $params['id'],
|
||
'check_type' => $v['check_type'],
|
||
'check_content' => $v['check_content'],
|
||
'check_problem' => $v['check_problem'],
|
||
'must_check' => $v['must_check'],
|
||
'check_result' => $v['check_result'],
|
||
'update_time' => time(),
|
||
]);
|
||
}else{
|
||
SupervisionAcceptResult::create([
|
||
'accept_id' => $params['id'],
|
||
'check_type' => $v['check_type'],
|
||
'check_content' => $v['check_content'],
|
||
'check_problem' => $v['check_problem'],
|
||
'must_check' => $v['must_check'],
|
||
'check_result' => $v['check_result']
|
||
]);
|
||
}
|
||
}
|
||
}
|
||
if(!empty($params['accept_check_problem'])){
|
||
foreach($params['accept_check_problem'] as $v){
|
||
if(!empty($v['id'])){
|
||
SupervisionAcceptProblem::where('id',$v['id'])->update([
|
||
'accept_id' => $params['id'],
|
||
'problem_cate' => $v['problem_cate'],
|
||
'problem_description' => $v['problem_description'],
|
||
'problem_name' => $v['problem_name'],
|
||
'update_time' => time(),
|
||
]);
|
||
}else{
|
||
SupervisionAcceptProblem::create([
|
||
'accept_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 15:23
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
$accept_result = SupervisionAcceptResult::where('accept_id',$params['id'])->findOrEmpty();
|
||
if(!$accept_result->isEmpty()){
|
||
self::setError('该验收内容下存在验收结果数据,请先删除验收结果数据');
|
||
return false;
|
||
}
|
||
$accept_problem = SupervisionAcceptProblem::where('accept_id',$params['id'])->findOrEmpty();
|
||
if(!$accept_problem->isEmpty()){
|
||
self::setError('该验收内容下存在验收问题数据,请先删除验收问题数据');
|
||
return false;
|
||
}
|
||
return SupervisionAccept::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取工程监理--验收登记详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/02/27 15:23
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = SupervisionAccept::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['accept_type_text'] = $data->accept_type_text;
|
||
$data['accept_result_text'] = $data->accept_result_text;
|
||
return $data->toArray();
|
||
}
|
||
} |