engineering/app/adminapi/logic/supervision_work/SupervisionWitnessSamplingLogic.php
2024-02-29 13:58:35 +08:00

164 lines
5.9 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\SupervisionMaterialEntry;
use app\common\model\supervision_work\SupervisionWitnessSampling;
use app\common\logic\BaseLogic;
use app\common\model\supervision_work\SupervisionWitnessSamplingDetail;
use think\facade\Db;
/**
* 工程监理--见证取样逻辑
* Class SupervisionWitnessSamplingLogic
* @package app\adminapi\logic\supervision_work
*/
class SupervisionWitnessSamplingLogic extends BaseLogic
{
/**
* @notes 添加工程监理--见证取样
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/29 09:22
*/
public static function add(array $params,$admin_id): bool
{
Db::startTrans();
try {
$res = SupervisionWitnessSampling::create([
'project_id' => $params['project_id'],
'material_entry_id' => $params['material_entry_id'],
'code' => data_unique_code('CLJZ'),
'sampling_date' => !empty($params['sampling_date']) ? strtotime($params['sampling_date']) : 0,
'witness' => $params['witness'],
'sampler' => $params['sampler'],
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
'create_user' => $admin_id
]);
if(!empty($params['sampling_detail'])){
foreach($params['sampling_detail'] as $v){
SupervisionWitnessSamplingDetail::create([
'witness_sampling_id' => $res->id,
'material_entry_detail_id' => $v['material_entry_detail_id'],
'num' => $v['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 09:22
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
SupervisionWitnessSampling::where('id', $params['id'])->update([
'project_id' => $params['project_id'],
'material_entry_id' => $params['material_entry_id'],
'sampling_date' => !empty($params['sampling_date']) ? strtotime($params['sampling_date']) : 0,
'witness' => $params['witness'],
'sampler' => $params['sampler'],
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
'update_time' => time()
]);
if(!empty($params['sampling_detail'])){
foreach($params['sampling_detail'] as $v){
if(!empty($v['id'])){
SupervisionWitnessSamplingDetail::where('id',$v['id'])->update([
'witness_sampling_id' => $params['id'],
'material_entry_detail_id' => $v['material_entry_detail_id'],
'num' => $v['num'],
'update_time' => time()
]);
}else{
SupervisionWitnessSamplingDetail::create([
'witness_sampling_id' => $params['id'],
'material_entry_detail_id' => $v['material_entry_detail_id'],
'num' => $v['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 09:22
*/
public static function delete(array $params): bool
{
$witness_sampling_detail = SupervisionWitnessSamplingDetail::where('witness_sampling_id',$params['id'])->findOrEmpty();
if(!$witness_sampling_detail->isEmpty()){
self::setError('当前数据下存在材料信息内容,请先删除材料信息内容');
return false;
}
return SupervisionWitnessSampling::destroy($params['id']);
}
/**
* @notes 获取工程监理--见证取样详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/29 09:22
*/
public static function detail($params): array
{
$data = SupervisionWitnessSampling::withoutField('update_time,delete_time')->findOrEmpty($params['id']);
$project = SupervisionProject::field('project_name')->where('id',$data['project_id'])->findOrEmpty();
$material_entry = SupervisionMaterialEntry::field('company_id,enter_time')->where('id',$data['material_entry_id'])->findOrEmpty();
$company = SupervisionParticipatingUnits::field('unit_name')->where('id',$material_entry['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['enter_time'] = $material_entry['enter_time'];
$data['create_user_name'] = $create_user['name'];
return $data->toArray();
}
}