146 lines
5.3 KiB
PHP
146 lines
5.3 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\finance;
|
||
|
||
|
||
use app\common\model\bank\BankAccount;
|
||
use app\common\model\contract\Contract;
|
||
use app\common\model\custom\Custom;
|
||
use app\common\model\finance\FinanceRefundApply;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\project\Project;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* FinanceRefundApply逻辑
|
||
* Class FinanceRefundApplyLogic
|
||
* @package app\adminapi\logic\finance
|
||
*/
|
||
class FinanceRefundApplyLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/14 16:58
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
$contract = Contract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty();
|
||
Db::startTrans();
|
||
try {
|
||
FinanceRefundApply::create([
|
||
'refund_code' => data_unique_code('退款申请'),
|
||
'project_id' => $contract['project_id'],
|
||
'contract_id' => $params['contract_id'],
|
||
'refund_date' => strtotime($params['refund_date']),
|
||
'reason' => $params['reason'],
|
||
'amount' => $params['amount'],
|
||
'refund_type' => $params['refund_type'],
|
||
'refund_user' => $params['refund_user'] ?? '',
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : '',
|
||
'collection_bank' => $params['collection_bank'],
|
||
'collection_account' => $params['collection_account'],
|
||
'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 2023/12/14 16:58
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
$contract = Contract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty();
|
||
Db::startTrans();
|
||
try {
|
||
FinanceRefundApply::create([
|
||
'project_id' => $contract['project_id'],
|
||
'contract_id' => $params['contract_id'],
|
||
'refund_date' => strtotime($params['refund_date']),
|
||
'reason' => $params['reason'],
|
||
'amount' => $params['amount'],
|
||
'refund_type' => $params['refund_type'],
|
||
'refund_user' => $params['refund_user'] ?? '',
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : '',
|
||
'collection_bank' => $params['collection_bank'],
|
||
'collection_account' => $params['collection_account'],
|
||
'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 2023/12/14 16:58
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return FinanceRefundApply::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/14 16:58
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = FinanceRefundApply::field('id,refund_code,project_id,contract_id,refund_date,reason,amount,refund_type,refund_user,remark,annex,collection_bank,collection_account,bank_account_id')
|
||
->findOrEmpty($params['id']);
|
||
$project = Project::field('custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||
$custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty();
|
||
$contract = Contract::field('contract_name,contract_code')->where('id',$data['contract_id'])->findOrEmpty();
|
||
$data['project_name'] = $project['name'];
|
||
$data['project_code'] = $project['project_code'];
|
||
$data['custom_name'] = $custom['name'];
|
||
$data['contract_name'] = $contract['contract_name'];
|
||
$data['contract_code'] = $contract['contract_code'];
|
||
$data['refund_type_text'] = $data->refund_type_text;
|
||
$data['bank_account_info'] = BankAccount::field('account_sn,deposit_bank,account_name,account')->where('id',$data['bank_account_id'])->findOrEmpty();
|
||
return $data->toArray();
|
||
}
|
||
} |