160 lines
5.4 KiB
PHP
160 lines
5.4 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\supervision_project\SupervisionProject;
|
||
use app\common\model\supervision_work\SupervisionCheckItem;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\supervision_work\SupervisionCheckItemDetail;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 工程监理--新增检查项逻辑
|
||
* Class SupervisionCheckItemLogic
|
||
* @package app\adminapi\logic\supervision_work
|
||
*/
|
||
class SupervisionCheckItemLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加工程监理--新增检查项
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/02/26 15:34
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = SupervisionCheckItem::create([
|
||
'project_id' => $params['project_id'],
|
||
'node_name' => $params['node_name'],
|
||
'node_type' => $params['node_type'],
|
||
'node_code' => $params['node_code'],
|
||
'pid' => $params['pid'],
|
||
'inspection_basis' => $params['inspection_basis'],
|
||
'reference_law' => $params['reference_law'],
|
||
]);
|
||
if(!empty($params['check_item_detail'])){
|
||
foreach($params['check_item_detail'] as $v){
|
||
SupervisionCheckItemDetail::create([
|
||
'node_id' => $res->id,
|
||
'check_type' => $v['check_type'],
|
||
'check_content' => $v['check_content'],
|
||
'must_check' => $v['must_check'],
|
||
]);
|
||
}
|
||
}
|
||
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/26 15:34
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
SupervisionCheckItem::where('id', $params['id'])->update([
|
||
'project_id' => $params['project_id'],
|
||
'node_name' => $params['node_name'],
|
||
'node_type' => $params['node_type'],
|
||
'node_code' => $params['node_code'],
|
||
'pid' => $params['pid'],
|
||
'inspection_basis' => $params['inspection_basis'],
|
||
'reference_law' => $params['reference_law'],
|
||
'update_time' => time(),
|
||
]);
|
||
if(!empty($params['check_item_detail'])){
|
||
foreach($params['check_item_detail'] as $v){
|
||
if(!empty($v['id'])){
|
||
SupervisionCheckItemDetail::where('id',$v['id'])->update([
|
||
'node_id' => $params['id'],
|
||
'check_type' => $v['check_type'],
|
||
'check_content' => $v['check_content'],
|
||
'must_check' => $v['must_check'],
|
||
'update_time' => time(),
|
||
]);
|
||
}else{
|
||
SupervisionCheckItemDetail::create([
|
||
'node_id' => $params['id'],
|
||
'check_type' => $v['check_type'],
|
||
'check_content' => $v['check_content'],
|
||
'must_check' => $v['must_check'],
|
||
]);
|
||
}
|
||
}
|
||
}
|
||
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/26 15:34
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
$data = SupervisionCheckItem::where('pid',$params['id'])->findOrEmpty();
|
||
if(!$data->isEmpty()){
|
||
self::setError('当前节点下存在子节点,请先删除子节点');
|
||
return false;
|
||
}
|
||
return SupervisionCheckItem::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取工程监理--新增检查项详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/02/26 15:34
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = SupervisionCheckItem::withoutField('create_time,update_time,delete_time')->findOrEmpty($params['id']);
|
||
$project = SupervisionProject::field('project_name')->where('id',$data['project_id'])->findOrEmpty();
|
||
$pid = SupervisionCheckItem::field('node_name')->where('id',$data['pid'])->findOrEmpty();
|
||
$data['project_name'] = $project['project_name'];
|
||
$data['p_node_name'] = $pid['node_name'];
|
||
$data['node_type_text'] = $data->node_type_text;
|
||
return $data->toArray();
|
||
}
|
||
} |