engineering/app/adminapi/logic/supervision_work/SupervisionMaterialParallelTestingDetailLogic.php
2024-02-29 16:19:38 +08:00

163 lines
5.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_work;
use app\common\model\supervision_work\SupervisionMaterialEntryDetail;
use app\common\model\supervision_work\SupervisionMaterialParallelTestingDetail;
use app\common\logic\BaseLogic;
use app\common\model\supervision_work\SupervisionProblem;
use think\facade\Db;
/**
* 工程监理--材料平行检验明细逻辑
* Class SupervisionMaterialParallelTestingDetailLogic
* @package app\adminapi\logic\supervision_work
*/
class SupervisionMaterialParallelTestingDetailLogic extends BaseLogic
{
/**
* @notes 添加工程监理--材料平行检验明细
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/29 15:00
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
SupervisionMaterialParallelTestingDetail::create([
'material_parallel_testing_id' => $params['material_parallel_testing_id'],
'material_entry_detail_id' => $params['material_entry_detail_id'],
'num' => $params['num'],
]);
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 15:00
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
SupervisionMaterialParallelTestingDetail::where('id', $params['id'])->update([
'material_parallel_testing_id' => $params['material_parallel_testing_id'],
'material_entry_detail_id' => $params['material_entry_detail_id'],
'num' => $params['num'],
'update_time' => time()
]);
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 09:22
*/
public static function check(array $params,$admin_id): bool
{
Db::startTrans();
try {
SupervisionMaterialParallelTestingDetail::where('id', $params['id'])->update([
'check_code' => $params['check_code'],
'check_result' => $params['check_result'],
'check_time' => !empty($params['check_time']) ? strtotime($params['check_time']) : 0,
'check_user' => $params['check_user'],
'check_remark' => $params['check_remark'],
'check_annex' => $params['check_annex'] ? json_encode($params['check_annex']) : null,
]);
if(!empty($params['check_problem'])){
foreach($params['check_problem'] as $v){
SupervisionProblem::create([
'data_id' => $params['id'],
'data_type' => 7,
'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 15:00
*/
public static function delete(array $params): bool
{
$check_problem = SupervisionProblem::where('data_id',$params['id'])->where('data_type',7)->findOrEmpty();
if(!$check_problem->isEmpty()){
self::setError('该内容下存在验收问题数据,请先删除验收问题数据');
return false;
}
return SupervisionMaterialParallelTestingDetail::destroy($params['id']);
}
/**
* @notes 获取工程监理--材料平行检验明细详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/29 15:00
*/
public static function detail($params): array
{
$data = SupervisionMaterialParallelTestingDetail::withoutField('create_time,update_time,delete_time')->findOrEmpty($params['id']);
$material_entry_detail = SupervisionMaterialEntryDetail::field('name,brand,model,contract_brand,entry_number')->where('id',$data['material_entry_detail_id'])->findOrEmpty();
$data['name'] = $material_entry_detail['name'];
$data['brand'] = $material_entry_detail['brand'];
$data['model'] = $material_entry_detail['model'];
$data['contract_brand'] = $material_entry_detail->contract_brand_text;
$data['entry_number'] = $material_entry_detail['entry_number'];
return $data->toArray();
}
}