176 lines
6.5 KiB
PHP
176 lines
6.5 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\SupervisionProblem;
|
||
use app\common\model\supervision_work\SupervisionTestBlocksSpecimens;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 工程监理--试块试件见证逻辑
|
||
* Class SupervisionTestBlocksSpecimensLogic
|
||
* @package app\adminapi\logic\supervision_work
|
||
*/
|
||
class SupervisionTestBlocksSpecimensLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加工程监理--试块试件见证
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/02/29 14:02
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = SupervisionTestBlocksSpecimens::create([
|
||
'project_id' => $params['project_id'],
|
||
'test_type' => $params['test_type'],
|
||
'code' => data_unique_code('SKSJJZ'),
|
||
'witness' => $params['witness'],
|
||
'test_site' => $params['test_site'],
|
||
'company_id' => $params['company_id'],
|
||
'start_date' => !empty($params['start_date']) ? strtotime($params['start_date']) : 0,
|
||
'end_date' => !empty($params['end_date']) ? strtotime($params['end_date']) : 0,
|
||
'test_result' => $params['test_result'],
|
||
'remark' => $params['remark'],
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
'create_user' => $admin_id
|
||
]);
|
||
if(!empty($params['problem'])){
|
||
foreach($params['problem'] as $v){
|
||
SupervisionProblem::create([
|
||
'data_id' => $res->id,
|
||
'data_type' => 6,
|
||
'problem_cate' => $v['problem_cate'],
|
||
'problem_description' => $v['problem_description'],
|
||
'problem_name' => $v['problem_name'],
|
||
'create_user' => $admin_id,
|
||
]);
|
||
}
|
||
}
|
||
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/29 14:02
|
||
*/
|
||
public static function edit(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
SupervisionTestBlocksSpecimens::where('id', $params['id'])->update([
|
||
'project_id' => $params['project_id'],
|
||
'test_type' => $params['test_type'],
|
||
'witness' => $params['witness'],
|
||
'test_site' => $params['test_site'],
|
||
'company_id' => $params['company_id'],
|
||
'start_date' => !empty($params['start_date']) ? strtotime($params['start_date']) : 0,
|
||
'end_date' => !empty($params['end_date']) ? strtotime($params['end_date']) : 0,
|
||
'test_result' => $params['test_result'],
|
||
'remark' => $params['remark'],
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
]);
|
||
if(!empty($params['problem'])){
|
||
foreach($params['problem'] as $v){
|
||
if(!empty($v['id'])){
|
||
SupervisionProblem::where('id',$v['id'])->update([
|
||
'data_id' => $params['id'],
|
||
'data_type' => 6,
|
||
'problem_cate' => $v['problem_cate'],
|
||
'problem_description' => $v['problem_description'],
|
||
'problem_name' => $v['problem_name'],
|
||
'update_time' => time(),
|
||
]);
|
||
}else{
|
||
SupervisionProblem::create([
|
||
'data_id' => $params['id'],
|
||
'data_type' => 6,
|
||
'problem_cate' => $v['problem_cate'],
|
||
'problem_description' => $v['problem_description'],
|
||
'problem_name' => $v['problem_name'],
|
||
'create_user' => $admin_id,
|
||
]);
|
||
}
|
||
}
|
||
}
|
||
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/29 14:02
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
$problem = SupervisionProblem::where('data_id',$params['id'])->where('data_type',6)->findOrEmpty();
|
||
if(!$problem->isEmpty()){
|
||
self::setError('该内容下存在试块试件见证问题数据,请先删除试块试件见证问题数据');
|
||
return false;
|
||
}
|
||
return SupervisionTestBlocksSpecimens::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取工程监理--试块试件见证详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/02/29 14:02
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = SupervisionTestBlocksSpecimens::withoutField('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();
|
||
$create_user = Admin::field('name')->where('id',$data['create_user'])->findOrEmpty();
|
||
$data['project_name'] = $project['project_name'];
|
||
$data['company_name'] = $company['unit_name'];
|
||
$data['create_user_name'] = $create_user['name'];
|
||
$data['test_result_text'] = $data->test_result_text;
|
||
return $data->toArray();
|
||
}
|
||
} |