Merge pull request 'update' (#163) from zhangwei into dev
Reviewed-on: #163
This commit is contained in:
commit
69adca47bd
@ -16,9 +16,9 @@
|
||||
namespace app\adminapi\controller\finance;
|
||||
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\finance\FinancePaymentApplyLists;
|
||||
use app\adminapi\logic\finance\FinancePaymentApplyLogic;
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\finance\FinancePaymentApplyLists;
|
||||
use app\adminapi\logic\finance\FinancePaymentApplyLogic;
|
||||
use app\adminapi\validate\finance\FinancePaymentApplyValidate;
|
||||
|
||||
|
||||
|
@ -16,8 +16,13 @@ namespace app\adminapi\lists\finance;
|
||||
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\contract\ProcurementContract;
|
||||
use app\common\model\contract\SubcontractingContract;
|
||||
use app\common\model\finance\FinancePaymentApply;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\finance\FinancePaymentPlan;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -39,7 +44,8 @@ class FinancePaymentApplyLists extends BaseAdminDataLists implements ListsSearch
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['fpa.supplier_id', 'fpa.contract_id', 'fpa.pay_date', 'fpa.payment_plan_id', 'fpa.payment_natrue', 'fpa.pay_type', 'fpa.applier', 'fpa.invoice_status'],
|
||||
'=' => ['supplier_id', 'project_id', 'contract_type', 'contract_id', 'payment_plan_id', 'payment_nature', 'pay_type', 'invoice_status'],
|
||||
'%like%' => ['apply_user']
|
||||
];
|
||||
}
|
||||
|
||||
@ -55,22 +61,29 @@ class FinancePaymentApplyLists extends BaseAdminDataLists implements ListsSearch
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return Db::name('FinancePaymentApply')->alias('fpa')
|
||||
->where($this->searchWhere)
|
||||
->whereNull('fpa.delete_time')
|
||||
->leftJoin('procurement_contract pc','pc.id = fpa.contract_id')
|
||||
->leftJoin('project p','p.id = pc.project_id')
|
||||
->field('fpa.*, p.id as project_id, p.name as project_name, p.project_code, pc.contract_no')
|
||||
return FinancePaymentApply::where($this->searchWhere)
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['fpa.id' => 'desc'])
|
||||
->select()->each(function($item, $key){
|
||||
//关联数据后续添加
|
||||
$item['supplier_name'] = '供应商名称';
|
||||
$item['contract_type'] = '1';
|
||||
$item['approve_no'] = '付款单号';
|
||||
$item['approve_step'] = '流程步骤';
|
||||
$item['approve_settle_status'] = 1;
|
||||
return $item;
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($data){
|
||||
$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'];
|
||||
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;
|
||||
return $data;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
@ -84,11 +97,7 @@ class FinancePaymentApplyLists extends BaseAdminDataLists implements ListsSearch
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Db::name('FinancePaymentApply')->alias('fpa')
|
||||
->where($this->searchWhere)
|
||||
->whereNull('fpa.delete_time')
|
||||
->leftJoin('procurement_contract pc','pc.id = fpa.contract_id')
|
||||
->leftJoin('project p','p.id = pc.project_id')->count();
|
||||
return FinancePaymentApply::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
@ -15,9 +15,14 @@
|
||||
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\project\Project;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -39,29 +44,37 @@ class FinancePaymentApplyLogic extends BaseLogic
|
||||
*/
|
||||
public static function add(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::create([
|
||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||
'contract_id' => $params['contract_id'] ?? 0,
|
||||
'approve_id' => $params['approve_id'] ?? 0,
|
||||
'pay_date' => $params['pay_date'] ?? '',
|
||||
'period' => $params['period'] ?? 0,
|
||||
'payment_plan_id' => $params['payment_plan_id'] ?? 0,
|
||||
'payment_natrue' => $params['payment_natrue'] ?? 0,
|
||||
'pay_type' => $params['pay_type'] ?? 0,
|
||||
'applier' => $params['applier'] ?? '',
|
||||
'invoice_status' => $params['invoice_status'] ?? 0,
|
||||
'amount' => $params['amount'] ?? 0,
|
||||
'amount_daxie' => $params['amount_daxie'] ?? '',
|
||||
'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'] ?? '',
|
||||
'bank' => $params['bank'] ?? '',
|
||||
'account_name' => $params['account_name'] ?? '',
|
||||
'account' => $params['account'] ?? '',
|
||||
'annex' => !empty($params['annex']) ? $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'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -81,27 +94,36 @@ class FinancePaymentApplyLogic extends BaseLogic
|
||||
*/
|
||||
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'] ?? 0,
|
||||
'contract_id' => $params['contract_id'] ?? 0,
|
||||
'approve_id' => $params['approve_id'] ?? 0,
|
||||
'pay_date' => $params['pay_date'] ?? '',
|
||||
'period' => $params['period'] ?? 0,
|
||||
'payment_plan_id' => $params['payment_plan_id'] ?? 0,
|
||||
'payment_natrue' => $params['payment_natrue'] ?? 0,
|
||||
'pay_type' => $params['pay_type'] ?? 0,
|
||||
'applier' => $params['applier'] ?? '',
|
||||
'invoice_status' => $params['invoice_status'] ?? 0,
|
||||
'amount' => $params['amount'] ?? 0,
|
||||
'amount_daxie' => $params['amount_daxie'] ?? '',
|
||||
'desc' => $params['desc'] ?? '',
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => $params['annex'] ?? '',
|
||||
'bank' => $params['bank'] ?? '',
|
||||
'account_name' => $params['account_name'] ?? '',
|
||||
'account' => $params['account'] ?? '',
|
||||
'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' => !empty($params['annex']) ? $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();
|
||||
@ -136,16 +158,26 @@ class FinancePaymentApplyLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$financePaymentApply = FinancePaymentApply::findOrEmpty($params['id']);
|
||||
$financePaymentApply->contract;
|
||||
$financePaymentApply->plan;
|
||||
// 供应商关联数据后续添加
|
||||
$financePaymentApply->supplier = null;
|
||||
$financePaymentApply->project = null;
|
||||
if (!empty($financePaymentApply->contract->project_id)) {
|
||||
$financePaymentApply->project = Project::findOrEmpty($financePaymentApply->contract->project_id);
|
||||
}
|
||||
$financePaymentApply->annex = json_decode($financePaymentApply->annex, true);
|
||||
return $financePaymentApply->toArray();
|
||||
$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'];
|
||||
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();
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
@ -15,6 +15,12 @@
|
||||
namespace app\adminapi\validate\finance;
|
||||
|
||||
|
||||
use app\common\model\bank\BankAccount;
|
||||
use app\common\model\contract\ProcurementContract;
|
||||
use app\common\model\contract\SubcontractingContract;
|
||||
use app\common\model\dict\DictData;
|
||||
use app\common\model\finance\FinancePaymentPlan;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
@ -32,12 +38,20 @@ class FinancePaymentApplyValidate extends BaseValidate
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'supplier_id' => 'require',
|
||||
'contract_id' => 'require',
|
||||
'approve_id' => 'require',
|
||||
'pay_date' => 'require',
|
||||
'pay_type' => 'require',
|
||||
'amount' => 'require',
|
||||
'supplier_id' => 'require|checkSupplier',
|
||||
'contract_cate' => 'require|in:1,2',
|
||||
'contract_id' => 'require|checkContract',
|
||||
'finance_payment_plan_id' => 'require|checkFinancePaymentPlan',
|
||||
'pay_date' => 'require|dateFormat:Y-m-d',
|
||||
'payment_nature' => 'require|checkPaymentNature',
|
||||
'pay_type' => 'require|checkPayType',
|
||||
'invoice_status' => 'require|checkInvoiceStatus',
|
||||
'amount' => 'require|float|gt:0',
|
||||
'annex' => 'checkAnnex',
|
||||
'payee_bank' => 'require',
|
||||
'payee_account_name' => 'require',
|
||||
'payee_account' => 'require',
|
||||
'bank_account_id' => 'require|checkBankAccount',
|
||||
];
|
||||
|
||||
|
||||
@ -47,11 +61,19 @@ class FinancePaymentApplyValidate extends BaseValidate
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'supplier_id' => '供应商id',
|
||||
'contract_id' => '合同id',
|
||||
'pay_date' => '付款日期',
|
||||
'pay_type' => '付款方式',
|
||||
'amount' => '本次申请金额',
|
||||
'supplier_id' => '供应商id',
|
||||
'contract_cate' => '合同类型',
|
||||
'contract_id' => '合同id',
|
||||
'finance_payment_plan_id' => '付款计划id',
|
||||
'pay_date' => '付款日期',
|
||||
'payment_nature' => '付款性质',
|
||||
'pay_type' => '付款方式',
|
||||
'invoice_status' => '开票状态',
|
||||
'amount' => '本次申请金额',
|
||||
'payee_bank' => '收款人开户银行',
|
||||
'payee_account_name' => '收款人开户名称',
|
||||
'payee_account' => '收款人账号',
|
||||
'bank_account_id' => '付款银行账户id',
|
||||
];
|
||||
|
||||
|
||||
@ -63,7 +85,7 @@ class FinancePaymentApplyValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['supplier_id','contract_id','pay_date','pay_type','amount']);
|
||||
return $this->remove('id',true);
|
||||
}
|
||||
|
||||
|
||||
@ -74,9 +96,7 @@ class FinancePaymentApplyValidate extends BaseValidate
|
||||
* @date 2023/12/15 13:47
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','supplier_id','contract_id','pay_date','pay_type','amount']);
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
@ -101,5 +121,91 @@ class FinancePaymentApplyValidate extends BaseValidate
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkSupplier($value): bool|string
|
||||
{
|
||||
$supplier = Supplier::where('id',$value)->findOrEmpty();
|
||||
if($supplier->isEmpty()){
|
||||
return '供应商信息不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkContract($value,$rule,$data): bool|string
|
||||
{
|
||||
if($data['contract_cate'] == 1){
|
||||
$contract = ProcurementContract::where('id',$value)->findOrEmpty()->toArray();
|
||||
}elseif($data['contract_cate'] == 2){
|
||||
$contract = SubcontractingContract::where('id',$value)->findOrEmpty()->toArray();
|
||||
}else{
|
||||
$contract = [];
|
||||
}
|
||||
if(empty($contract)){
|
||||
return '合同信息不存在';
|
||||
}
|
||||
if($contract['supplier_id'] != $data['supplier_id']){
|
||||
return '合同信息无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkFinancePaymentPlan($value,$rule,$data): bool|string
|
||||
{
|
||||
$payment_plan = FinancePaymentPlan::where('id',$value)->findOrEmpty();
|
||||
if($payment_plan->isEmpty()){
|
||||
return '付款计划信息不存在';
|
||||
}
|
||||
if($payment_plan['contract_id'] != $data['contract_id'] || $payment_plan['contract_type'] != $data['contract_cate']){
|
||||
return '付款计划信息无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkPaymentNature($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','payment_natrue')->column('value');
|
||||
if(!in_array($value,$dict)){
|
||||
return '付款性质无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkPayType($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','pay_type')->column('value');
|
||||
if(!in_array($value,$dict)){
|
||||
return '付款方式无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkInvoiceStatus($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','invoice_status')->column('value');
|
||||
if(!in_array($value,$dict)){
|
||||
return '开票状态无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkAnnex($value): bool|string
|
||||
{
|
||||
if(!empty($value) && $value != ''){
|
||||
$annex = json_decode($value,true);
|
||||
if(empty($annex) || !is_array($annex)){
|
||||
return '附件格式错误';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkBankAccount($value): bool|string
|
||||
{
|
||||
$bank = BankAccount::where('id',$value)->findOrEmpty();
|
||||
if($bank->isEmpty()){
|
||||
return '付款银行账户信息不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ namespace app\common\model\finance;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\dict\DictData;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
@ -29,14 +30,34 @@ class FinancePaymentApply extends BaseModel
|
||||
use SoftDelete;
|
||||
protected $name = 'finance_payment_apply';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
public function contract()
|
||||
{
|
||||
return $this->belongsTo(\app\common\model\contract\ProcurementContract::class, 'contract_id');
|
||||
}
|
||||
|
||||
public function plan()
|
||||
{
|
||||
return $this->hasOne(FinancePaymentPlan::class, 'id','payment_plan_id');
|
||||
}
|
||||
|
||||
public function getAnnexAttr($value){
|
||||
return !empty($value) ? json_decode($value,true) : '';
|
||||
}
|
||||
|
||||
public function getContractTypeTextAttr($value,$data): string
|
||||
{
|
||||
$type = [1=>'采购合同',2=>'分包合同'];
|
||||
return $type[$data['contract_type']];
|
||||
}
|
||||
|
||||
public function getPaymentNatureTextAttr($value,$data){
|
||||
$dict = DictData::where('type_value','payment_natrue')->column('name','value');
|
||||
return $dict[$data['payment_nature']];
|
||||
}
|
||||
|
||||
public function getPayTypeTextAttr($value,$data){
|
||||
$dict = DictData::where('type_value','pay_type')->column('name','value');
|
||||
return $dict[$data['pay_type']];
|
||||
}
|
||||
|
||||
public function getInvoiceStatusTextAttr($value,$data){
|
||||
$dict = DictData::where('type_value','invoice_status')->column('name','value');
|
||||
return $dict[$data['invoice_status']];
|
||||
}
|
||||
|
||||
public function getPayDateAttr($value): string
|
||||
{
|
||||
return !empty($value) ? date('Y-m-d',$value) : '';
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user