137 lines
4.7 KiB
PHP
137 lines
4.7 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\project;
|
||
|
||
|
||
use app\common\model\project\Project;
|
||
use app\common\model\project\ProjectInsuranceManagement;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\project\ProjectPersonnel;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 保险管理逻辑
|
||
* Class ProjectInsuranceManagementLogic
|
||
* @package app\adminapi\logic\project
|
||
*/
|
||
class ProjectInsuranceManagementLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加保险管理
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/25 15:58
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProjectInsuranceManagement::create([
|
||
'project_id' => $params['project_id'],
|
||
'project_person_id' => $params['project_person_id'],
|
||
'insurance_date' => strtotime($params['insurance_date']),
|
||
'due_date' => strtotime($params['due_date']),
|
||
'type' => $params['type'],
|
||
'insurance_no' => $params['insurance_no'],
|
||
'insurance' => $params['insurance'],
|
||
'insured_amount' => $params['insured_amount'],
|
||
'insurance_company' => $params['insurance_company'],
|
||
'insurance_detail' => $params['insurance_detail'],
|
||
'invoice_no' => $params['invoice_no'],
|
||
'handler' => $params['handler'],
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
]);
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑保险管理
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/25 15:58
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProjectInsuranceManagement::where('id', $params['id'])->update([
|
||
'project_id' => $params['project_id'],
|
||
'project_person_id' => $params['project_person_id'],
|
||
'insurance_date' => strtotime($params['insurance_date']),
|
||
'due_date' => strtotime($params['due_date']),
|
||
'type' => $params['type'],
|
||
'insurance_no' => $params['insurance_no'],
|
||
'insurance' => $params['insurance'],
|
||
'insured_amount' => $params['insured_amount'],
|
||
'insurance_company' => $params['insurance_company'],
|
||
'insurance_detail' => $params['insurance_detail'],
|
||
'invoice_no' => $params['invoice_no'],
|
||
'handler' => $params['handler'],
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
]);
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除保险管理
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/25 15:58
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return ProjectInsuranceManagement::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取保险管理详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/25 15:58
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = ProjectInsuranceManagement::findOrEmpty($params['id'])->toArray();
|
||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||
$person = ProjectPersonnel::field('name,idcard')->where('id',$data['project_person_id'])->findOrEmpty();
|
||
$data['project_name'] = $project['name'];
|
||
$data['project_code'] = $project['project_code'];
|
||
$data['person_name'] = $person['name'];
|
||
$data['person_idcard'] = $person['idcard'];
|
||
return $data;
|
||
}
|
||
} |