281 lines
12 KiB
PHP
281 lines
12 KiB
PHP
<?php
|
|
|
|
namespace app\model;
|
|
|
|
use think\Db;
|
|
|
|
class Charge extends Base
|
|
{
|
|
|
|
public function getList($where = [], $order = [], $paginate = []) {
|
|
$field = [
|
|
'charge_id',
|
|
'report_no',
|
|
'account_manager_name',
|
|
'bank',
|
|
'bank_branch',
|
|
'bank_sub_branch',
|
|
'city',
|
|
'region',
|
|
'building_name',
|
|
'estate_num',
|
|
'inquiry_type',
|
|
'assessment_purpose',
|
|
'order_src',
|
|
'estate_area',
|
|
'assessment_total',
|
|
'taxation_total_one',
|
|
'taxation_total_two',
|
|
'loan_total',
|
|
'loan_type',
|
|
'is_confirm',
|
|
'collection_status',
|
|
'receivable',
|
|
'received',
|
|
'confirm_amount',
|
|
'uncollected_amount',
|
|
'check_amount',
|
|
'charge_status',
|
|
'check_time',
|
|
'report_completion_time',
|
|
'department_name',
|
|
'department_manager_name',
|
|
'account_manager_name',
|
|
'salesman_name',
|
|
'business_type'
|
|
];
|
|
|
|
$data = Charge::where($where)
|
|
->field($field)
|
|
->order($order)
|
|
->paginate($paginate)
|
|
->each(function ($item,$key){
|
|
$item['inquiry_type_str'] = getDictionaryName('INQUIRY_TYPE', $item['inquiry_type']);
|
|
$item['is_confirm_str'] = getDictionaryName('IS_CONFIRM', $item['is_confirm']);
|
|
$item['collection_status_str'] = getDictionaryName('COLLECTION_STATUS', $item['collection_status']);
|
|
$item['charge_status_str'] = getDictionaryName('CHARGE_STATUS', $item['charge_status']);
|
|
$item['account_manager_name'] = $item['bank'].$item['bank_sub_branch'];
|
|
$item['business_source_str'] = getDictionaryName('BUSINESS_SOURCE', $item['order_src']);
|
|
$item['business_type'] = $item['business_type']==1?'个贷':'对公';
|
|
// 实结单时间
|
|
$item['real_check_time'] = '';
|
|
if ($item['charge_status'] == 3) {
|
|
$item['real_check_time'] = $item['check_time'];
|
|
}
|
|
$item['estate_name_array']=[];
|
|
if(!empty($item['building_name'])){
|
|
$temp['show']=explode(',',$item['building_name'])[0];
|
|
$temp['array']=explode(',',$item['building_name']);
|
|
$item['estate_name_array']=$temp;
|
|
}
|
|
// 业务确认收款账户信息
|
|
$item['bank_account_info_str'] = '';
|
|
$bank_account_id = Db::name('income_expenditure_detail')->where(['report_no'=>$item['report_no']])->order('id desc')->find();
|
|
if ($bank_account_id) {
|
|
$bank_account_info = Db::name('bank_account')->where(['id'=>$bank_account_id['bank_account_id']])->find();
|
|
if ($bank_account_info) {
|
|
$item['bank_account_info_str'] = $bank_account_info['bank_account'].'-'.$bank_account_info['bank_card'].'-'.$bank_account_info['bank'];
|
|
}
|
|
}
|
|
return $item;
|
|
})->toArray();
|
|
$data['count'] = $data['total'];
|
|
$data['receivable_sum'] = number_format($this->getSum($where, 'receivable'));
|
|
$data['received_sum'] = number_format($this->getSum($where, 'received'));
|
|
$data['confirmed_sum'] = number_format($this->getSum($where, 'confirm_amount'));
|
|
$data['check_sum'] = number_format($this->getSum($where, 'check_amount'));
|
|
$data['uncollected_sum'] = number_format($this->getSum($where,'uncollected_amount'));
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 通过报告获取Charge数据
|
|
*
|
|
* @param [type] $report_no 报告号
|
|
* @return object Array|Null
|
|
*/
|
|
public function getInfoByReportNo( $report_no )
|
|
{
|
|
return $this->where('report_no',$report_no)->find();
|
|
}
|
|
|
|
// 统计金额
|
|
public function getSum($where = [], $field_sum) {
|
|
return Charge::where($where)->sum($field_sum);
|
|
}
|
|
|
|
// 更新确认金额
|
|
public function updConfirmAmount($where, $data) {
|
|
return Charge::save($data, $where);
|
|
}
|
|
|
|
public function getSummaryList($where = [], $order = [], $paginate = []) {
|
|
$field = [
|
|
'a.charge_id',
|
|
'a.report_no',
|
|
'a.order_no',
|
|
'a.account_manager_name',
|
|
'a.bank',
|
|
'a.bank_branch',
|
|
'a.bank_sub_branch',
|
|
'a.city',
|
|
'a.region',
|
|
'a.building_name',
|
|
'a.assessment_purpose',
|
|
'a.assessment_total',
|
|
'a.is_confirm',
|
|
'a.collection_status',
|
|
'a.receivable',
|
|
'a.received',
|
|
'a.confirm_amount',
|
|
'a.uncollected_amount',
|
|
'a.check_amount',
|
|
'a.charge_status',
|
|
'a.check_time',
|
|
'a.report_completion_time',
|
|
'a.salesman_name',
|
|
'a.department_name',
|
|
'a.order_src',
|
|
'a.is_housing_fund',
|
|
'a.pay_type',
|
|
'a.confirm_time',
|
|
'a.business_type',
|
|
// 'b.refund_id',
|
|
// 'b.refund_type',
|
|
// 'b.refund_amount',
|
|
// 'b.refund_status'
|
|
];
|
|
$data = $this->alias('a')
|
|
// ->leftJoin('refund b', 'a.report_no=b.report_no')
|
|
->where($where)
|
|
->field($field)
|
|
->order($order)
|
|
->paginate($paginate)
|
|
->each(function ($item, $key){
|
|
$item['is_confirm_str'] = getDictionaryName('IS_CONFIRM', $item['is_confirm']);
|
|
$item['collection_status_str'] = getDictionaryName('COLLECTION_STATUS', $item['collection_status']);
|
|
$item['charge_status_str'] = getDictionaryName('CHARGE_STATUS', $item['charge_status']);
|
|
$item['business_source_str'] = getDictionaryName('BUSINESS_SOURCE', $item['order_src']);
|
|
$item['is_housing_fund'] = $item['is_housing_fund']==1?'是':'否';
|
|
$item['pay_type'] = $item['pay_type']==1?'月结':'个人';
|
|
$item['business_type'] = $item['business_type']==1?'个贷':'对公';
|
|
$item['bank_customer_mgr_name'] = $item['bank'].$item['bank_sub_branch'];
|
|
// 实结单时间
|
|
$item['real_check_time'] = '';
|
|
if ($item['charge_status'] == 3) {
|
|
$item['real_check_time'] = $item['check_time'];
|
|
}
|
|
$item['estate_name_array']=[];
|
|
if(!empty($item['building_name'])){
|
|
$temp['show']=explode(',',$item['building_name'])[0];
|
|
$temp['array']=explode(',',$item['building_name']);
|
|
$item['estate_name_array']=$temp;
|
|
}
|
|
// 申请退报告费
|
|
$refund_tui_result = Db::name('refund')
|
|
->where(['report_no'=>$item['report_no'], 'refund_status'=>4, 'refund_type'=>1])
|
|
->field('refund_id,refund_type,refund_amount,refund_status')
|
|
->order('refund_id', 'desc')
|
|
->find();
|
|
if ($refund_tui_result) {
|
|
$item['tui_refund_id'] = $refund_tui_result['refund_id'];
|
|
$item['tui_refund_type'] = $refund_tui_result['refund_type'];
|
|
$item['tui_refund_amount'] = $refund_tui_result['refund_amount'];
|
|
$item['tui_refund_status'] = $refund_tui_result['refund_status'];
|
|
$item['tui_amount'] = $refund_tui_result['refund_amount'];
|
|
$item['tui_refund_type_str'] = getDictionaryName('REFUND_TYPE', $refund_tui_result['refund_type']);
|
|
} else {
|
|
$item['tui_amount'] = 0;
|
|
}
|
|
// 申请优惠
|
|
$refund_you_result = Db::name('refund')
|
|
->where(['order_no'=>$item['order_no'], 'refund_status'=>4, 'refund_type'=>2])
|
|
->field('refund_id,refund_type,refund_amount,refund_status')
|
|
->order('refund_id', 'desc')
|
|
->find();
|
|
if ($refund_you_result) {
|
|
$item['youhui_refund_id'] = $refund_you_result['refund_id'];
|
|
$item['youhui_refund_type'] = $refund_you_result['refund_type'];
|
|
$item['youhui_refund_amount'] = $refund_you_result['refund_amount'];
|
|
$item['youhui_refund_status'] = $refund_you_result['refund_status'];
|
|
$item['youhui_amount'] = $refund_you_result['refund_amount'];
|
|
$item['youhui_refund_type_str'] = getDictionaryName('REFUND_TYPE', $refund_you_result['refund_type']);
|
|
} else {
|
|
$item['youhui_amount'] = 0;
|
|
}
|
|
return $item;
|
|
})
|
|
->toArray();
|
|
$data['count'] = $data['total'];
|
|
$data['receivable_sum'] = number_format($this->getSummarySum($where, 'a.receivable'));
|
|
$data['received_sum'] = number_format($this->getSummarySum($where, 'a.received'));
|
|
$data['confirmed_sum'] = number_format($this->getSummarySum($where, 'a.confirm_amount'));
|
|
$data['check_sum'] = number_format($this->getSummarySum($where, 'a.check_amount'));
|
|
$data['uncollected_sum'] = number_format($this->getSummarySum($where,'a.uncollected_amount'));
|
|
return $data;
|
|
}
|
|
|
|
// 汇总列表统计金额
|
|
public function getSummarySum($where = [], $field_sum) {
|
|
return $this->alias('a')->where($where)->sum($field_sum);
|
|
}
|
|
|
|
/**
|
|
* 修改结单状态
|
|
* @param $charge_id
|
|
* @param $charge_status
|
|
* @return bool
|
|
*/
|
|
public function updStatementStatus($charge_id, $charge_status) {
|
|
$charge_ids = [];
|
|
if (strpos($charge_id, ',') !== false) {
|
|
$charge_ids = explode(',', $charge_id);
|
|
} else {
|
|
$charge_ids[] = $charge_id;
|
|
}
|
|
return $this->save(['charge_status'=>$charge_status, 'check_time'=>date('Y-m-d H:i:s')], ['charge_id'=>$charge_ids]);
|
|
}
|
|
|
|
public function getSimpleReportList($where = [], $order = [], $paginate = []) {
|
|
$field = [
|
|
'charge_id',
|
|
'report_no',
|
|
'building_name',
|
|
'inquiry_type',
|
|
'estate_area',
|
|
'eva_unit_price',
|
|
'assessment_total',
|
|
'simple_collection_status',
|
|
'receivable',
|
|
'confirm_amount',
|
|
'confirm_time',
|
|
'inquiry_time',
|
|
'salesman_name',
|
|
'department_name',
|
|
'report_completion_time'
|
|
];
|
|
$data = Charge::where($where)
|
|
->field($field)
|
|
->order($order)
|
|
->paginate($paginate)
|
|
->each(function ($item,$key){
|
|
$item['inquiry_type_str'] = getDictionaryName('INQUIRY_TYPE', $item['inquiry_type']);
|
|
$item['simple_collection_status_str'] = getDictionaryName('SIMPLE_COLLECTION_STATUS', $item['simple_collection_status']);
|
|
$item['estate_name_array'] = [];
|
|
if (!empty($item['building_name'])) {
|
|
$temp['show']=explode(',',$item['building_name'])[0];
|
|
$temp['array']=explode(',',$item['building_name']);
|
|
$item['estate_name_array']=$temp;
|
|
}
|
|
if (strpos($item['assessment_total'], '/') !== false) {
|
|
$assessment_total_array = explode('/', $item['assessment_total']);
|
|
$item['assessment_total'] = number_format(array_sum($assessment_total_array), '2');
|
|
}
|
|
return $item;
|
|
})->toArray();
|
|
$data['count'] = $data['total'];
|
|
return $data;
|
|
}
|
|
|
|
}
|