201 lines
8.0 KiB
PHP
201 lines
8.0 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\ProcurementContract;
|
||
use app\common\model\contract\SubcontractingContract;
|
||
use app\common\model\finance\FinancePaymentApply;
|
||
use app\common\model\finance\FinancePaymentPlan;
|
||
use app\common\model\oa\FlowApprove;
|
||
use app\common\model\project\Project;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\supplier\Supplier;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* FinancePaymentApply逻辑
|
||
* Class FinancePaymentApplyLogic
|
||
* @package app\adminapi\logic\finance
|
||
*/
|
||
class FinancePaymentApplyLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/15 13:47
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
if($params['contract_cate'] == 1){
|
||
$contract = ProcurementContract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty()->toArray();
|
||
}elseif($params['contract_cate'] == 2){
|
||
$contract = SubcontractingContract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty()->toArray();
|
||
}else{
|
||
self::setError('合同信息不存在');
|
||
return false;
|
||
}
|
||
Db::startTrans();
|
||
try {
|
||
$res = FinancePaymentApply::create([
|
||
'payment_apply_code' => data_unique_code('付款申请'),
|
||
'supplier_id' => $params['supplier_id'],
|
||
'project_id' => $contract['project_id'],
|
||
'contract_type' => $params['contract_cate'],
|
||
'contract_id' => $params['contract_id'],
|
||
'finance_payment_plan_id' => $params['finance_payment_plan_id'],
|
||
'pay_date' => strtotime($params['pay_date']),
|
||
'payment_nature' => $params['payment_nature'],
|
||
'pay_type' => $params['pay_type'],
|
||
'apply_user' => $params['apply_user'] ?? '',
|
||
'invoice_status' => $params['invoice_status'],
|
||
'amount' => $params['amount'],
|
||
'desc' => $params['desc'] ?? '',
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
'payee_bank' => $params['payee_bank'],
|
||
'payee_account_name' => $params['payee_account_name'],
|
||
'payee_account' => $params['payee_account'],
|
||
'bank_account_id' => $params['bank_account_id'],
|
||
]);
|
||
//添加审批信息
|
||
addApprove(
|
||
'付款申请',
|
||
$res->id,
|
||
'app\common\model\finance\FinancePaymentApply',
|
||
'app\adminapi\logic\finance\FinancePaymentApplyLogic',
|
||
$params['approve_detail']['path'],
|
||
$params['approve_detail']['flow_type'],
|
||
$params['approve_detail']['flow_path'],
|
||
$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 2023/12/15 13:47
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
if($params['contract_cate'] == 1){
|
||
$contract = ProcurementContract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty()->toArray();
|
||
}elseif($params['contract_cate'] == 2){
|
||
$contract = SubcontractingContract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty()->toArray();
|
||
}else{
|
||
self::setError('合同信息不存在');
|
||
return false;
|
||
}
|
||
Db::startTrans();
|
||
try {
|
||
FinancePaymentApply::where('id', $params['id'])->update([
|
||
'supplier_id' => $params['supplier_id'],
|
||
'project_id' => $contract['project_id'],
|
||
'contract_type' => $params['contract_cate'],
|
||
'contract_id' => $params['contract_id'],
|
||
'finance_payment_plan_id' => $params['finance_payment_plan_id'],
|
||
'pay_date' => strtotime($params['pay_date']),
|
||
'payment_nature' => $params['payment_nature'],
|
||
'pay_type' => $params['pay_type'],
|
||
'apply_user' => $params['apply_user'] ?? '',
|
||
'invoice_status' => $params['invoice_status'],
|
||
'amount' => $params['amount'],
|
||
'desc' => $params['desc'] ?? '',
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
'payee_bank' => $params['payee_bank'],
|
||
'payee_account_name' => $params['payee_account_name'],
|
||
'payee_account' => $params['payee_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/15 13:47
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return FinancePaymentApply::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/15 13:47
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = FinancePaymentApply::findOrEmpty($params['id']);
|
||
$data['payment_nature_text'] = $data->payment_nature_text;
|
||
$data['pay_type_text'] = $data->pay_type_text;
|
||
$data['invoice_status_text'] = $data->invoice_status_text;
|
||
$supplier = Supplier::field('supplier_name,supplier_code')->where('id',$data['supplier_id'])->findOrEmpty();
|
||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||
$finance_payment_plan = FinancePaymentPlan::field('period')->where('id',$data['finance_payment_plan_id'])->findOrEmpty();
|
||
$data['supplier_name'] = $supplier['supplier_name'];
|
||
$data['supplier_code'] = $supplier['supplier_code'];
|
||
$data['project_name'] = $project['name'];
|
||
$data['project_code'] = $project['project_code'];
|
||
$data['contract_cate'] = $data['contract_type'];
|
||
$data['contract_type_text'] = $data->contract_type_text;
|
||
if($data['contract_type'] == 1){
|
||
$contract = ProcurementContract::field('contract_no,contract_name')->where('id',$data['contract_id'])->findOrEmpty();
|
||
}else{
|
||
$contract = SubcontractingContract::field('contract_no,contract_name')->where('id',$data['contract_id'])->findOrEmpty();
|
||
}
|
||
$data['contract_no'] = $contract['contract_no'];
|
||
$data['contract_name'] = $contract['contract_name'];
|
||
$data['period'] = $finance_payment_plan->period_text;
|
||
$data['bank_account_info'] = BankAccount::field('account_sn,deposit_bank,account_name,account')->where('id',$data['bank_account_id'])->findOrEmpty();
|
||
$approve_info = FlowApprove::field('id')->where('content_id',$params['id'])
|
||
->where('content_model','app\common\model\finance\FinancePaymentApply')
|
||
->where('content_logic','app\adminapi\logic\finance\FinancePaymentApplyLogic')->findOrEmpty();
|
||
$data['approve_id'] = $approve_info['id'];
|
||
return $data->toArray();
|
||
}
|
||
} |