This commit is contained in:
weiz 2024-01-12 11:41:53 +08:00
parent a0453d3251
commit dc94d7ed58
4 changed files with 153 additions and 67 deletions

View File

@ -16,8 +16,12 @@ namespace app\adminapi\lists\finance;
use app\adminapi\lists\BaseAdminDataLists;
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\lists\ListsSearchInterface;
use app\common\model\project\Project;
/**
@ -38,7 +42,8 @@ class FinanceRefundApplyLists extends BaseAdminDataLists implements ListsSearchI
public function setSearch(): array
{
return [
'=' => ['customer_id', 'contract_id', 'collection_acccount'],
'=' => ['project_id', 'contract_id', 'refund_type'],
'%like%' => ['refund_user']
];
}
@ -54,14 +59,29 @@ class FinanceRefundApplyLists extends BaseAdminDataLists implements ListsSearchI
*/
public function lists(): array
{
return FinanceRefundApply::where($this->searchWhere)
->alias('f')
->join('custom c', 'c.id = f.customer_id')
->join('project p', 'p.id = f.contract_id')
->field(['f.*','c.name as custom_name','p.name as project_name','p.project_code'])
$params = $this->request->get(['custom_id']);
$where = [];
if(isset($params['custom_id']) && $params['custom_id'] != ''){
$project_ids = Project::where('custom_id',$params['custom_id'])->column('id');
$where[] = ['project_id','in',$project_ids];
}
return FinanceRefundApply::where($this->searchWhere)->where($where)
->field('id,refund_code,project_id,contract_id,refund_date,reason,amount,refund_type,refund_user,remark,collection_bank,collection_account,bank_account_id')
->limit($this->limitOffset, $this->limitLength)
->order(['f.id' => 'desc'])
->select()
->order(['id' => 'desc'])
->select()->each(function($data){
$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'] = $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();
}
@ -74,7 +94,13 @@ class FinanceRefundApplyLists extends BaseAdminDataLists implements ListsSearchI
*/
public function count(): int
{
return FinanceRefundApply::where($this->searchWhere)->count();
$params = $this->request->get(['custom_id']);
$where = [];
if(isset($params['custom_id']) && $params['custom_id'] != ''){
$project_ids = Project::where('custom_id',$params['custom_id'])->column('id');
$where[] = ['project_id','in',$project_ids];
}
return FinanceRefundApply::where($this->searchWhere)->where($where)->count();
}
}

View File

@ -15,8 +15,12 @@
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;
@ -38,24 +42,24 @@ class FinanceRefundApplyLogic extends BaseLogic
*/
public static function add(array $params): bool
{
$contract = Contract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty();
Db::startTrans();
try {
FinanceRefundApply::create([
'customer_id' => $params['customer_id'] ?? 0,
'contract_id' => $params['contract_id'] ?? 0,
'approve_id' => $params['approve_id'] ?? 0,
'refund_date' => $params['refund_date'] ?? '',
'reason' => $params['reason'] ?? '',
'amount' => $params['amount'] ?? 0,
'amount_daxie' => $params['amount_daxie'] ?? '',
'refund_type' => $params['refund_type'] ?? 0,
'refunder' => $params['refunder'] ?? '',
'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'] ?? '',
'collection_bank' => $params['collection_bank'] ?? '',
'collection_acccount' => $params['collection_acccount'] ?? ''
'annex' => !empty($params['annex']) ? $params['annex'] : null,
'collection_bank' => $params['collection_bank'],
'collection_account' => $params['collection_account'],
'bank_account_id' => $params['bank_account_id'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
@ -75,24 +79,24 @@ class FinanceRefundApplyLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
$contract = Contract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty();
Db::startTrans();
try {
FinanceRefundApply::create([
'customer_id' => $params['customer_id'] ?? 0,
'contract_id' => $params['contract_id'] ?? 0,
'approve_id' => $params['approve_id'] ?? 0,
'refund_date' => $params['refund_date'] ?? '',
'reason' => $params['reason'] ?? '',
'amount' => $params['amount'] ?? 0,
'amount_daxie' => $params['amount_daxie'] ?? '',
'refund_type' => $params['refund_type'] ?? 0,
'refunder' => $params['refunder'] ?? '',
'remark' => $params['remark'] ?? '',
'annex' => $params['annex'] ?? '',
'collection_bank' => $params['collection_bank'] ?? '',
'collection_acccount' => $params['collection_acccount'] ?? ''
'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' => !empty($params['annex']) ? $params['annex'] : null,
'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) {
@ -125,20 +129,18 @@ class FinanceRefundApplyLogic extends BaseLogic
*/
public static function detail($params): array
{
$financeRefundApply = FinanceRefundApply::findOrEmpty($params['id']);
$financeRefundApply->contract;
$financeRefundApply->custom;
$financeRefundApply->document = null;
$financeRefundApply->project = null;
if (!empty($financeRefundApply->contract->document)) {
$financeRefundApply->document = $financeRefundApply->contract->document;
unset($financeRefundApply->contract->document);
}
if (!empty($financeRefundApply->document->project)) {
$financeRefundApply->project = $financeRefundApply->document->project;
unset($financeRefundApply->document->project);
}
$financeRefundApply->annex = json_decode($financeRefundApply->annex, true);
return $financeRefundApply->toArray();
$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();
}
}

View File

@ -15,6 +15,9 @@
namespace app\adminapi\validate\finance;
use app\common\model\bank\BankAccount;
use app\common\model\contract\Contract;
use app\common\model\dict\DictData;
use app\common\validate\BaseValidate;
@ -32,9 +35,15 @@ class FinanceRefundApplyValidate extends BaseValidate
*/
protected $rule = [
'id' => 'require',
'customer_id' => 'require',
'contract_id' => 'require',
'approve_id' => 'require',
'contract_id' => 'require|checkContract',
'refund_date' => 'require|dateFormat:Y-m-d',
'reason' => 'require',
'amount' => 'require|float|gt:0',
'refund_type' => 'require|checkRefundType',
'annex' => 'checkAnnex',
'collection_bank' => 'require',
'collection_account' => 'require',
'bank_account_id' => 'require|checkBankAccount',
];
@ -44,6 +53,14 @@ class FinanceRefundApplyValidate extends BaseValidate
*/
protected $field = [
'id' => 'id',
'contract_id' => '项目合同',
'refund_date' => '退款日期',
'reason' => '退款原因',
'amount' => '退款金额',
'refund_type' => '退款方式',
'collection_bank' => '收款银行',
'collection_account' => '收款账号',
'bank_account_id' => '付款银行账号'
];
@ -66,9 +83,7 @@ class FinanceRefundApplyValidate extends BaseValidate
* @date 2023/12/14 16:58
*/
public function sceneEdit()
{
return $this->only(['id', 'customer_id', 'contract_id', 'approve_id']);
}
{}
/**
@ -93,5 +108,43 @@ class FinanceRefundApplyValidate extends BaseValidate
{
return $this->only(['id']);
}
public function checkContract($value): bool|string
{
$data = Contract::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目合同不存在';
}
return true;
}
public function checkRefundType($value): bool|string
{
$dict = DictData::where('type_value','refund_type')->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;
}
}

View File

@ -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,15 +30,19 @@ class FinanceRefundApply extends BaseModel
use SoftDelete;
protected $name = 'finance_refund_apply';
protected $deleteTime = 'delete_time';
public function custom()
{
return $this->belongsTo(\app\common\model\custom\Custom::class, 'customer_id');
}
public function contract()
{
return $this->belongsTo(\app\common\model\contract\Contract::class, 'contract_id');
}
public function getAnnexAttr($value){
return !empty($value) ? json_decode($value,true) : '';
}
public function getRefundTypeTextAttr($value,$data){
$dict = DictData::where('type_value','refund_type')->column('name','value');
return $dict[$data['refund_type']];
}
public function getRefundDateAttr($value): string
{
return !empty($value) ? date('Y-m-d',$value) : '';
}
}