1286 lines
61 KiB
PHP
1286 lines
61 KiB
PHP
<?php
|
||
/**
|
||
* 财务管理
|
||
*/
|
||
|
||
namespace app\admin\controller;
|
||
use app\model\Charge as ChargeModel;
|
||
use app\model\Income;
|
||
use app\util\ReturnCode;
|
||
use think\Cache;
|
||
use think\Db;
|
||
use think\facade\Env;
|
||
use think\Response;
|
||
use app\common\validate\RefundValidate;
|
||
use app\model\Attachment;
|
||
use app\admin\service\ChargeService;
|
||
use app\lib\AuthApi;
|
||
|
||
class Charge extends Base
|
||
{
|
||
//构造函数
|
||
public function __construct(){
|
||
if($_SERVER['REQUEST_METHOD'] == 'OPTIONS'){
|
||
header("Access-Control-Allow-Origin: *");
|
||
header("Access-Control-Allow-Headers: userId, ApiAuth, Category, User-Agent, Keep-Alive, Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With");
|
||
header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS,PATCH');
|
||
header('Access-Control-Allow-Credentials:true');
|
||
exit;
|
||
}
|
||
parent::__construct();
|
||
}
|
||
|
||
/**
|
||
* 收费管理财务待确认列表
|
||
*/
|
||
public function getTobeConfirmedList() {
|
||
$data = $this->getTobeConfirmedData();
|
||
return $this->buildSuccess($data);
|
||
}
|
||
|
||
public function getTobeConfirmedData(){
|
||
$charge_service = new ChargeService();
|
||
$map = $charge_service->searchCondition();
|
||
$map[] = ['is_confirm', '=', 2];
|
||
$map[] = ['collection_status', '<>', 3];
|
||
|
||
$charge = new ChargeModel();
|
||
$order = ['report_completion_time'];
|
||
return $charge->getList($map, $order, $this->getPage());
|
||
}
|
||
|
||
/**
|
||
* 待确认列表导出
|
||
*/
|
||
public function tobeConfirmedExport() {
|
||
$data = $this->getTobeConfirmedDataExport();
|
||
$indexKey = ['report_no', 'account_manager_name', 'city', 'region', 'building_name', 'assessment_purpose', 'is_confirm_str', 'collection_status_str', 'receivable', 'received', 'confirm_amount', 'uncollected_amount', 'check_amount', 'charge_status_str', 'real_check_time', 'report_completion_time', 'salesman_name'];
|
||
$indexValue = ['报告编号', '银行', '城市', '城区', '物业名称', '评估目的','实收状态', '收款状态', '应收金额', '实收金额', '确认金额', '未收金额', '实结单金额', '结单状态', '实结单日期', '出报告日期', '业务员'];
|
||
(new ChargeManage())->exportExcel($data['data'], 'unconfirm_'.date('Ymd'), $indexKey, $indexValue);
|
||
}
|
||
|
||
public function getTobeConfirmedDataExport(){
|
||
$charge_service = new ChargeService();
|
||
$map = $charge_service->searchCondition();
|
||
$map[] = ['is_confirm', '=', 2];
|
||
$map[] = ['collection_status', '<>', 3];
|
||
|
||
$charge = new ChargeModel();
|
||
$order = ['report_completion_time'];
|
||
return $charge->getList($map, $order, ['list_rows' => 10000000, 'page' => 1]);
|
||
}
|
||
|
||
/**
|
||
* 待确认列表查看详细
|
||
*/
|
||
public function getWaitDetail() {
|
||
$charge_id = $this->request->param('charge_id');
|
||
if (empty($charge_id)) {
|
||
return $this->buildFailed('参数错误');
|
||
}
|
||
$data = $this->getChargeDetail($charge_id);
|
||
return $this->buildSuccess($data);
|
||
}
|
||
|
||
/**
|
||
* 查看收费详细(共用)
|
||
* @param $charge_id
|
||
* @return array
|
||
*/
|
||
public function getChargeDetail($charge_id) {
|
||
$map['charge_id'] = $charge_id;
|
||
// 收费详情
|
||
$charge_data = (new ChargeModel())->getList($map);
|
||
|
||
// 收支明细
|
||
$income_data = Income::getAll($map);
|
||
|
||
return ['charge_data' => $charge_data['data'][0], 'income_data' => $income_data];
|
||
}
|
||
|
||
/**
|
||
* 查看转账凭证
|
||
*/
|
||
public function getTransferVoucherById() {
|
||
$map = [];
|
||
$id = $this->request->param('id');
|
||
if (!empty($id)) {
|
||
$map['id'] = $id;
|
||
} else {
|
||
return $this->buildFailed('参数错误');
|
||
}
|
||
|
||
$field = [
|
||
'transfer_voucher'
|
||
];
|
||
$data = Income::where($map)->field($field)->find();
|
||
if ($data['transfer_voucher']) {
|
||
$attachment = (new Attachment())->getUrls($data['transfer_voucher']);
|
||
return $this->buildSuccess(['img'=>$attachment]);
|
||
} else {
|
||
return $this->buildFailed('查无凭证');
|
||
}
|
||
}
|
||
|
||
public function getTransferVoucherByChargeId() {
|
||
$map = [];
|
||
$charge_id = $this->request->param('charge_id');
|
||
if (!empty($charge_id)) {
|
||
$map['charge_id'] = $charge_id;
|
||
$map['type'] = 1;
|
||
} else {
|
||
return $this->buildFailed('参数错误');
|
||
}
|
||
|
||
$field = [
|
||
'transfer_voucher'
|
||
];
|
||
$data = Income::where($map)->field($field)->find();
|
||
if ($data['transfer_voucher']) {
|
||
$attachment = (new Attachment())->getUrls($data['transfer_voucher']);
|
||
return $this->buildSuccess(['img'=>$attachment]);
|
||
} else {
|
||
return $this->buildFailed('查无凭证');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 财务确认收款
|
||
*/
|
||
public function updConfirmAmount() {
|
||
$ids = $this->request->param('ids');
|
||
if (empty($ids)) {
|
||
return $this->buildFailed('请选择需要确认金额的数据!');
|
||
}
|
||
$is_equal = $this->request->param('is_equal', 1); // 确认金额是否等于应收,1:是,2:否
|
||
|
||
$map = [];
|
||
$charge = new ChargeModel();
|
||
$income = new Income();
|
||
if ($is_equal == 1) {
|
||
$id_arr = [];
|
||
if (strpos($ids, ',') !== false) {
|
||
$id_arr = explode(',', $ids);
|
||
} else {
|
||
$id_arr[] = $ids;
|
||
}
|
||
Db::startTrans();
|
||
foreach ($id_arr as $value) {
|
||
$map['charge_id'] = $value;
|
||
$field = [
|
||
'report_no',
|
||
'receivable',
|
||
'received'
|
||
];
|
||
// 验证业务员实收金额是否等于应收金额
|
||
$res = ChargeModel::getOne($map, $field);
|
||
if ($res['receivable'] == $res['received']) {
|
||
$upd_charge_data = [
|
||
'confirm_amount' => $res['receivable'],
|
||
'uncollected_amount' => 0,
|
||
'collection_status' => 3
|
||
];
|
||
$charge_result = ChargeModel::where($map)->update($upd_charge_data);
|
||
$upd_income_data = [
|
||
'finance_id' => $this->userInfo['user_id'],
|
||
'finance_confirm_name' => $this->userInfo['user_name'],
|
||
'finance_confirm_amount' => $res['receivable'],
|
||
'confirm_time' => date('Y-m-d H:i:s')
|
||
];
|
||
$income_result = Income::where(['charge_id'=>$value, 'type'=>1])->update($upd_income_data);
|
||
if ($charge_result && $income_result) {
|
||
Db::commit();
|
||
} else {
|
||
Db::rollback();
|
||
return $this->buildFailed('确认金额失败!');
|
||
}
|
||
} else {
|
||
Db::rollback();
|
||
return $this->buildFailed('报告编号为'.$res['report_no'].'的应收金额不等于确认金额!');
|
||
}
|
||
}
|
||
} elseif($is_equal == 2) {
|
||
$confirm_amount = $this->request->param('confirm_amount');
|
||
if (empty($confirm_amount)) {
|
||
return $this->buildFailed('请输入确认金额!');
|
||
}
|
||
Db::startTrans();
|
||
$map['charge_id'] = $ids;
|
||
$field = [
|
||
'report_no',
|
||
'receivable',
|
||
'received',
|
||
'confirm_amount'
|
||
];
|
||
$res = ChargeModel::getOne($map, $field);
|
||
if ($res['received'] == $res['confirm_amount'] + $confirm_amount) {
|
||
if ($res['received'] != $res['receivable']) {
|
||
$upd_charge_data = [
|
||
'confirm_amount' => $res['received'],
|
||
'uncollected_amount' => $res['receivable'] - $res['received'],
|
||
'collection_status' => 2,
|
||
'is_confirm' => 1
|
||
];
|
||
} else {
|
||
$upd_charge_data = [
|
||
'confirm_amount' => $res['received'],
|
||
'uncollected_amount' => $res['receivable'] - $res['received'],
|
||
'collection_status' => 3
|
||
];
|
||
}
|
||
$charge->updConfirmAmount($map, $upd_charge_data);
|
||
$upd_income_data = [
|
||
'finance_id' => $this->userInfo['user_id'],
|
||
'finance_confirm_name' => $this->userInfo['user_name'],
|
||
'finance_confirm_amount' => $confirm_amount,
|
||
'confirm_time' => date('Y-m-d H:i:s')
|
||
];
|
||
$income_id = Income::getOne(['charge_id'=>$ids, 'type'=>1], 'id', ['id'=>'desc']);
|
||
$income->updConfirmAmount(['id'=>$income_id['id']], $upd_income_data);
|
||
if ($charge && $income) {
|
||
Db::commit();
|
||
} else {
|
||
Db::rollback();
|
||
return $this->buildFailed('确认金额失败!');
|
||
}
|
||
} else {
|
||
return $this->buildFailed('报告编号为'.$res['report_no'].'的实收金额不等于确认金额!');
|
||
}
|
||
} else {
|
||
return $this->buildFailed('参数错误');
|
||
}
|
||
return Response::create(['code'=>1, 'msg'=>'确认收款成功'], 'json');
|
||
}
|
||
|
||
/**
|
||
* 获取业务部下所有部门
|
||
*/
|
||
public function getBusinessDeparts() {
|
||
// 获取业务部id
|
||
$business_department_id = getDictionaryCode('DEPARTMENT', '业务部');
|
||
if (!$business_department_id) {
|
||
return $this->buildFailed('查无数据,请确认字典数据表是否设置业务部相关数据');
|
||
}
|
||
|
||
$data = [
|
||
'departIds' => $business_department_id['code'],
|
||
'access_token' => $this->token
|
||
];
|
||
$Auth = new AuthApi();
|
||
|
||
$result = $Auth->getBusinessDepartment($data);
|
||
$result = json_decode($result,true);
|
||
if($result["code"] == 0)
|
||
return $this->buildSuccess($result['data'], '成功');
|
||
else
|
||
return $this->buildFailed($result['msg'],$result['msg']);
|
||
}
|
||
|
||
/**
|
||
* 收费汇总列表
|
||
*/
|
||
public function getSummaryList() {
|
||
$data = $this->getSummaryData();
|
||
return $this->buildSuccess($data);
|
||
}
|
||
|
||
public function getSummaryData() {
|
||
$charge_service = new ChargeService();
|
||
$map = $charge_service->summarySearchCondition();
|
||
|
||
$charge = new ChargeModel();
|
||
$order = ['a.report_completion_time'];
|
||
return $charge->getSummaryList($map, $order, $this->getPage());
|
||
}
|
||
|
||
/**
|
||
* 收费汇总列表导出
|
||
*/
|
||
public function summaryExport() {
|
||
$data = $this->getSummaryDataExport();
|
||
$indexKey = ['report_no', 'account_manager_name', 'city', 'region', 'building_name', 'assessment_purpose', 'business_source_str', 'is_housing_fund', 'pay_type', 'business_type', 'is_confirm_str', 'collection_status_str', 'receivable', 'received', 'confirm_amount', 'uncollected_amount', 'check_amount', 'charge_status_str', 'real_check_time', 'report_completion_time', 'salesman_name', 'department_name', 'youhui_amount', 'tui_amount'];
|
||
$indexValue = ['报告编号', '银行', '城市', '城区', '物业名称', '评估目的', '业务来源', '是否公积金', '收费方式', '业务类别', '实收状态', '收款状态', '应收金额', '实收金额', '确认金额', '未收金额', '实结单金额', '结单状态', '实结单时间', '出报告日期', '业务员', '部门', '优惠金额', '退费金额'];
|
||
(new ChargeManage())->exportExcel($data['data'], 'summary_'.date('Ymd'), $indexKey, $indexValue);
|
||
}
|
||
|
||
public function getSummaryDataExport() {
|
||
$charge_service = new ChargeService();
|
||
$map = $charge_service->summarySearchCondition();
|
||
|
||
$charge = new ChargeModel();
|
||
$order = ['a.report_completion_time'];
|
||
return $charge->getSummaryList($map, $order, ['list_rows' => 10000000, 'page' => 1]);
|
||
}
|
||
|
||
/**
|
||
* 汇总列表查看详细
|
||
*/
|
||
public function getSummaryDetail() {
|
||
$charge_id = $this->request->param('charge_id');
|
||
if (empty($charge_id)) {
|
||
return $this->buildFailed('参数错误');
|
||
}
|
||
$data = $this->getChargeDetail($charge_id);
|
||
// 查询开票数据
|
||
$bill_data = Db::name('charge')
|
||
->alias('a')
|
||
->join('bill b', 'a.report_no=b.report_no')
|
||
->join('bill_detail c', 'b.bill_id=c.bill_id')
|
||
->where(['a.charge_id'=>$charge_id])
|
||
->field('b.bill_status,b.bill_type,c.*')
|
||
->paginate()
|
||
->each(function ($item,$key){
|
||
$item['bill_type_str'] = getDictionaryName('BILL_TYPE', $item['bill_type']);
|
||
$item['invoice_type_str'] = getDictionaryName('INVOICE_TYPE', $item['invoice_type']);
|
||
$item['bill_attachment_img']['img'] = $item['bill_attachment']?(new Attachment())->getUrls($item['bill_attachment']):[];
|
||
return $item;
|
||
})
|
||
->toArray();
|
||
if ($bill_data['data']) {
|
||
$data['bill_data'] = $bill_data['data'][0];
|
||
} else {
|
||
$data['bill_data'] = [];
|
||
}
|
||
return $this->buildSuccess($data);
|
||
}
|
||
|
||
/**
|
||
* 申请退费(优惠)详细(共用)
|
||
*/
|
||
public function getRefundDetail() {
|
||
$refund_id = $this->request->param('refund_id');
|
||
if (empty($refund_id)) {
|
||
return $this->buildFailed('参数错误');
|
||
}
|
||
$field = [
|
||
'refund_type',
|
||
'refund_status as approval_node',
|
||
'order_no',
|
||
'report_no',
|
||
'building_name',
|
||
'estate_num',
|
||
'salesman_name',
|
||
'assessment_total',
|
||
'receivable',
|
||
'is_received',
|
||
'create_time',
|
||
'receiving_bank',
|
||
'collection_account',
|
||
'payee',
|
||
'refund_amount',
|
||
'reason',
|
||
'related_document'
|
||
];
|
||
// 退费详细数据
|
||
$refund_detail = Db::name('refund')
|
||
->where(['refund_id'=>$refund_id])
|
||
->field($field)
|
||
->paginate()
|
||
->each(function ($item,$key){
|
||
$item['approval_node_str'] = getDictionaryName('REFUND_STATUS', $item['approval_node']);
|
||
$item['refund_type_str'] = getDictionaryName('REFUND_TYPE', $item['refund_type']);
|
||
$item['related_document_img']['img'] = $item['related_document']?(new Attachment())->getUrls($item['related_document']):[];
|
||
return $item;
|
||
})
|
||
->toArray();
|
||
// 退费审批记录
|
||
$refund_log = Db::name('refund_approval_log')
|
||
->where(['refund_id'=>$refund_id])
|
||
->field(['approval_id','approver','processing_time','approval_node','approval_results','approval_comments'])
|
||
->paginate()
|
||
->each(function ($item,$key){
|
||
$item['approval_node_str'] = getDictionaryName('REFUND_STATUS', $item['approval_node']);
|
||
$item['approval_results_str'] = $item['approval_results']==1?'通过':'驳回';
|
||
return $item;
|
||
})
|
||
->toArray();
|
||
|
||
return $this->buildSuccess(['refund_detail'=>$refund_detail['data'][0], 'refund_log'=>$refund_log['data']]);
|
||
}
|
||
|
||
/**
|
||
* 业务管理费用申请管理退费列表
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function getBusinessRefundList() {
|
||
$map = [];
|
||
if (!in_array("ROLE_ADMIN", $this->userInfo['roleCode'])) {
|
||
$user_ids = array($this->userInfo['user_id']); // $this->userInfo['user_ids'] ? implode(',', $this->userInfo['user_ids']) : '';
|
||
$map[] = ['salesman_id', 'in', $user_ids];
|
||
}
|
||
$data = $this->getRefundListData($map);
|
||
return $this->buildSuccess($data);
|
||
}
|
||
|
||
/**
|
||
* 费用管理财务管理退费列表
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function getFinanceRefundList() {
|
||
$map = [];
|
||
if (in_array("Finance_CSPG", $this->userInfo['roleCode'])) {
|
||
$map[] = ['refund_status', '=', 3];
|
||
}
|
||
$data = $this->getRefundListData($map);
|
||
return $this->buildSuccess($data);
|
||
}
|
||
|
||
/**
|
||
* 退费列表
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function getRefundList() {
|
||
$map = [];
|
||
if (in_array("Business_manager", $this->userInfo['roleCode'])) {
|
||
$map[] = ['refund_status', '=', 1];
|
||
} elseif (in_array("general_manager", $this->userInfo['roleCode'])) {
|
||
$map[] = ['refund_status', '=', 2];
|
||
}
|
||
|
||
if (!in_array("ROLE_ADMIN", $this->userInfo['roleCode']) && !in_array("Integrated_Management_Manager_CSPG", $this->userInfo['roleCode'])) {
|
||
$user_ids = array($this->userInfo['user_id']);//$this->userInfo['user_ids'] ? implode(',', $this->userInfo['user_ids']) : '';
|
||
$map[] = ['salesman_id', 'in', $user_ids];
|
||
}
|
||
|
||
$data = $this->getRefundListData($map);
|
||
return $this->buildSuccess($data);
|
||
}
|
||
|
||
public function getRefundListData($where = []) {
|
||
if(empty($this->userInfo)){
|
||
return $this->buildFailed("获取退款列表失败,因用户信息为空,请重新登录","",ReturnCode::AUTH_ERROR);
|
||
}
|
||
|
||
$map = $where;
|
||
// 业务员姓名关键字搜索
|
||
$salesman_name = $this->request->param('salesman_name');
|
||
if (!empty($salesman_name)) {
|
||
$map[] = ['salesman_name', 'like', '%'.$salesman_name.'%'];
|
||
}
|
||
// 申请状态
|
||
$refund_status = $this->request->param('refund_status');
|
||
if (!empty($refund_status)) {
|
||
$map[] = ['refund_status', 'like', '%'.$refund_status.'%'];
|
||
}
|
||
// 申请类型
|
||
$refund_type = $this->request->param('refund_type');
|
||
if (!empty($refund_type)) {
|
||
$map[] = ['refund_type', '=', $refund_type];
|
||
}
|
||
// 申请开始时间
|
||
$create_time_start = $this->request->param('create_time_start');
|
||
if (!empty($create_time_start)) {
|
||
$map[] = ['create_time', '>', $create_time_start];
|
||
}
|
||
// 申请结束时间
|
||
$create_time_end = $this->request->param('create_time_end');
|
||
if (!empty($create_time_end)) {
|
||
$map[] = ['create_time', '<', $create_time_end];
|
||
}
|
||
// 物业名称关键字搜索
|
||
$building_name = $this->request->param('building_name');
|
||
if (!empty($building_name)) {
|
||
$map[] = ['building_name', 'like', '%'.$building_name.'%'];
|
||
}
|
||
|
||
$field = [
|
||
'refund_id',
|
||
'order_no',
|
||
'report_no',
|
||
'estate_name',
|
||
'refund_type',
|
||
'refund_status',
|
||
'refund_amount',
|
||
'customer_name',
|
||
'account_manager_name',
|
||
'inquiry_time',
|
||
'salesman_name',
|
||
'create_time'
|
||
];
|
||
|
||
$data = Db::name('refund')
|
||
->where($map)
|
||
->field($field)
|
||
->order('create_time', 'asc')
|
||
->paginate($this->getPage())
|
||
->each(function ($item, $key){
|
||
$item['refund_type_str'] = getDictionaryName('REFUND_TYPE', $item['refund_type']);
|
||
$item['refund_status_str'] = getDictionaryName('REFUND_STATUS', $item['refund_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;
|
||
}
|
||
return $item;
|
||
})
|
||
->toArray();
|
||
$data['count'] = $data['total'];
|
||
return $data;
|
||
}
|
||
|
||
/**
|
||
* 申请退费(优惠)审批
|
||
*/
|
||
public function refundApproval() {
|
||
$refund_id = $this->request->param('refund_id');
|
||
$approval_results = $this->request->param('approval_results', 1);
|
||
$approval_comments = $this->request->param('approval_comments');
|
||
$refund_transfer = $this->request->param('refund_transfer');
|
||
if (empty($refund_id) || empty($approval_results)) {
|
||
return $this->buildFailed('参数错误');
|
||
}
|
||
$refund_data = Db::name('refund')->where(['refund_id'=>$refund_id])->find();
|
||
if (!$refund_data || $refund_data['refund_status']==5) {
|
||
return $this->buildFailed('不存在的申请或申请已被驳回请重新申请退费');
|
||
}
|
||
// 开启事务
|
||
Db::startTrans();
|
||
if ($approval_results == 1) {
|
||
// 审批通过
|
||
if ($refund_data['refund_status'] == 3) {
|
||
// 财务审批通过,退费状态refund_status的值流转为4
|
||
$refund_status = 4;
|
||
if ($refund_data['refund_type'] == 1) {
|
||
if (empty($refund_transfer)) {
|
||
return $this->buildFailed('必须上传转账凭证');
|
||
}
|
||
// 向收入支出记录表插入一条支出类型的记录
|
||
$ins_data = [
|
||
'report_no' => $refund_data['report_no'],
|
||
'content' => '退报告费',
|
||
'type' => 2,
|
||
'amount' => $refund_data['refund_amount'],
|
||
'remark' => $approval_comments,
|
||
'salesman_id' => $refund_data['salesman_id'],
|
||
'salesman_name' => $refund_data['salesman_name'],
|
||
'apply_time' => $refund_data['apply_time'],
|
||
'pay_time' => date('Y-m-d H:i:s'),
|
||
'bank_account_id' => '',
|
||
'transfer_voucher' => implode(',', $refund_transfer),
|
||
'create_time'=> date('Y-m-d H:i:s'),
|
||
'update_time'=> date('Y-m-d H:i:s')
|
||
];
|
||
// 申请退费类型为申请退报告费,更新收费表pg_charge字段confirm_amount的值
|
||
if (Db::name('charge')->where(['report_no'=>$refund_data['report_no']])->find()) {
|
||
$charge_upd = Db::name('charge')->where(['report_no'=>$refund_data['report_no']])->setDec('confirm_amount', $refund_data['refund_amount']);
|
||
if (!$charge_upd) {
|
||
// 事务回滚
|
||
Db::rollback();
|
||
return $this->buildFailed('审批失败');
|
||
}
|
||
$charge_id = ChargeModel::where(['report_no'=>$refund_data['report_no']])->field('charge_id')->find();
|
||
$ins_data['charge_id'] = $charge_id['charge_id'];
|
||
}
|
||
$income_ins = Db::name('income_expenditure_detail')->insert($ins_data);
|
||
if (!$income_ins) {
|
||
// 事务回滚
|
||
Db::rollback();
|
||
return $this->buildFailed('审批失败');
|
||
}
|
||
} else {
|
||
// 申请退费类型为申请优惠,更新收费表pg_charge字段receivable的值
|
||
if (Db::name('charge')->where(['report_no'=>$refund_data['report_no']])->find()) {
|
||
$charge_upd = Db::name('charge')->where(['report_no'=>$refund_data['report_no']])->setDec('receivable', $refund_data['refund_amount']);
|
||
if (!$charge_upd) {
|
||
// 事务回滚
|
||
Db::rollback();
|
||
return $this->buildFailed('审批失败');
|
||
}
|
||
}
|
||
}
|
||
} else {
|
||
// 部门经理审批通过,退费状态refund_status的值流转为2,总经理审批通过退费状态refund_status的值流转为3
|
||
$refund_status = $refund_data['refund_status'] == 1?2:3;
|
||
}
|
||
} else {
|
||
// 审批驳回,退费状态refund_status的值流转为5
|
||
$refund_status = 5;
|
||
}
|
||
|
||
// 更新退费表退费状态
|
||
$refund_upd = Db::name('refund')->where(['refund_id'=>$refund_id])->update(['refund_status'=>$refund_status]);
|
||
|
||
// 插入审批记录
|
||
$log_data = [
|
||
'refund_id' => $refund_id,
|
||
'approver_id' => $this->userInfo['user_id'],
|
||
'approver' => $this->userInfo['user_name'],
|
||
'approval_node' => $refund_data['refund_status'],
|
||
'processing_time' => date('Y-m-d H:i:s'),
|
||
'approval_results' => $approval_results,
|
||
'approval_comments' => $approval_comments,
|
||
'refund_transfer' => $refund_transfer?implode(',', $refund_transfer):'',
|
||
'create_time' => date('Y-m-d H:i:s'),
|
||
'update_time' => date('Y-m-d H:i:s')
|
||
];
|
||
$log_ins = Db::name('refund_approval_log')->insert($log_data);
|
||
|
||
if ($refund_upd && $log_ins) {
|
||
// 事务提交
|
||
Db::commit();
|
||
// 获取询价id
|
||
$quot_id = Db::name('inquiry')->where(['order_no'=>$refund_data['order_no']])->field('id')->find();
|
||
// 写入消息
|
||
if ($approval_results == 1) {
|
||
// 审批通过写入消息
|
||
if ($refund_data['refund_status'] == 1) {
|
||
// 部门经理通过审批写入消息
|
||
PublicMessage($quot_id['id'], 8, 16);
|
||
// 待总经理审批写入消息
|
||
PublicMessage($quot_id['id'], 8, 32);
|
||
} elseif($refund_data['refund_status'] == 2) {
|
||
// 总经理通过审批写入消息
|
||
PublicMessage($quot_id['id'], 8, 18);
|
||
// 待财务审批写入消息
|
||
PublicMessage($quot_id['id'], 8, 20);
|
||
} elseif($refund_data['refund_status'] == 3) {
|
||
// 财务通过审批写入消息
|
||
PublicMessage($quot_id['id'], 9, 21);
|
||
}
|
||
} else {
|
||
// 审批不通过写入消息
|
||
if ($refund_data['refund_status'] == 1) {
|
||
// 部门经理驳回审批写入消息
|
||
PublicMessage($quot_id['id'], 8, 17);
|
||
} elseif($refund_data['refund_status'] == 2) {
|
||
// 总经理驳回审批写入消息
|
||
PublicMessage($quot_id['id'], 8, 19);
|
||
} elseif($refund_data['refund_status'] == 3) {
|
||
// 财务驳回审批写入消息
|
||
PublicMessage($quot_id['id'], 9, 22);
|
||
}
|
||
}
|
||
return Response::create(['code' => 1, 'msg' => '审批成功'], 'json');
|
||
} else {
|
||
// 事务回滚
|
||
Db::rollback();
|
||
return $this->buildFailed('审批失败');
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 校验报告
|
||
*/
|
||
public function checkReportNo(){
|
||
$number = trim($this->request->post('number'));
|
||
$refund_type = $this->request->post('refund_type');
|
||
if(!$number || !$refund_type) return $this->buildFailed('参数错误');
|
||
|
||
if($refund_type == 1){ //申请退报告费
|
||
if(!Db::name('report')->where(['report_no'=>$number])->order('id desc')->find())
|
||
return $this->buildFailed('报告编号错误,无此报告');
|
||
|
||
if(Db::name('report')->alias('r')->join('inquiry i', 'r.quot_id = i.id')->where(['r.report_no'=>$number, 'i.is_simple'=>1])->find())
|
||
return $this->buildFailed('简易报告不可申请');
|
||
|
||
if(!Db::name('report')->alias('r')->join('inquiry i', 'r.quot_id = i.id')->where(['r.report_no'=>$number,'i.user_id'=>$this->userInfo['user_id']])->find())
|
||
return $this->buildFailed('此报告非当前登录业务员,不可申请');
|
||
|
||
if(Db::name('refund')->where('refund_status', '<>', 5)->where(['report_no'=>$number, 'refund_type'=>1])->find())
|
||
return $this->buildFailed('此报告已申请退报告费,不可重复申请');
|
||
|
||
}elseif($refund_type == 2){ //申请优惠
|
||
if(!Db::name('inquiry')->where(['order_no'=>$number])->find())
|
||
return $this->buildFailed('单号错误,无此询价单');
|
||
|
||
if(Db::name('inquiry')->where(['order_no'=>$number, 'is_simple'=>1])->find())
|
||
return $this->buildFailed('简易询价,不可申请');
|
||
|
||
if(!Db::name('inquiry')->where(['order_no'=>$number,'user_id'=>$this->userInfo['user_id']])->find())
|
||
return $this->buildFailed('此单号非当前登录业务员,不可申请');
|
||
|
||
if(Db::name('refund')->where('refund_status', '<>', 5)->where(['order_no'=>$number, 'refund_type'=>1])->find())
|
||
return $this->buildFailed('此订单已申请退报告费,不可重复申请');
|
||
|
||
if(Db::name('refund')->where('refund_status', '<>', 5)->where(['order_no'=>$number,'refund_type'=>2])->find())
|
||
return $this->buildFailed('此订单已申请优惠,不可重复申请');
|
||
}
|
||
|
||
return $this->buildSuccess();
|
||
}
|
||
|
||
/**
|
||
* 申请退费 - 获取相关信息
|
||
*/
|
||
public function getRefund(){
|
||
$number = trim($this->request->post('number'));
|
||
$refund_type = $this->request->post('refund_type');
|
||
if(!$number || !$refund_type) return $this->buildFailed('参数错误');
|
||
if($refund_type == 1){ //申请退报告费详情
|
||
$where['r.report_no'] = $number;
|
||
}else{ //申请优惠详情
|
||
$where['i.order_no'] = $number;
|
||
}
|
||
//报告编号、业务员id、业务员名称
|
||
$subsql = Db::table('pg_return_price')->field('property_cert_info_id,eva_total_value')->group('property_cert_info_id')->order('property_cert_info_id', 'desc')->buildSql();
|
||
$res = Db::name('inquiry')->alias('i')
|
||
->join('property_cert_info d', 'i.id=d.quot_id')
|
||
->join('report r', 'i.id=r.quot_id', 'left')
|
||
->join([$subsql => 'p'], 'd.id = p.property_cert_info_id', 'left')
|
||
->field('i.id,i.type,i.product_id,i.order_no,r.report_no,i.user_id as salesman_id,i.user_name as salesman_name,count(d.id) as estate_num, sum(p.eva_total_value) as assessment_total,group_concat(d.property_full_name) as building_name,r.business_type,i.is_simple')
|
||
->where($where)
|
||
->group('i.order_no')
|
||
->find();
|
||
|
||
//应收金额
|
||
$map[] = ['report_no|order_no', '=', $number];
|
||
$refund_money = Db::name('charge')->where($map)->field('receivable')->find();
|
||
if ($refund_money) {
|
||
$res['receivable'] = $refund_money['receivable'];
|
||
} else {
|
||
$result = $this->getReceivable($res['assessment_total'], $res['product_id'], $res['type'],$res['estate_num'],$res['business_type'],$res['is_simple']);
|
||
$res['receivable'] = $result['receivable'];
|
||
}
|
||
return $this->buildSuccess($res);
|
||
}
|
||
|
||
/**
|
||
* 申请退费
|
||
*/
|
||
public function applyRefund(){
|
||
|
||
$data = $this->request->post();
|
||
if(!isset($data['refund_type']) || !$data['refund_type'])
|
||
return $this->buildFailed('参数错误');
|
||
|
||
|
||
//验证
|
||
$validate = new RefundValidate();
|
||
if($data['refund_type'] == 1){ //申请退报告费
|
||
if (!$validate->scene('companyTicket')->check($data))
|
||
return $this->buildFailed($validate->getError());
|
||
|
||
}elseif($data['refund_type'] == 2 ) { //申请优惠
|
||
|
||
if (!$validate->scene('applyDiscount')->check($data))
|
||
return $this->buildFailed($validate->getError());
|
||
}
|
||
|
||
|
||
if (isset($data['related_document']) && !empty($data['related_document']))
|
||
$data['related_document'] = implode(",", $data['related_document']);
|
||
|
||
$inquiry = Db::name('inquiry')->where(['order_no'=>$data['order_no']])->find();
|
||
$property_cert_info = Db::name('property_cert_info')->where(['quot_id'=>$inquiry['id']])->column('property_full_name');
|
||
$data['building_name'] = $property_cert_info ? implode(',', $property_cert_info) : '';
|
||
$data['receiving_bank'] = $inquiry['bank_name'].$inquiry['bank_branch_name']; //收款银行名称
|
||
$data['account_manager_id'] = $inquiry['bank_customer_mgr_id']; //客户经理id
|
||
$data['account_manager_name'] = $inquiry['bank_customer_mgr_name'];//客户经理名称
|
||
$data['inquiry_time'] = $inquiry['create_time']; //询价时间
|
||
$data['salesman_id'] = $this->userInfo['user_id'];
|
||
$data['salesman_name'] = $this->userInfo['user_name'];
|
||
$data['apply_time'] = date('Y-m-d');
|
||
$data['create_time'] = $data['update_time'] = date('Y-m-d H:i:s');
|
||
|
||
if(!Db::name('refund')->insert($data))
|
||
return $this->buildFailed('申请退费失败');
|
||
|
||
// 写入消息
|
||
PublicMessage($inquiry['id'], 8, 15);
|
||
return $this->buildSuccess();
|
||
}
|
||
|
||
/**
|
||
* 报告制作完成向pg_charge表插入数据
|
||
* @param array $report_id
|
||
* @return array
|
||
*/
|
||
public function insReportData($report_id) {
|
||
// 获取报告表相关字段数据
|
||
$report_field = [
|
||
'id',
|
||
'quot_id', // 询价表id
|
||
'report_no', // 报告编号
|
||
'e_case_code', // 电子提取码
|
||
'order_src', // 业务来源
|
||
'is_housing_fund', // 是否用公积金,1:是,0:否
|
||
'pay_type', // 收费方式,1:月结,2:个人
|
||
'business_type', // 业务类型,1:个贷,2:对公
|
||
'completion_time', // 报告完成时间
|
||
'report_remark_copy'
|
||
];
|
||
$report_result = Db::name('report')
|
||
->where(['id'=>$report_id])
|
||
// ->where(['id'=>$report_id,'status'=>3])
|
||
->field($report_field)
|
||
->find();
|
||
if (!$report_result) {
|
||
return ['result'=>false, 'msg'=>'表pg_report不存在id为'.$report_id.'的记录'];
|
||
}
|
||
$charge = Db::name('charge')->where(['report_no'=>$report_result['report_no']])->find();
|
||
if ($charge) {
|
||
// return ['result'=>false, 'msg'=>'重复的'.$report_result['report_no']];
|
||
return ['result'=>true];
|
||
}
|
||
// 获取询价表相关字段数据
|
||
$inquiry_field = [
|
||
'id',
|
||
'order_no', // 询价单编号
|
||
'user_id', // 业务员id
|
||
'user_name', // 录单员姓名
|
||
'buss_username', // 业务员姓名
|
||
'bank_id', // 银行id
|
||
'bank_name', // 银行名称
|
||
'bank_branch_id', // 分行id
|
||
'bank_branch_name', // 分行名称
|
||
'bank_sub_id', // 支行id
|
||
'bank_sub_name', // 支行名称
|
||
'bank_customer_mgr_id', // 客户经理id
|
||
'bank_customer_mgr_name', // 客户经理姓名
|
||
'department_id', // 部门id
|
||
'department_name', // 部门名称
|
||
'eva_purpose', // 评估目的
|
||
'product_id', // 评估目的id
|
||
'type', // 询价类型,1:住宅,2:商业
|
||
'is_multiple', // 是否多套,0:否,1:是
|
||
'is_simple', // 是否简易询价,1:是,0:否
|
||
'create_time' // 询价时间
|
||
];
|
||
$inquiry_result = Db::name('inquiry')
|
||
->where(['id'=>$report_result['quot_id']])
|
||
->field($inquiry_field)
|
||
->find();
|
||
if (!$inquiry_result) {
|
||
return ['result'=>false, 'msg'=>'表pg_inquiry不存在id为'.$report_result['quot_id'].'的记录'];
|
||
}
|
||
$inquiry_detail_field = ['id', 'city', 'city_id', 'property_full_name', 'building_name', 'survey_user_id', 'survey_user_name'];
|
||
$report_detail_field = ['area_id', 'area', 'property_cert', 'obligee', 'cert_no', 'purchase_date'];
|
||
$return_price_field = [
|
||
'area', // 面积
|
||
'eva_unit_price', // 评估单价
|
||
'eva_total_value', // 评估总值
|
||
'eva_net_value', // 评估净值1
|
||
'eva_net_value2', // 评估净值2
|
||
'total_taxes1', // 税费1合计
|
||
'total_taxes2', // 税费2合计
|
||
'eva_net_value', // 净值1
|
||
'eva_net_value2' // 净值2
|
||
];
|
||
if ($inquiry_result['is_multiple']==1) {
|
||
// 多套
|
||
$inquiry_detail_result = Db::name('property_cert_info')
|
||
->where(['quot_id'=>$inquiry_result['id']])
|
||
->field($inquiry_detail_field)
|
||
->select();
|
||
if (!$inquiry_detail_result) {
|
||
return ['result'=>false, 'msg'=>'表pg_inquiry_detail不存在inquiry_id为'.$inquiry_result['id'].'的记录'];
|
||
}
|
||
|
||
$estate_num = count($inquiry_detail_result);
|
||
$city_id = $inquiry_detail_result[0]['city_id'];
|
||
$city = $inquiry_detail_result[0]['city'];
|
||
$building_name = [];
|
||
$property_full_name = [];
|
||
$survey_username_id = [];
|
||
$survey_user_name = [];
|
||
$property_cert = [];
|
||
$obligee = [];
|
||
$cert_no = [];
|
||
$purchase_date = [];
|
||
$area = [];
|
||
$eva_unit_price = [];
|
||
$eva_total_value = [];
|
||
$assessment_all_value_c = [];
|
||
$eva_net_value = [];
|
||
$eva_net_value2 = [];
|
||
$total_taxes1 = [];
|
||
$total_taxes2 = [];
|
||
$loan_total = [];
|
||
|
||
foreach ($inquiry_detail_result as $key=>$value) {
|
||
$building_name[] = $value['building_name'];
|
||
$property_full_name[] = $value['property_full_name'];
|
||
$survey_username_id[] = $value['survey_user_id'];
|
||
$survey_user_name[] = $value['survey_user_name'];
|
||
|
||
$report_detail_result = Db::name('report_detail')
|
||
->where(['report_id'=>$report_id,'property_cert_info_id'=>$value['id']])
|
||
->field($report_detail_field)
|
||
->find();
|
||
if (!$report_detail_result) {
|
||
return ['result'=>false, 'msg'=>'表pg_report_detail不存在inquiry_detail_id为'.$value['id'].'和report_id为'.$report_id.'的记录'];
|
||
}
|
||
$region_id = $report_detail_result['area_id'];
|
||
$region = $report_detail_result['area'];
|
||
$property_cert[] = $report_detail_result['property_cert'];
|
||
$obligee[] = $report_detail_result['obligee'];
|
||
$cert_no[] = $report_detail_result['cert_no'];
|
||
$purchase_date[] = $report_detail_result['purchase_date'];
|
||
|
||
$return_price_result = Db::name('return_price')
|
||
->where(['property_cert_info_id'=>$value['id']])
|
||
->field($return_price_field)
|
||
->order('id desc')
|
||
->find();
|
||
if (!$return_price_result) {
|
||
return ['result'=>false, 'msg'=>'表pg_return_price不存在inquiry_detail_id为'.$value['id'].'的记录'];
|
||
}
|
||
$area[] = $return_price_result['area'];
|
||
$eva_unit_price[] = number_format($return_price_result['eva_unit_price']);
|
||
$eva_total_value[] = number_format($return_price_result['eva_total_value']); //总值
|
||
$assessment_all_value_c[] = $return_price_result['eva_total_value'];//总值的copy值
|
||
$eva_net_value[] = number_format($return_price_result['eva_net_value']);
|
||
$eva_net_value2[] = number_format($return_price_result['eva_net_value2']);
|
||
$total_taxes1[] = number_format($return_price_result['total_taxes1']);
|
||
$total_taxes2[] = number_format($return_price_result['total_taxes2']);
|
||
if ($return_price_result['eva_net_value'] >= $return_price_result['eva_net_value2']) {
|
||
$loan_total[] = number_format($return_price_result['eva_net_value2']);
|
||
} else {
|
||
$loan_total[] = number_format($return_price_result['eva_net_value']);
|
||
}
|
||
}
|
||
$estate_name_str = implode(',', $building_name);
|
||
$full_estate_name_str = implode(',', $property_full_name);
|
||
$survey_username_id_str = implode('/', $survey_username_id);
|
||
$survey_username_str = implode('/', $survey_user_name);
|
||
$deed_number_str = implode('/', $property_cert);
|
||
$obligee_str = implode('/', $obligee);
|
||
$id_number_str = implode('/', $cert_no);
|
||
$buy_date_str = implode('/', $purchase_date);
|
||
$area_str = implode('/', $area);
|
||
$assessment_price_str = implode('/', $eva_unit_price);
|
||
$assessment_all_value_str = implode('/', $eva_total_value);
|
||
$assessment_net_worth_str = implode('/', $eva_net_value);
|
||
$assessment_net_worth_tow_str = implode('/', $eva_net_value2);
|
||
$total_tax1_str = implode('/', $total_taxes1);
|
||
$total_tax2_str = implode('/', $total_taxes2);
|
||
$loan_total_str = implode('/', $loan_total);
|
||
$assessment_total = array_sum($assessment_all_value_c);
|
||
} else {
|
||
// 单套
|
||
$estate_num = 1;
|
||
$inquiry_detail_result = Db::name('property_cert_info')
|
||
->where(['quot_id'=>$inquiry_result['id']])
|
||
->field($inquiry_detail_field)
|
||
->find();
|
||
if (!$inquiry_detail_result) {
|
||
return ['result'=>false, 'msg'=>'表pg_inquiry_detail不存在inquiry_id为'.$inquiry_result['id'].'的记录'];
|
||
}
|
||
$city_id = $inquiry_detail_result['city_id'];
|
||
$city = $inquiry_detail_result['city'];
|
||
$estate_name_str = $inquiry_detail_result['building_name'];
|
||
$full_estate_name_str = $inquiry_detail_result['property_full_name'];
|
||
$survey_username_id_str = $inquiry_detail_result['survey_user_id'];
|
||
$survey_username_str = $inquiry_detail_result['survey_user_name'];
|
||
|
||
$report_detail_result = Db::name('report_detail')
|
||
->where(['report_id'=>$report_id,'property_cert_info_id'=>$inquiry_detail_result['id']])
|
||
->field($report_detail_field)
|
||
->find();
|
||
if (!$report_detail_result) {
|
||
return ['result'=>false, 'msg'=>'表pg_report_detail不存在inquiry_detail_id为'.$inquiry_detail_result['id'].'和report_id为'.$report_id.'的记录'];
|
||
}
|
||
$region_id = $report_detail_result['area_id'];
|
||
$region = $report_detail_result['area'];
|
||
$deed_number_str = $report_detail_result['property_cert'];
|
||
$obligee_str = $report_detail_result['obligee'];
|
||
$id_number_str = $report_detail_result['cert_no'];
|
||
$buy_date_str = $report_detail_result['purchase_date'];
|
||
|
||
$return_price_result = Db::name('return_price')
|
||
->where(['property_cert_info_id'=>$inquiry_detail_result['id']])
|
||
->field($return_price_field)
|
||
->order('id desc')
|
||
->find();
|
||
if (!$return_price_result) {
|
||
return ['result'=>false, 'msg'=>'表pg_return_price不存在inquiry_detail_id为'.$inquiry_detail_result['id'].'的记录'];
|
||
}
|
||
$area_str = $return_price_result['area'];
|
||
$assessment_price_str = number_format($return_price_result['eva_unit_price']);
|
||
$assessment_all_value_str = number_format($return_price_result['eva_total_value']);
|
||
$assessment_net_worth_str = number_format($return_price_result['eva_net_value']);
|
||
$assessment_net_worth_tow_str = number_format($return_price_result['eva_net_value2']);
|
||
$total_tax1_str = number_format($return_price_result['total_taxes1']);
|
||
$total_tax2_str = number_format($return_price_result['total_taxes2']);
|
||
if ($return_price_result['eva_net_value'] >= $return_price_result['eva_net_value2']) {
|
||
$loan_total_str = number_format($return_price_result['eva_net_value2']);
|
||
} else {
|
||
$loan_total_str = number_format($return_price_result['eva_net_value']);
|
||
}
|
||
$assessment_total = $return_price_result['eva_total_value'];
|
||
}
|
||
// 计算应收金额
|
||
$receivable_data = $this->getReceivable($assessment_total, $inquiry_result['product_id'], $inquiry_result['type'], $estate_num, $report_result['business_type'], $inquiry_result['is_simple']);
|
||
// 报告工本费
|
||
$report_cost = $receivable_data['report_cost'];
|
||
// 应收金额
|
||
$receivable = $receivable_data['receivable'];
|
||
$data = [
|
||
'order_no' => $inquiry_result['order_no'], // 询价单编号
|
||
'report_no' => $report_result['report_no'], // 报告编号
|
||
'report_code' => $report_result['e_case_code'], // 报告电子提取码
|
||
'report_type' => $inquiry_result['type'], // 报告类型(业务类型),1:个贷(住宅),2:商贷(商业)
|
||
'account_manager_id' => '', // 客户id(客户来源id,银行或机构)
|
||
'account_manager_name' => '', // 客户名称
|
||
'city_id' => $city_id, // 城市id
|
||
'city' => $city, // 城市名称
|
||
'region_id' => $region_id, // 城区id
|
||
'region' => $region, // 城区名称
|
||
// 'building_name' => $estate_name_str, // 物业名称,多个物业用逗号隔开
|
||
'building_name' => $full_estate_name_str, // 物业名称,多个物业用逗号隔开
|
||
'estate_num' => $estate_num, // 物业数量
|
||
'estate_area' => $area_str, // 面积,多个物业用'/'隔开
|
||
'assessment_purpose_id' => $inquiry_result['product_id'], // 评估目的字典id
|
||
'assessment_purpose' => $inquiry_result['eva_purpose'], // 评估目的
|
||
'receivable' => $receivable, // 应收金额
|
||
// 'report_completion_time' => date('Y-m-d H:i:s', $report_result['completion_time']), // 出报告时间日期,格式:2020-05-10 12:10:08
|
||
'report_completion_time' => date('Y-m-d H:i:s'), // 出报告时间日期,格式:2020-05-10 12:10:08
|
||
'salesman_id' => $inquiry_result['user_id'], // 业务员id
|
||
'salesman_name' => $inquiry_result['buss_username'], // 业务员姓名
|
||
'department_id' => $inquiry_result['department_id'], // 业务员所属部门id
|
||
'department_name' => $inquiry_result['department_name'], // 业务员所属部门名称
|
||
'bank_id' => $inquiry_result['bank_id'],
|
||
'bank' => $inquiry_result['bank_name'], // 银行名称
|
||
'bank_branch_id' => $inquiry_result['bank_branch_id'],
|
||
'bank_branch' => $inquiry_result['bank_branch_name'], // 分行名称
|
||
'bank_sub_branch_id' => $inquiry_result['bank_sub_id'],
|
||
'bank_sub_branch' => $inquiry_result['bank_sub_name'], // 支行名称
|
||
'account_manager_id' => $inquiry_result['bank_customer_mgr_id'], // 客户经理id
|
||
'account_manager_name' => $inquiry_result['bank_customer_mgr_name'], // 客户经理姓名
|
||
'department_manager_id' => '', // 业务员所属部门的部门经理id
|
||
'department_manager_name' => '', // 业务员所属部门的部门经理姓名
|
||
'eva_unit_price' => $assessment_price_str, // 评估单价,多个物业用'/'隔开
|
||
'assessment_total' => $assessment_all_value_str, // 评估总值,多个物业用'/'隔开
|
||
'taxation_total_one' => $total_tax1_str, // 税费1合计,多个物业用'/'隔开
|
||
'taxation_total_two' => $total_tax2_str, // 税费2合计,多个物业用'/'隔开
|
||
'assessment_net_total_one' => $assessment_net_worth_str, // 评估净值1,多个物业用'/'隔开
|
||
'assessment_net_total_two' => $assessment_net_worth_tow_str, // 评估净值2,多个物业用'/'隔开
|
||
'loan_total' => $loan_total_str, // 贷款金额
|
||
'loan_type' => $inquiry_result['type'], // 贷款类型,1:个贷,2:商贷
|
||
'inquiry_type' => $inquiry_result['type'], // 询价类型,1:住宅,2:商业
|
||
'inquiry_time' => $inquiry_result['create_time'], // 询价时间
|
||
'obligee' => $obligee_str, // 权利人,多套用'/'隔开
|
||
'cert_no' => $id_number_str, // 权利人证件号,多套用'/'隔开
|
||
'property_cert' => $deed_number_str, // 房产证号,多套用'/'隔开
|
||
'purchase_date' => $buy_date_str, // 房产证登记日期,多套用'/'隔开
|
||
'report_cost' => $report_cost, // 报告工本费
|
||
'order_src' => $report_result['order_src'], // 业务来源
|
||
'is_housing_fund' => $report_result['is_housing_fund'], // 是否公积金,1:是,0:否
|
||
'pay_type' => $report_result['pay_type'], // 收费方式,1:月结,2:个人
|
||
'business_type' => $report_result['business_type'], // 业务类别,1:个贷,2:对公
|
||
'is_simple' => $inquiry_result['is_simple'], // 是否简易报告,1:是,0:否
|
||
'survey_username_id' => $survey_username_id_str,
|
||
'survey_user_name' => $survey_username_str,
|
||
'remark' => $report_result['report_remark_copy'],
|
||
'create_time' => date('Y-m-d H:i:s'),
|
||
'update_time' => date('Y-m-d H:i:s')
|
||
];
|
||
// return (new ChargeModel())->insert($data);
|
||
$ins_result = (new ChargeModel())->insert($data);
|
||
if ($ins_result) {
|
||
return ['result'=>true, 'msg'=>'插入数据成功'];
|
||
} else {
|
||
return ['result'=>false, 'msg'=>'插入数据失败'];
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 计算产品总值区间收费金额
|
||
* @param $where
|
||
* @param $assessment_total
|
||
* @return int|mixed
|
||
*/
|
||
public function chargeCalculation($where, $assessment_total) {
|
||
$receivable = 0;
|
||
$product_item = Db::name('product_item')->where($where)->select();
|
||
if ($product_item) {
|
||
foreach ($product_item as $key=>$value) {
|
||
if ((strpos($value['tvoa_rise'], '-') !== false || empty($value['tvoa_rise'])) && $assessment_total <= $value['tvoa_stop']*10000) {
|
||
$receivable = !empty($value['money'])?$value['money']:$assessment_total * $value['ratio'] / 100;
|
||
} elseif ((strpos($value['tvoa_stop'], '-') !== false || empty($value['tvoa_stop'])) && $assessment_total >= $value['tvoa_rise']*10000) {
|
||
$receivable = !empty($value['money'])?$value['money']:$assessment_total * $value['ratio'] / 100;
|
||
} elseif ($assessment_total >= $value['tvoa_rise']*10000 && $assessment_total <= $value['tvoa_stop']*10000) {
|
||
$receivable = !empty($value['money'])?$value['money']:$assessment_total * $value['ratio'] / 100;
|
||
}
|
||
}
|
||
}
|
||
return $receivable;
|
||
}
|
||
|
||
/**
|
||
* 计算产品总值区间对公收费金额
|
||
* @param $assessment_total
|
||
* @return int|mixed
|
||
*/
|
||
public function publicExpenseCalculation($assessment_total) {
|
||
$receivable = 0;
|
||
$public_expense = Db::name('public_expense')->select();
|
||
if ($public_expense) {
|
||
foreach ($public_expense as $key=>$value) {
|
||
if ((strpos($value['assessment_gv_rise'], '-') !== false || empty($value['assessment_gv_rise'])) && $assessment_total <= $value['assessment_gv_stop']*10000) {
|
||
$receivable = $assessment_total * $value['charge_rate'] / 1000;
|
||
} elseif ((strpos($value['assessment_gv_stop'], '-') !== false || empty($value['assessment_gv_stop'])) && $assessment_total >= $value['assessment_gv_rise']*10000) {
|
||
$receivable = $assessment_total * $value['charge_rate'] / 1000;
|
||
} elseif ($assessment_total >= $value['assessment_gv_rise']*10000 && $assessment_total <= $value['assessment_gv_stop']*10000) {
|
||
$receivable = $assessment_total * $value['charge_rate'] / 1000;
|
||
}
|
||
}
|
||
}
|
||
return $receivable;
|
||
}
|
||
|
||
// 测试
|
||
public function test() {
|
||
// $map[] = ['create_time', 'between time', ['2020-01-01 00:00:00', '2020-08-01 00:00:00']];
|
||
// $map[] = ['type', '=', 2];
|
||
// $inquiry = Db::name('inquiry')->where($map)->select();
|
||
// $inquiry_cnt = 0;
|
||
// $return_price_cnt = 0;
|
||
// foreach ($inquiry as $key=>$value) {
|
||
// $property_cert_info = Db::name('property_cert_info')
|
||
// ->where(['quot_id'=>$value['id']])
|
||
// ->select();
|
||
// foreach ($property_cert_info as $k=>$v) {
|
||
// $return_price = Db::name('return_price')->where(['property_cert_info_id'=>$v['id']])->select();
|
||
// if ($return_price) {
|
||
// foreach ($return_price as $ke=>$va) {
|
||
// $upd = $va;
|
||
// $upd['internal_remarks'] = $va['external_remarks'];
|
||
// $upd['external_remarks'] = $va['internal_remarks'];
|
||
// Db::name('return_price')->where(['id'=>$va['id']])->update($upd);
|
||
// $return_price_cnt++;
|
||
// }
|
||
// }
|
||
// }
|
||
// $inquiry_cnt++;
|
||
// }
|
||
// print_r($inquiry_cnt.'==='.$return_price_cnt);
|
||
// exit();
|
||
// $report_id = $this->request->param('report_id');
|
||
// $result = $this->insReportData($report_id);
|
||
// if ($result['result']) {
|
||
// return $this->buildSuccess($result, '插入数据成功!');
|
||
// } else {
|
||
// return $this->buildFailed($result['msg']);
|
||
// }
|
||
|
||
/*
|
||
property_cert_info_id=64 72
|
||
【房产详细资料】
|
||
深圳市宝安区西乡街道西乡大道北侧中粮澜山花园29-30#楼A单元101,房地产证号5000452985,房屋结构为短肢剪力墙,房地产用途为住宅,宗地号为A112-0119,土地使用年限为70年(自2002年03月22日至2072年03月21日),竣工时间为2009年12月28日,登记价为RMB4863773,登记日期2010年08月18日,房屋性质商品房,建筑面积为243.29平方米。
|
||
【产权信息】
|
||
产权状态为:抵押
|
||
权利人份额:100%
|
||
抵押权人:中国农业银行股份有限公司深圳宝安支行
|
||
抵押日期:2010-04-08
|
||
property_cert_info_id=70 80
|
||
【房产详细资料】
|
||
深圳市宝安区民治街道上塘居委银泉花园6栋805,不动产权证号粤(2016)深圳市不动产权第0155149号,房屋结构为框架结构,房地产用途为住宅,宗地号为A823-0168,土地使用年限为70年(自1991年12月15日至2061年12月14日),竣工时间为1999年12月29日,登记价为RMB1699011,登记日期2016年07月20日,房屋性质商品房,建筑面积为72.20平方米。
|
||
【产权信息】
|
||
产权状态为:抵押
|
||
权利人份额:100%
|
||
抵押权人:中国银行股份有限公司深圳东门支行
|
||
抵押日期:2016-07-21
|
||
*/
|
||
$consult = Db::name('consult_record')->where(['property_cert_info_id'=>70])->find();
|
||
$deed_number_str = Db::name('consult_record_det')->where(['id'=>$consult['consult_record_det_id']])->find();
|
||
if (strpos($deed_number_str['data_printResult'], ',') !== false) {
|
||
$deed_number_str_array = explode(',', $deed_number_str['data_printResult']);
|
||
if (strpos($deed_number_str_array[1], '证号') !== false) {
|
||
$deed_number_array = explode('证号', $deed_number_str_array[1]);
|
||
if (strpos($deed_number_array[1], '不动产权') !== false) {
|
||
$property_cert = $deed_number_array[1];
|
||
} else {
|
||
$property_cert = '深房地字第'.$deed_number_array[1].'号';
|
||
}
|
||
}
|
||
}
|
||
dump($property_cert);
|
||
|
||
$receivable1 = $this->chargeCalculation(['product_id'=>38],5071050);
|
||
dump($receivable1);
|
||
|
||
$receivable2 = $this->getReceivable(5071050,38,1,1);
|
||
dump($receivable2);
|
||
|
||
$getEnv = Env::get('auth.auth_url');
|
||
dump($getEnv);
|
||
}
|
||
|
||
public function getReceivable($assessment_total, $product_id, $type, $estate_num, $business_type, $is_simple) {
|
||
// 报告工本费
|
||
$report_cost = 0;
|
||
// 报告应收金额
|
||
$receivable = 0;
|
||
if ($is_simple==1) {
|
||
// 简易报告的收费
|
||
$simple_report_rate = getDictionaryCode('REPORT_RATE', '简易报告费率');
|
||
$rate = $simple_report_rate?$simple_report_rate['code']:5;
|
||
$receivable = $assessment_total * $rate / 1000;
|
||
} else {
|
||
if($business_type==2) {
|
||
// 业务类别为对公的收费
|
||
$receivable = $this->publicExpenseCalculation($assessment_total);
|
||
} else {
|
||
// 业务类别为个贷的收费
|
||
$product_result = Db::name('product')->where(['id'=>$product_id, 'state'=>1])->find();
|
||
if ($product_result) {
|
||
$report_cost = $product_result['report_cost'];
|
||
if ($product_result['charging_method'] == 1) {
|
||
// 评估总值区间
|
||
$map = ['product_id'=>$product_id];
|
||
$receivable = $this->chargeCalculation($map, $assessment_total);
|
||
} elseif ($product_result['charging_method'] == 2) {
|
||
// 评估总值物业区间
|
||
$map = ['product_id'=>$product_id, 'type'=>$type];
|
||
$receivable = $this->chargeCalculation($map, $assessment_total);
|
||
} elseif ($product_result['charging_method'] == 3) {
|
||
// 物业类型
|
||
$product_item = Db::name('product_item')->where(['product_id'=>$product_id, 'type'=>$type])->find();
|
||
if ($product_item) {
|
||
$receivable = $product_item['money'];
|
||
} else {
|
||
$receivable = 0;
|
||
}
|
||
} elseif ($product_result['charging_method'] == 4) {
|
||
// 单笔
|
||
$product_item = Db::name('product_item')->where(['product_id'=>$product_id])->find();
|
||
if ($product_item) {
|
||
if ($estate_num > 1) {
|
||
$receivable = $product_item['money'] + ($estate_num - 1) * $product_item['extra_charge'];
|
||
} else {
|
||
$receivable = $product_item['money'];
|
||
}
|
||
} else {
|
||
$receivable = 0;
|
||
}
|
||
} elseif ($product_result['charging_method'] == 5 && $estate_num == 1) {
|
||
// 单套评估总值
|
||
$map = ['product_id'=>$product_id];
|
||
$receivable = $this->chargeCalculation($map, $assessment_total);
|
||
} else {
|
||
$receivable = 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return ['receivable'=>round($receivable), 'report_cost'=>$report_cost];
|
||
}
|
||
|
||
public function deleteAutomatic() {
|
||
// 获取指定范围自动估价询价记录
|
||
$inquiry_data = Db::name('inquiry')
|
||
->where(['is_auto' => 1])
|
||
->where('create_time', 'lt', '2021-07-06 00:00:00')
|
||
->field('id')
|
||
->select();
|
||
foreach ($inquiry_data as $key=>$value) {
|
||
$inquiry_detail_data = Db::name('property_cert_info')
|
||
->where(['quot_id' => $value['id']])
|
||
->field('id')
|
||
->select();
|
||
foreach ($inquiry_detail_data as $k=>$v) {
|
||
Db::name('return_price')->where(['property_cert_info_id' => $v['id']])->delete();
|
||
Db::name('property_cert_info')->where(['id' => $v['id']])->delete();
|
||
}
|
||
Db::name('signature_record')->where(['quot_id' => $value['id']])->delete();
|
||
Db::name('inquiry')->where(['id' => $value['id']])->delete();
|
||
}
|
||
return $this->buildSuccess('', '删除成功!');
|
||
}
|
||
|
||
|
||
}
|