162 lines
6.1 KiB
PHP
162 lines
6.1 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\SupervisionMaterialEntry;
|
||
use app\common\model\supervision_work\SupervisionMaterialParallelTesting;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\supervision_work\SupervisionMaterialParallelTestingDetail;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 工程监理--材料平行检验逻辑
|
||
* Class SupervisionMaterialParallelTestingLogic
|
||
* @package app\adminapi\logic\supervision_work
|
||
*/
|
||
class SupervisionMaterialParallelTestingLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加工程监理--材料平行检验
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/02/29 15:00
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = SupervisionMaterialParallelTesting::create([
|
||
'project_id' => $params['project_id'],
|
||
'material_entry_id' => $params['material_entry_id'],
|
||
'code' => data_unique_code('CLPXJY'),
|
||
'inspector' => $params['inspector'],
|
||
'inspection_date' => !empty($params['inspection_date']) ? strtotime($params['inspection_date']) : 0,
|
||
'remark' => $params['remark'],
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
'create_user' => $admin_id
|
||
]);
|
||
if(!empty($params['detail'])){
|
||
foreach($params['detail'] as $v){
|
||
SupervisionMaterialParallelTestingDetail::create([
|
||
'material_parallel_testing_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 15:00
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
SupervisionMaterialParallelTesting::where('id', $params['id'])->update([
|
||
'project_id' => $params['project_id'],
|
||
'material_entry_id' => $params['material_entry_id'],
|
||
'inspector' => $params['inspector'],
|
||
'inspection_date' => !empty($params['inspection_date']) ? strtotime($params['inspection_date']) : 0,
|
||
'remark' => $params['remark'],
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
'update_time' => time()
|
||
]);
|
||
if(!empty($params['detail'])){
|
||
foreach($params['detail'] as $v){
|
||
if(!empty($v['id'])){
|
||
SupervisionMaterialParallelTestingDetail::where('id',$v['id'])->update([
|
||
'material_parallel_testing_id' => $params['id'],
|
||
'material_entry_detail_id' => $v['material_entry_detail_id'],
|
||
'num' => $v['num'],
|
||
'update_time' => time()
|
||
]);
|
||
}else{
|
||
SupervisionMaterialParallelTestingDetail::create([
|
||
'material_parallel_testing_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 15:00
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
$detail = SupervisionMaterialParallelTestingDetail::where('material_parallel_testing_id',$params['id'])->findOrEmpty();
|
||
if(!$detail->isEmpty()){
|
||
self::setError('当前数据下存在材料信息内容,请先删除材料信息内容');
|
||
return false;
|
||
}
|
||
return SupervisionMaterialParallelTesting::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取工程监理--材料平行检验详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/02/29 15:00
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = SupervisionMaterialParallelTesting::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')->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['create_user_name'] = $create_user['name'];
|
||
return $data->toArray();
|
||
}
|
||
} |