新增试块试件见证模块

This commit is contained in:
weiz 2024-02-29 15:05:02 +08:00
parent c8b07a587c
commit 2deb11111c
7 changed files with 604 additions and 1 deletions

@ -0,0 +1,108 @@
<?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\controller\supervision_work;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\supervision_work\SupervisionTestBlocksSpecimensLists;
use app\adminapi\logic\supervision_work\SupervisionTestBlocksSpecimensLogic;
use app\adminapi\validate\supervision_work\SupervisionTestBlocksSpecimensValidate;
/**
* 工程监理--试块试件见证控制器
* Class SupervisionTestBlocksSpecimensController
* @package app\adminapi\controller\supervision_work
*/
class SupervisionTestBlocksSpecimensController extends BaseAdminController
{
/**
* @notes 获取工程监理--试块试件见证列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/29 14:02
*/
public function lists()
{
return $this->dataLists(new SupervisionTestBlocksSpecimensLists());
}
/**
* @notes 添加工程监理--试块试件见证
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/29 14:02
*/
public function add()
{
$params = (new SupervisionTestBlocksSpecimensValidate())->post()->goCheck('add');
$result = SupervisionTestBlocksSpecimensLogic::add($params,$this->adminId);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(SupervisionTestBlocksSpecimensLogic::getError());
}
/**
* @notes 编辑工程监理--试块试件见证
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/29 14:02
*/
public function edit()
{
$params = (new SupervisionTestBlocksSpecimensValidate())->post()->goCheck('edit');
$result = SupervisionTestBlocksSpecimensLogic::edit($params,$this->adminId);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(SupervisionTestBlocksSpecimensLogic::getError());
}
/**
* @notes 删除工程监理--试块试件见证
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/29 14:02
*/
public function delete()
{
$params = (new SupervisionTestBlocksSpecimensValidate())->post()->goCheck('delete');
SupervisionTestBlocksSpecimensLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取工程监理--试块试件见证详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/29 14:02
*/
public function detail()
{
$params = (new SupervisionTestBlocksSpecimensValidate())->goCheck('detail');
$result = SupervisionTestBlocksSpecimensLogic::detail($params);
return $this->data($result);
}
}

@ -0,0 +1,91 @@
<?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\lists\supervision_work;
use app\adminapi\lists\BaseAdminDataLists;
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\lists\ListsSearchInterface;
/**
* 工程监理--试块试件见证列表
* Class SupervisionTestBlocksSpecimensLists
* @package app\adminapi\listssupervision_work
*/
class SupervisionTestBlocksSpecimensLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/02/29 14:02
*/
public function setSearch(): array
{
return [
'=' => ['project_id', 'test_result'],
'%like%' => ['test_type', 'code', 'witness', 'test_site'],
];
}
/**
* @notes 获取工程监理--试块试件见证列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/02/29 14:02
*/
public function lists(): array
{
return SupervisionTestBlocksSpecimens::withoutField('update_time,delete_time')->where($this->searchWhere)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$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;
$data['problem_num'] = SupervisionProblem::field('id')->where('data_id',$data['id'])->where('data_type',6)->count();
$data['reply_num'] = SupervisionProblem::field('id')->where('data_id',$data['id'])->where('data_type',6)->where('is_rectification',1)->count();
})
->toArray();
}
/**
* @notes 获取工程监理--试块试件见证数量
* @return int
* @author likeadmin
* @date 2024/02/29 14:02
*/
public function count(): int
{
return SupervisionTestBlocksSpecimens::where($this->searchWhere)->count();
}
}

@ -20,6 +20,7 @@ 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\SupervisionMaterialEntryDetail;
use app\common\model\supervision_work\SupervisionProblem;
use app\common\model\supervision_work\SupervisionWitnessSampling;
use app\common\lists\ListsSearchInterface;
use app\common\model\supervision_work\SupervisionWitnessSamplingDetail;
@ -90,6 +91,8 @@ class SupervisionWitnessSamplingLists extends BaseAdminDataLists implements List
$data['model'] = $material_entry_detail['model'];
$data['entry_number'] = $material_entry_detail['entry_number'];
$data['check_result_text'] = $data->check_result_text;
$data['problem_num'] = SupervisionProblem::field('id')->where('data_id',$data['id'])->where('data_type',5)->count();
$data['reply_num'] = SupervisionProblem::field('id')->where('data_id',$data['id'])->where('data_type',5)->where('is_rectification',1)->count();
})
->toArray();
}

@ -0,0 +1,176 @@
<?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();
}
}

@ -0,0 +1,173 @@
<?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\validate\supervision_work;
use app\common\model\dict\DictData;
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\validate\BaseValidate;
/**
* 工程监理--试块试件见证验证器
* Class SupervisionTestBlocksSpecimensValidate
* @package app\adminapi\validate\supervision_work
*/
class SupervisionTestBlocksSpecimensValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'project_id' => 'require|checkProject',
'witness' => 'require',
'company_id' => 'checkCompany',
'start_date' => 'require|dateFormat:Y-m-d',
'end_date' => 'require|dateFormat:Y-m-d',
'test_result' => 'require|in:0,1',
'annex' => 'checkAnnex',
'problem' => 'checkProblem'
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'project_id' => '项目id',
'test_type' => '试验类型',
'code' => '编号',
'witness' => '见证人',
'test_site' => '试验部位',
'company_id' => '单位名称',
'start_date' => '开始日期',
'end_date' => '结束日期',
'test_result' => '试验结果 0-符合标准 1-不符合标准',
'remark' => '备注',
'create_user' => '创建人',
];
/**
* @notes 添加场景
* @return SupervisionTestBlocksSpecimensValidate
* @author likeadmin
* @date 2024/02/29 14:02
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return SupervisionTestBlocksSpecimensValidate
* @author likeadmin
* @date 2024/02/29 14:02
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return SupervisionTestBlocksSpecimensValidate
* @author likeadmin
* @date 2024/02/29 14:02
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return SupervisionTestBlocksSpecimensValidate
* @author likeadmin
* @date 2024/02/29 14:02
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value){
$data = SupervisionTestBlocksSpecimens::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '数据不存在';
}
return true;
}
public function checkProject($value): bool|string
{
$data = SupervisionProject::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目信息不存在';
}
return true;
}
public function checkCompany($value,$rule,$params): bool|string
{
$data = SupervisionParticipatingUnits::where('id',$value)->where('project_id',$params['project_id'])->findOrEmpty();
if($data->isEmpty()){
return '单位信息不存在';
}
return true;
}
public function checkAnnex($value): bool|string
{
if(!empty($value) && $value != '' && !is_array($value)){
return '附件格式错误';
}
return true;
}
public function checkProblem($value): bool|string
{
if(!isset($value) || $value == '') return true;
if(!is_array($value)) return '试块试件见证问题数据格式错误';
foreach($value as $k=>$v){
if(!empty($v['id'])){
$data = SupervisionProblem::where('id',$v['id'])->findOrEmpty();
if($data->isEmpty()){
return '试块试件见证问题列表第'.($k+1).'行数据不存在';
}
}
if(empty($v['problem_cate'])){
return '试块试件见证问题列表第'.($k+1).'行问题分类为空';
}else{
$dict = DictData::where('type_value','problem_cate')->column('value');
if(!in_array($v['problem_cate'],$dict)) return '试块试件见证问题列表第'.($k+1).'行问题分类数据值无效';
}
if(empty($v['problem_description'])) return '试块试件见证问题列表第'.($k+1).'行问题说明为空';
if(empty($v['problem_name'])) return '试块试件见证问题列表第'.($k+1).'行问题名称为空';
}
return true;
}
}

@ -34,7 +34,7 @@ class SupervisionProblem extends BaseModel
public function getDataTypeTextAttr($value,$data): string
{
//1-巡视 2-旁站 3-验收 4-设备进场 5-见证取样 6-材料平行检验 7-实体平行检验
$arr = [1=>'巡视', 2=>'旁站', 3=>'验收', 4=>'设备进场', 5=>'见证取样', 6=>'材料平行检验', 7=>'实体平行检验'];
$arr = [1=>'巡视', 2=>'旁站', 3=>'验收', 4=>'设备进场', 5=>'见证取样', 6=>'试块试件见证', 7=>'材料平行检验', 8=>'实体平行检验'];
return $arr[$data['data_type']];
}

@ -0,0 +1,52 @@
<?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\common\model\supervision_work;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 工程监理--试块试件见证模型
* Class SupervisionTestBlocksSpecimens
* @package app\common\model\supervision_work
*/
class SupervisionTestBlocksSpecimens extends BaseModel
{
use SoftDelete;
protected $name = 'supervision_test_blocks_specimens';
protected $deleteTime = 'delete_time';
public function getAnnexAttr($value)
{
return !empty($value) ? json_decode($value,true) : '';
}
public function getTestResultTextAttr($value,$data){
$arr = [0=>'符合标准', 1=>'不符合标准'];
return $arr[$data['test_result']];
}
public function getStartDateAttr($value): string
{
return !empty($value) ? date('Y-m-d', $value) : '';
}
public function getEndDateAttr($value): string
{
return !empty($value) ? date('Y-m-d', $value) : '';
}
}