engineering/app/adminapi/logic/project/ProjectLoanApplyLogic.php
2024-02-19 17:49:52 +08:00

166 lines
5.4 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\project;
use app\common\model\bank\BankAccount;
use app\common\model\oa\FlowApprove;
use app\common\model\project\Project;
use app\common\model\project\ProjectLoanApply;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 借款申请逻辑
* Class ProjectLoanApplyLogic
* @package app\adminapi\logic\project
*/
class ProjectLoanApplyLogic extends BaseLogic
{
/**
* @notes 添加借款申请
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/17 11:05
*/
public static function add(array $params,$admin_id): bool
{
Db::startTrans();
try {
$res = ProjectLoanApply::create([
'loan_apply_code' => data_unique_code('项目借款'),
'project_id' => $params['project_id'],
'apply_user' => $params['apply_user'],
'loan_date' => strtotime($params['loan_date']),
'loan_amount' => $params['loan_amount'],
'payee_name' => $params['payee_name'],
'payee_bank' => $params['payee_bank'],
'payee_account' => $params['payee_account'],
'remark' => $params['remark'] ?? '',
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
'bank_account_id' => $params['bank_account_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/01/17 11:05
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectLoanApply::where('id', $params['id'])->update([
'project_id' => $params['project_id'],
'apply_user' => $params['apply_user'],
'loan_date' => strtotime($params['loan_date']),
'loan_amount' => $params['loan_amount'],
'payee_name' => $params['payee_name'],
'payee_bank' => $params['payee_bank'],
'payee_account' => $params['payee_account'],
'remark' => $params['remark'] ?? '',
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
'bank_account_id' => $params['bank_account_id'],
'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/01/17 11:05
*/
public static function delete(array $params): bool
{
return ProjectLoanApply::destroy($params['id']);
}
/**
* @notes 获取借款申请详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/01/17 11:05
*/
public static function detail($params): array
{
$data = ProjectLoanApply::field('id,project_id,loan_apply_code,apply_user,loan_date,loan_amount,payee_name,payee_bank,payee_account,remark,annex,bank_account_id,approve_id')
->findOrEmpty($params['id']);
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['bank_account'] = BankAccount::field('account_sn,deposit_bank,account_name,account')->where('id',$data['bank_account_id'])->findOrEmpty();
$approve_data = FlowApprove::where('id',$data['approve_id'])->findOrEmpty();
$data['approve_check_status'] = $approve_data['check_status'];
return $data->toArray();
}
public static function approve($params,$admin_id): bool{
$data = ProjectLoanApply::where('id',$params['id'])->findOrEmpty();
$approve_data = FlowApprove::where('id',$data['approve_id'])->findOrEmpty();
if(!empty($data['approve_id']) && $approve_data['check_status'] != 3){
self::setError('当前内容存在审核信息,请勿重复提交');
return false;
}
Db::startTrans();
try {
$res = addApprove(
'借款申请',
$params['id'],
'app\common\model\project\ProjectLoanApply',
$params['path'],
$params['flow_id'],
$admin_id
);
if($res){
ProjectLoanApply::where('id',$params['id'])->update([
'approve_id' => $res,
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}