update
This commit is contained in:
parent
a9cf9b768f
commit
b8faf0954e
@ -16,9 +16,9 @@
|
||||
namespace app\adminapi\controller\finance;
|
||||
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\finance\FinanceReturnedRecordLists;
|
||||
use app\adminapi\logic\finance\FinanceReturnedRecordLogic;
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\finance\FinanceReturnedRecordLists;
|
||||
use app\adminapi\logic\finance\FinanceReturnedRecordLogic;
|
||||
use app\adminapi\validate\finance\FinanceReturnedRecordValidate;
|
||||
|
||||
|
||||
|
@ -16,8 +16,13 @@ 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\FinanceReturnedMoney;
|
||||
use app\common\model\finance\FinanceReturnedRecord;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\project\Project;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
@ -38,7 +43,7 @@ class FinanceReturnedRecordLists extends BaseAdminDataLists implements ListsSear
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['frr.customer_id', 'frr.contract_id', 'frr.finance_returned_money_id'],
|
||||
'=' => ['project_id', 'contract_id', 'finance_returned_money_id', 'collection_type', 'invoice_status', 'pay_type'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -54,18 +59,32 @@ class FinanceReturnedRecordLists extends BaseAdminDataLists implements ListsSear
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return Db::name('FinanceReturnedRecord')->alias('frr')
|
||||
->where($this->searchWhere)
|
||||
->whereNull('frr.delete_time')
|
||||
->leftJoin('contract c','c.id = frr.contract_id')
|
||||
->leftJoin('bid_buy_bidding_document bbbd','bbbd.id = c.buy_bidding_document_id')
|
||||
->leftJoin('project p','p.id = bbbd.project_id')
|
||||
->leftJoin('custom ct','ct.id = c.customer_id')
|
||||
->field('frr.*, bbbd.project_id, c.contract_code, c.contract_name, c.contract_type, p.name as project_name, p.project_code, ct.name as customer_name')
|
||||
$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 FinanceReturnedRecord::where($this->searchWhere)->where($where)
|
||||
->field('id,project_id,contract_id,finance_returned_money_id,return_date,amount,collection_type,invoice_status,pay_type,receiver,bank_account_id')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['frr.id' => 'desc'])
|
||||
->select()->each(function($item, $key){
|
||||
return $item;
|
||||
->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();
|
||||
$finance_returned_money = FinanceReturnedMoney::field('period')->where('id',$data['finance_returned_money_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['period'] = $finance_returned_money->period_text;
|
||||
$data['collection_type'] = $data->collection_type_text;
|
||||
$data['invoice_status'] = $data->invoice_status_text;
|
||||
$data['pay_type'] = $data->pay_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();
|
||||
}
|
||||
@ -79,13 +98,13 @@ class FinanceReturnedRecordLists extends BaseAdminDataLists implements ListsSear
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Db::name('FinanceReturnedRecord')->alias('frr')
|
||||
->where($this->searchWhere)
|
||||
->whereNull('frr.delete_time')
|
||||
->leftJoin('contract c','c.id = frr.contract_id')
|
||||
->leftJoin('bid_buy_bidding_document bbbd','bbbd.id = c.buy_bidding_document_id')
|
||||
->leftJoin('project p','p.id = bbbd.project_id')
|
||||
->leftJoin('custom ct','ct.id = c.customer_id')->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 FinanceReturnedRecord::where($this->searchWhere)->where($where)->count();
|
||||
}
|
||||
|
||||
}
|
@ -15,8 +15,13 @@
|
||||
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\FinanceReturnedMoney;
|
||||
use app\common\model\finance\FinanceReturnedRecord;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\project\Project;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -38,28 +43,24 @@ class FinanceReturnedRecordLogic extends BaseLogic
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
$contract = Contract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty();
|
||||
Db::startTrans();
|
||||
try {
|
||||
FinanceReturnedRecord::create([
|
||||
'customer_id' => $params['customer_id'],
|
||||
'project_id' => $contract['project_id'],
|
||||
'contract_id' => $params['contract_id'],
|
||||
'finance_returned_money_id' => $params['finance_returned_money_id'],
|
||||
'return_date' => $params['return_date'],
|
||||
'period' => $params['period'],
|
||||
'return_date' => strtotime($params['return_date']),
|
||||
'amount' => $params['amount'],
|
||||
'collection_type' => $params['collection_type'],
|
||||
'invoice_status' => $params['invoice_status'],
|
||||
'pay_type' => $params['pay_type'],
|
||||
'return_total_amount' => $params['return_total_amount'],
|
||||
'return_desc' => $params['return_desc'],
|
||||
'receiver' => $params['receiver'],
|
||||
'payee_id' => $params['payee_id'],
|
||||
'is_interest' => $params['is_interest'],
|
||||
'interest_date' => $params['interest_date'],
|
||||
'remark' => $params['remark'],
|
||||
'annex' => $params['annex'],
|
||||
'return_desc' => $params['return_desc'] ?? '',
|
||||
'receiver' => $params['receiver'] ?? '',
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => !empty($params['annex']) ? $params['annex'] : null,
|
||||
'bank_account_id' => $params['bank_account_id'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -79,28 +80,25 @@ class FinanceReturnedRecordLogic extends BaseLogic
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
$contract = Contract::field('project_id')->where('id',$params['contract_id'])->findOrEmpty();
|
||||
Db::startTrans();
|
||||
try {
|
||||
FinanceReturnedRecord::where('id', $params['id'])->update([
|
||||
'customer_id' => $params['customer_id'],
|
||||
'contract_id' => $params['contract_id'],
|
||||
'finance_returned_money_id' => $params['finance_returned_money_id'],
|
||||
'return_date' => $params['return_date'],
|
||||
'period' => $params['period'],
|
||||
'amount' => $params['amount'],
|
||||
'collection_type' => $params['collection_type'],
|
||||
'invoice_status' => $params['invoice_status'],
|
||||
'pay_type' => $params['pay_type'],
|
||||
'return_total_amount' => $params['return_total_amount'],
|
||||
'return_desc' => $params['return_desc'],
|
||||
'receiver' => $params['receiver'],
|
||||
'payee_id' => $params['payee_id'],
|
||||
'is_interest' => $params['is_interest'],
|
||||
'interest_date' => $params['interest_date'],
|
||||
'remark' => $params['remark'],
|
||||
'annex' => $params['annex'],
|
||||
'project_id' => $contract['project_id'],
|
||||
'contract_id' => $params['contract_id'],
|
||||
'finance_returned_money_id' => $params['finance_returned_money_id'],
|
||||
'return_date' => strtotime($params['return_date']),
|
||||
'amount' => $params['amount'],
|
||||
'collection_type' => $params['collection_type'],
|
||||
'invoice_status' => $params['invoice_status'],
|
||||
'pay_type' => $params['pay_type'],
|
||||
'return_desc' => $params['return_desc'] ?? '',
|
||||
'receiver' => $params['receiver'] ?? '',
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => !empty($params['annex']) ? $params['annex'] : null,
|
||||
'bank_account_id' => $params['bank_account_id'],
|
||||
'update_time' => time(),
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -133,21 +131,22 @@ class FinanceReturnedRecordLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$financeReturnedRecord = FinanceReturnedRecord::findOrEmpty($params['id']);
|
||||
$financeReturnedRecord->contract;
|
||||
$financeReturnedRecord->custom;
|
||||
$financeReturnedRecord->plan = $financeReturnedRecord->returnedPlan;
|
||||
$financeReturnedMoney['document'] = null;
|
||||
$financeReturnedMoney['project'] = null;
|
||||
if (!empty($financeReturnedMoney['contract']['document'])) {
|
||||
$financeReturnedMoney['document'] = $financeReturnedMoney['contract']['document'];
|
||||
unset($financeReturnedMoney['contract']['document']);
|
||||
}
|
||||
if (!empty($financeReturnedMoney['document']['project'])) {
|
||||
$financeReturnedMoney['project'] = $financeReturnedMoney['document']['project'];
|
||||
unset($financeReturnedMoney['document']['project']);
|
||||
}
|
||||
unset($financeReturnedRecord->returnedPlan);
|
||||
return $financeReturnedRecord->toArray();
|
||||
$data = FinanceReturnedRecord::field('id,project_id,contract_id,finance_returned_money_id,return_date,amount,collection_type,invoice_status,pay_type,return_desc,receiver,remark,annex,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();
|
||||
$finance_returned_money = FinanceReturnedMoney::field('period')->where('id',$data['finance_returned_money_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['period'] = $finance_returned_money->period_text;
|
||||
$data['collection_type_text'] = $data->collection_type_text;
|
||||
$data['invoice_status_text'] = $data->invoice_status_text;
|
||||
$data['pay_type_text'] = $data->pay_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();
|
||||
}
|
||||
}
|
@ -15,6 +15,10 @@
|
||||
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\model\finance\FinanceReturnedMoney;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
@ -32,8 +36,15 @@ class FinanceReturnedRecordValidate extends BaseValidate
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'customer_id' => 'require',
|
||||
'contract_id' => 'require',
|
||||
'contract_id' => 'require|checkContract',
|
||||
'finance_returned_money_id' => 'require|checkReturnedMoney',
|
||||
'return_date' => 'require|dateFormat:Y-m-d',
|
||||
'collection_type' => 'require|checkCollectionType',
|
||||
'amount' => 'require|float|gt:0',
|
||||
'invoice_status' => 'require|checkInvoiceStatus',
|
||||
'pay_type' => 'require|checkPayType',
|
||||
'annex' => 'checkAnnex',
|
||||
'bank_account_id' => 'require|checkBankAccount',
|
||||
];
|
||||
|
||||
|
||||
@ -43,6 +54,14 @@ class FinanceReturnedRecordValidate extends BaseValidate
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'contract_id' => '项目合同',
|
||||
'finance_returned_money_id' => '回款计划',
|
||||
'return_date' => '日期',
|
||||
'collection_type' => '收款性质',
|
||||
'amount' => '金额',
|
||||
'invoice_status' => '开票状态',
|
||||
'pay_type' => '付款方式',
|
||||
'bank_account_id' => '银行账号',
|
||||
];
|
||||
|
||||
|
||||
@ -65,9 +84,7 @@ class FinanceReturnedRecordValidate extends BaseValidate
|
||||
* @date 2023/12/13 16:28
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id', 'customer_id', 'contract_id', 'finance_returned_money_id']);
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
@ -92,5 +109,73 @@ class FinanceReturnedRecordValidate 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 checkReturnedMoney($value,$rule,$data): bool|string
|
||||
{
|
||||
$return_money = FinanceReturnedMoney::where('id',$value)->findOrEmpty();
|
||||
if($return_money->isEmpty()){
|
||||
return '回款计划信息不存在';
|
||||
}
|
||||
if($return_money['contract_id'] != $data['contract_id']){
|
||||
return '回款计划信息无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkCollectionType($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','collection_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 checkPayType($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','pay_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;
|
||||
}
|
||||
|
||||
}
|
@ -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,20 +30,28 @@ class FinanceReturnedRecord extends BaseModel
|
||||
use SoftDelete;
|
||||
protected $name = 'finance_returned_record';
|
||||
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 returnedPlan()
|
||||
{
|
||||
return $this->belongsTo(\app\common\model\finance\FinanceReturnedMoney::class, 'finance_returned_money_id');
|
||||
}
|
||||
|
||||
|
||||
public function getAnnexAttr($value){
|
||||
return !empty($value) ? json_decode($value,true) : '';
|
||||
}
|
||||
|
||||
public function getCollectionTypeTextAttr($value,$data){
|
||||
$dict = DictData::where('type_value','collection_type')->column('name','value');
|
||||
return $dict[$data['collection_type']];
|
||||
}
|
||||
|
||||
public function getInvoiceStatusTextAttr($value,$data){
|
||||
$dict = DictData::where('type_value','invoice_status')->column('name','value');
|
||||
return $dict[$data['invoice_status']];
|
||||
}
|
||||
|
||||
public function getPayTypeTextAttr($value,$data){
|
||||
$dict = DictData::where('type_value','pay_type')->column('name','value');
|
||||
return $dict[$data['pay_type']];
|
||||
}
|
||||
|
||||
public function getReturnDateAttr($value): string
|
||||
{
|
||||
return !empty($value) ? date('Y-m-d',$value) : '';
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user