Commit f615411e authored by hujun's avatar hujun

方法转移

parent 6a67aaa9
......@@ -933,349 +933,6 @@ class Finance extends Basic
return $this->response($data['code'], $data['msg']);
}
/**
* 退款列表
*
* @return \think\Response|\think\response\View
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function refundList()
{
//显示视图
if (!$this->request->isAjax()) {
return view('refundList');
}
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$refund = new ORefundModel();
$m_house = new GHouses();
$m_store = new AStore();
$where['a.is_del'] = 0;
if (isset($this->params['status']) && $this->params['status'] != -1) {
if ($this->params['status'] == 1) {
$where['a.status'] = ['in', '0,1'];
} else {
$where['a.status'] = $this->params['status'];
}
}
if (!empty($this->params['start_time']) && empty($this->params['end_time'])) {
$where['a.create_time'] = ['>', $this->params['start_time'] . ' 00:00:00'];
}
if (!empty($this->params['end_time']) && empty($this->params['start_time'])) {
$where['a.create_time'] = ['>', $this->params['end_time'] . ' 23:59:59'];
}
if (!empty($this->params['start_time']) && !empty($this->params['end_time'])) {
$where['a.create_time'] = ['between', [$this->params['start_time'] . ' 00:00:00', $this->params['end_time'] . ' 23:59:59']];
}
if (!empty($this->params['income_start_time']) && empty($this->params['income_end_time'])) {
$where['d.income_time'] = ['>', $this->params['income_start_time'] . ' 00:00:00'];
}
if (!empty($this->params['income_end_time']) && empty($this->params['income_start_time'])) {
$where['d.income_time'] = ['>', $this->params['income_end_time'] . ' 23:59:59'];
}
if (!empty($this->params['income_start_time']) && !empty($this->params['income_end_time'])) {
$where['d.income_time'] = ['between', [$this->params['income_start_time'] . ' 00:00:00', $this->params['income_end_time'] . ' 23:59:59']];
}
if (isset($this->params['type']) && $this->params['type'] != -1) {
$where['a.type'] = $this->params['type'];
}
if (!empty($this->params['order_id'])) {
$where['a.order_id'] = $this->params['order_id'];
}
if (!empty($this->params['id'])) {
$where['a.id'] = $this->params['id'];
}
if (!empty($this->params['house_id'])) {
$where['b.house_id'] = $this->params['house_id'];
}
if (!empty($this->params['address'])) {
$m_house = new GHouses();
$house_id = $m_house->getHouseColumn('id', ['internal_address' => ['LIKE', '%' . trim($this->params['address']) . '%']]);
if (isset($where['b.house_id'])) {
$house_id[] = $where['b.house_id'];
}
if (!empty($house_id)) {
$where['b.house_id'] = ['in', $house_id];
}
}
if (!empty($this->params['district_id'])) {
$where['c.district_id'] = $this->params['district_id'];
}
if (!empty($this->params['store_id'])) {
$where['c.store_id'] = $this->params['store_id'];
}
if (!empty($this->params['agent_id'])) {
$where['a.agent_id'] = $this->params['agent_id'];
}
if (!empty($this->params['pay_log_id'])) {
$where['a.pay_log_id'] = $this->params['pay_log_id'];
}
if (isset($this->params['is_self']) && $this->params['is_self'] != -1) {
if ($this->params['is_self']) {
$where['e.operation_id'] = $this->userId;
} else {
$where[] = ['EXP', 'a.id NOT IN (SELECT refund_id FROM o_refund_log WHERE operation_id =' . $this->userId . ')'];
}
}
//案场费和中介费是否开业
if (isset($this->params['is_open'])) {
if ($this->params['is_open'] == 1) {
$where['d.is_open'] = 1;
} else {
$where['d.is_open'] = 0;
}
if (!isset($where['a.type'])) {
$where['a.type'] = ['in', '4,5'];
}
}
$fields = 'a.create_time,a.id,a.order_id,a.pay_log_id,a.refund_money,a.type,a.agent_id,a.agent_name,b.house_id,a.status,';
$fields .= 'd.income_time,a.type,c.store_id';
$list = $refund->getCheckRefundList($pageNo, $pageSize, 'a.id DESC', $fields, $where);
foreach ($list as $k => $v) {
$store_id[] = $v['store_id'];
$house_id[] = $v['house_id'];
}
if (isset($store_id)) {
$store_id = array_unique($store_id);
$store_id = array_filter($store_id);
$store_data = $m_store->getColumn('id,store_name', ['id'=>['in', $store_id]]);
} else {
$store_data = [];
}
if (isset($house_id)) {
$house_id = array_unique($house_id);
$house_id = array_filter($house_id);
$house_data = $m_house->getHouseColumn('id,internal_address', ['id'=>['in', $house_id]]);
} else {
$house_data = [];
}
foreach($list as $k2=>$v2) {
$list[$k2]['store_name'] = array_key_exists($v2['store_id'], $store_data) ? $store_data[$v2['store_id']] : '';
$list[$k2]['address'] = array_key_exists($v2['house_id'], $house_data) ? $house_data[$v2['house_id']] : '';
$list[$k2]['income_time'] = empty($v2['income_time']) ? '':$v2['income_time'];
}
$data['data']['list'] = $list;
$data['data']['total_money'] = $refund->getSumMoney($where);
$data['data']['total'] = $refund->getCheckRefundListTotal($where);
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 退款列表-导出excel
* @return string
*/
public function refundListExcel()
{
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
$refund = new ORefundModel();
$m_house = new GHouses();
$m_store = new AStore();
$where['a.is_del'] = 0;
if (isset($this->params['status']) && $this->params['status'] != -1) {
if ($this->params['status'] == 1) {
$where['a.status'] = ['in', '0,1'];
} else {
$where['a.status'] = $this->params['status'];
}
}
if (!empty($this->params['start_time']) && empty($this->params['end_time'])) {
$where['a.create_time'] = ['>', $this->params['start_time'] . ' 00:00:00'];
}
if (!empty($this->params['end_time']) && empty($this->params['start_time'])) {
$where['a.create_time'] = ['>', $this->params['end_time'] . ' 23:59:59'];
}
if (!empty($this->params['start_time']) && !empty($this->params['end_time'])) {
$where['a.create_time'] = ['between', [$this->params['start_time'] . ' 00:00:00', $this->params['end_time'] . ' 23:59:59']];
}
if (!empty($this->params['income_start_time']) && empty($this->params['income_end_time'])) {
$where['d.income_time'] = ['>', $this->params['income_start_time'] . ' 00:00:00'];
}
if (!empty($this->params['income_end_time']) && empty($this->params['income_start_time'])) {
$where['d.income_time'] = ['>', $this->params['income_end_time'] . ' 23:59:59'];
}
if (!empty($this->params['income_start_time']) && !empty($this->params['income_end_time'])) {
$where['d.income_time'] = ['between', [$this->params['income_start_time'] . ' 00:00:00', $this->params['income_end_time'] . ' 23:59:59']];
}
if (is_numeric($this->params['type']) && $this->params['type'] != -1) {
$where['a.type'] = $this->params['type'];
}
if (!empty($this->params['order_id'])) {
$where['a.order_id'] = $this->params['order_id'];
}
if (!empty($this->params['id'])) {
$where['a.id'] = $this->params['id'];
}
if (!empty($this->params['house_id'])) {
$where['b.house_id'] = $this->params['house_id'];
}
if (!empty($this->params['address'])) {
$m_house = new GHouses();
$house_id = $m_house->getHouseColumn('id', ['internal_address' => ['LIKE', '%' . trim($this->params['address']) . '%']]);
if (isset($where['b.house_id'])) {
$house_id[] = $where['b.house_id'];
}
if (!empty($house_id)) {
$where['b.house_id'] = ['in', $house_id];
}
}
if (!empty($this->params['district_id'])) {
$where['c.district_id'] = $this->params['district_id'];
}
if (!empty($this->params['store_id'])) {
$where['c.store_id'] = $this->params['store_id'];
}
if (!empty($this->params['agent_id'])) {
$where['a.agent_id'] = $this->params['agent_id'];
}
if (!empty($this->params['pay_log_id'])) {
$where['a.pay_log_id'] = $this->params['pay_log_id'];
}
if (is_numeric($this->params['is_self']) && $this->params['is_self'] != -1) {
if ($this->params['is_self']) {
$where['e.operation_id'] = $this->userId;
} else {
$where[] = ['EXP', 'a.id NOT IN (SELECT refund_id FROM o_refund_log WHERE operation_id =' . $this->userId . ')'];
}
}
$fields = 'a.create_time,a.id,a.type,a.order_id,a.pay_log_id,a.refund_money,';
$fields .= 'd.income_time,a.status,c.store_id,a.agent_name,b.house_id';
$list = $refund->getCheckRefundListForExcel('a.id DESC', $fields, $where);
foreach ($list as $k => $v) {
if (($v['status'] == 0) or ($v['status'] == 1)) {
$v['status'] = '审核中';
} elseif ($v['status'] == 2) {
$v['status'] = '退款成功';
} elseif ($v['status'] == 3) {
$v['status'] = '已审核';
} elseif ($v['status'] == 4) {
$v['status'] = '驳回';
} else {
$v['status'] = '';
}
if ($v['type'] == 1) {
$v['type'] = '意向金转定';
} elseif ($v['type'] == 2) {
$v['type'] = '退保管金';
} elseif ($v['type'] == 3) {
$v['type'] = '保管金转定';
} elseif ($v['type'] == 4) {
$v['type'] = '退中介费';
} elseif ($v['type'] == 5) {
$v['type'] = '退案场费';
} elseif ($v['type'] == 0) {
$v['type'] = '退意向金';
} else {
$v['type'] = '';
}
if (empty($v['house_id'])) {
$v['address'] = '';
} else {
$v['address'] = $m_house->getHouseValue('internal_address', ['id' => $v['house_id']]);
}
if (empty($v['store_id'])) {
$v['store_name'] = '';
} else {
$v['store_name'] = $m_store->getStoreKeyById('store_name', ['id' => $v['store_id']]);
}
$excel_data_ = [];
$excel_data_[] = $v['create_time'];
$excel_data_[] = $v['id'];
$excel_data_[] = $v['status'];
$excel_data_[] = $v['order_id'];
$excel_data_[] = $v['pay_log_id'];
$excel_data_[] = $v['refund_money'];
$excel_data_[] = $v['income_time'];
$excel_data_[] = $v['type'];
$excel_data_[] = $v['agent_name'];
$excel_data_[] = $v['store_name'];
$excel_data_[] = $v['house_id'];
$excel_data_[] = $v['address'];
$excel_data[] = $excel_data_;
}
$total_money = $refund->getSumMoney($where);
if (!$excel_data) {
return '<script>alert("导出失败");window.close();</script>';
}
$export = new ExportExcelUntil();
$title = ['提交时间', '退款ID', '状态', '订单ID', '收款ID', '退款金额', '入账日期', '退款类型', '提交人', '所属门店', '商铺ID', '商铺地址'];
$export->exportTable('退款审核明细表', $excel_data, 11, '退款审核明细表 (退款总计:' . $total_money . ')', $title);
return '';
}
/**
* 已退款列表
*
......@@ -4337,226 +3994,6 @@ class Finance extends Basic
return $this->response("101", "request faild");
}
/**
* 退款审核
*
* @return \think\Response
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function checkRefund()
{
$code = 101;
$msg = '';
if (empty($this->params['refund_id']) || empty($this->params['status'])) {
return $this->response($code, '参数错误');
}
$m_refund = new ORefundModel();
$refund_where['id'] = $this->params['refund_id'];
// 0申请 1审核中 2退款成功 3已审核4驳回
switch ($this->params['status']) {
case 1 :
$refund_where['status'] = ['in', '0,1,4'];
break;
case 2 :
$refund_where['status'] = 3;
break;
}
$refund_where['is_del'] = $status = 0;
$refund_data = $m_refund->selectRefundByOrderNo('id,status,order_id,agent_id', $refund_where);
if (empty($refund_data[0]['id'])) {
return $this->response($code, '没有该退款详情或审核完成');
}
if (($refund_data[0]['status'] == 4) && ($this->params['status'] == 4)) {
return $this->response($code, '该退款已驳回');
}
if (($refund_data[0]['status'] == 3) && ($this->params['status'] == 3)) {
return $this->response($code, '该退款已审核');
}
if (($refund_data[0]['status'] == 2) && ($this->params['status'] == 2)) {
return $this->response($code, '已退款');
}
$m_refund_log = new ORefundLogModel();
$save_data['refund_id'] = $this->params['refund_id'];
$save_data['remark'] = trim($this->params['remark']);
$save_data['operation_id'] = $this->userId;
$save_data['operation_name'] = $this->userName;
$save_data['order_id'] = $refund_data[0]['order_id'];
$log_where['is_del'] = 0;
$log_where['refund_id'] = $this->params['refund_id'];
$num = 0;
switch ($this->params['status']) {
case 1 :
$log_where['status'] = 1;
$check_agent_id = $m_refund_log->getListAll('operation_id', $log_where);
foreach ($check_agent_id as $v) {
if ($v['operation_id'] == $this->userId) {
return $this->response(101, '你已审核过');
}
}
if (count($check_agent_id) >= 1) {
$status = 3; //已审核
}
$save_data['status'] = 1;
$num = $m_refund_log->insertData($save_data);
break;
case 2 :
$log_where['status'] = 1;
$check_num = $m_refund_log->getTotal($log_where);
$id = 0;
if ($check_num >= 2) {
$save_data['status'] = $status = 2; //已审核
$num = $id = $m_refund_log->insertData($save_data);
$push = new PushMessageService();
$m_order = new OrderModel();
$house_title = $m_order->getOrderById('house_id,house_title', $refund_data[0]['order_id']);
$record_data['message'] = '[' . $house_title['house_title'] . ']退款成功';
$record_data['order_id'] = $refund_data[0]['order_id'];
$record_data['house_id'] = $house_title['house_id'];
$record_data['title'] = '退款成功-商铺';
$push->recordCheck(3, [$refund_data[0]['agent_id']], $this->userId, $record_data);
}
if ($id > 0 && is_array($this->params['img_arr'])) {
$m_img = new OImg();
$m_img->addImgAll($id, 4, $this->params['img_arr']);
}
break;
case 4 :
$save_data['status'] = $status = 4;
$m_refund_log->updateData(['is_del' => 1], ['refund_id' => $this->params['refund_id'], 'status' => 1, 'is_del' => 0]);
$num = $m_refund_log->insertData($save_data);
$push = new PushMessageService();
$m_order = new OrderModel();
$house_title = $m_order->getOrderById('house_id,house_title', $refund_data[0]['order_id']);
$record_data['message'] = '[' . $house_title['house_title'] . ']退款被驳回,驳回原因:' . $save_data['remark'];
$record_data['order_id'] = $refund_data[0]['order_id'];
$record_data['house_id'] = $house_title['house_id'];
$record_data['title'] = '退款驳回-商铺';
$push->recordCheck(1, [$refund_data[0]['agent_id']], $this->userId, $record_data);
}
if ($num) {
if ($status) {
$m_refund->updateData(['status' => $status], ['id' => $this->params['refund_id']]);
}
$code = 200;
} else {
$msg = '审核失败';
}
return $this->response($code, $msg);
}
/**
* 退款详情
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function refundDetail()
{
if (empty($this->params['refund_id'])) {
return $this->response(101, '参数错误');
}
$code = 200;
$msg = '';
$m_refund = new ORefundModel();
$m_refund_log = new ORefundLogModel();
$m_pay_log = new OPayLogModel();
$m_img = new OImg();
$field = 'id,refund_money,receipt_number,type,refund_cause,refund_way,card_no,bank,name,phone,agent_id,status,pay_log_id,create_time';
$refund_data = $m_refund->selectRefundByOrderNo($field, ['id' => $this->params['refund_id'], 'is_del' => 0]);
if (empty($refund_data[0])) {
return $this->response(101, '退款信息错误');
}
$data = $refund_data[0];
if ($data['agent_id']) {
$m_store = new AAgents();
$store_name = $m_store->getAgentsStoreById(['a.id' => $data['agent_id']], 'a.name,b.store_name');
$data['store_name'] = $store_name['store_name'];
$data['agent_name'] = $store_name['name'];
} else {
$data['store_name'] = '';
$data['agent_name'] = '';
}
if ($data['pay_log_id']) {
$pay_field = 'a.income_time,c.internal_address as address,a.create_time,a.order_id,b.house_id';
$pay_data = $m_pay_log->getOrderHouse($pay_field, ['a.id' => $data['pay_log_id']]);
$data['address'] = $pay_data[0]['address'] ? $pay_data[0]['address'] : '';
$data['income_time'] = $pay_data[0]['income_time'];
$data['pay_create_time'] = $pay_data[0]['create_time'];
$data['order_id'] = $pay_data[0]['order_id'];
$data['house_id'] = $pay_data[0]['house_id'];
} else {
$data['address'] = '';
$data['income_time'] = '';
}
$img_where['img_id'] = $this->params['refund_id'];
$img_where['img_type'] = 3;
$img_where['img_status'] = 1;
$data['img'] = $m_img->getImgList($img_where);
$data['log'] = $m_refund_log->getListAll('operation_name,create_time,status', ['refund_id' => $this->params['refund_id'], 'is_del' => 0]);
return $this->response($code, $msg, $data);
}
/**
* 删除退款
*
* @return \think\Response
*/
public function delRefund()
{
$code = 101;
if (empty($this->params['refund_id'])) {
return $this->response($code, '参数错误');
}
try {
$where['id'] = $this->params['refund_id'];
$where['status'] = ['<>', 2];
$m_refund = new ORefundModel();
$m_refund_log = new ORefundLogModel();
$data = $m_refund->getFind('id', $where);
if (empty($data['id'])) {
return $this->response($code, '退款信息错误');
}
$num = $m_refund->updateData(['is_del' => 1], ['id' => $this->params['refund_id']]);
$msg = '删除失败';
if ($num) {
$m_refund_log->updateData(['is_del' => 1], ['refund_id' => $this->params['refund_id']]);
$code = 200;
$msg = '删除成功';
}
} catch (\Exception $e) {
$msg = '内部错误:' . $e->getMessage();
}
return $this->response($code, $msg, []);
}
/**
* 撤销列表-恢复成交报告
*
......
......@@ -9,7 +9,16 @@
namespace app\index\controller;
use app\api_broker\service\PushMessageService;
use app\index\extend\Basic;
use app\index\untils\ExportExcelUntil;
use app\model\AAgents;
use app\model\AStore;
use app\model\GHouses;
use app\model\OImg;
use app\model\OPayLogModel;
use app\model\OrderModel;
use app\model\ORefundLogModel;
use app\model\ORefundModel;
class Refund extends Basic
......@@ -43,4 +52,565 @@ class Refund extends Basic
}
return $this->response($code, $msg);
}
/**
* 退款审核
*
* @return \think\Response
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function checkRefund()
{
$code = 101;
$msg = '';
if (empty($this->params['refund_id']) || empty($this->params['status'])) {
return $this->response($code, '参数错误');
}
$m_refund = new ORefundModel();
$refund_where['id'] = $this->params['refund_id'];
// 0申请 1审核中 2退款成功 3已审核4驳回
switch ($this->params['status']) {
case 1 :
$refund_where['status'] = ['in', '0,1,4'];
break;
case 2 :
$refund_where['status'] = 3;
break;
}
$refund_where['is_del'] = $status = 0;
$refund_data = $m_refund->selectRefundByOrderNo('id,status,order_id,agent_id', $refund_where);
if (empty($refund_data[0]['id'])) {
return $this->response($code, '没有该退款详情或审核完成');
}
if (($refund_data[0]['status'] == 4) && ($this->params['status'] == 4)) {
return $this->response($code, '该退款已驳回');
}
if (($refund_data[0]['status'] == 3) && ($this->params['status'] == 3)) {
return $this->response($code, '该退款已审核');
}
if (($refund_data[0]['status'] == 2) && ($this->params['status'] == 2)) {
return $this->response($code, '已退款');
}
$m_refund_log = new ORefundLogModel();
$save_data['refund_id'] = $this->params['refund_id'];
$save_data['remark'] = trim($this->params['remark']);
$save_data['operation_id'] = $this->userId;
$save_data['operation_name'] = $this->userName;
$save_data['order_id'] = $refund_data[0]['order_id'];
$log_where['is_del'] = 0;
$log_where['refund_id'] = $this->params['refund_id'];
$num = 0;
switch ($this->params['status']) {
case 1 :
$log_where['status'] = 1;
$check_agent_id = $m_refund_log->getListAll('operation_id', $log_where);
foreach ($check_agent_id as $v) {
if ($v['operation_id'] == $this->userId) {
return $this->response(101, '你已审核过');
}
}
if (count($check_agent_id) >= 2) {
$status = 3; //已审核
}
$save_data['status'] = 1;
$num = $m_refund_log->insertData($save_data);
break;
case 2 :
$log_where['status'] = 1;
$check_num = $m_refund_log->getTotal($log_where);
$id = 0;
if ($check_num >= 2) {
$save_data['status'] = $status = 2; //已审核
$num = $id = $m_refund_log->insertData($save_data);
$push = new PushMessageService();
$m_order = new OrderModel();
$house_title = $m_order->getOrderById('house_id,house_title', $refund_data[0]['order_id']);
$record_data['message'] = '[' . $house_title['house_title'] . ']退款成功';
$record_data['order_id'] = $refund_data[0]['order_id'];
$record_data['house_id'] = $house_title['house_id'];
$record_data['title'] = '退款成功-商铺';
$push->recordCheck(3, [$refund_data[0]['agent_id']], $this->userId, $record_data);
}
if ($id > 0 && is_array($this->params['img_arr'])) {
$m_img = new OImg();
$m_img->addImgAll($id, 4, $this->params['img_arr']);
}
break;
case 4 :
$save_data['status'] = $status = 4;
$m_refund_log->updateData(['is_del' => 1], ['refund_id' => $this->params['refund_id'], 'status' => 1, 'is_del' => 0]);
$num = $m_refund_log->insertData($save_data);
$push = new PushMessageService();
$m_order = new OrderModel();
$house_title = $m_order->getOrderById('house_id,house_title', $refund_data[0]['order_id']);
$record_data['message'] = '[' . $house_title['house_title'] . ']退款被驳回,驳回原因:' . $save_data['remark'];
$record_data['order_id'] = $refund_data[0]['order_id'];
$record_data['house_id'] = $house_title['house_id'];
$record_data['title'] = '退款驳回-商铺';
$push->recordCheck(1, [$refund_data[0]['agent_id']], $this->userId, $record_data);
}
if ($num) {
if ($status) {
$m_refund->updateData(['status' => $status], ['id' => $this->params['refund_id']]);
}
$code = 200;
} else {
$msg = '审核失败';
}
return $this->response($code, $msg);
}
/**
* 退款列表
*
* @return \think\Response|\think\response\View
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function refundList()
{
//显示视图
if (!$this->request->isAjax()) {
return view('refundList');
}
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$refund = new ORefundModel();
$m_house = new GHouses();
$m_store = new AStore();
$where['a.is_del'] = 0;
if (isset($this->params['status']) && $this->params['status'] != -1) {
if ($this->params['status'] == 1) {
$where['a.status'] = ['in', '0,1'];
} else {
$where['a.status'] = $this->params['status'];
}
}
if (!empty($this->params['start_time']) && empty($this->params['end_time'])) {
$where['a.create_time'] = ['>', $this->params['start_time'] . ' 00:00:00'];
}
if (!empty($this->params['end_time']) && empty($this->params['start_time'])) {
$where['a.create_time'] = ['>', $this->params['end_time'] . ' 23:59:59'];
}
if (!empty($this->params['start_time']) && !empty($this->params['end_time'])) {
$where['a.create_time'] = ['between', [$this->params['start_time'] . ' 00:00:00', $this->params['end_time'] . ' 23:59:59']];
}
if (!empty($this->params['income_start_time']) && empty($this->params['income_end_time'])) {
$where['d.income_time'] = ['>', $this->params['income_start_time'] . ' 00:00:00'];
}
if (!empty($this->params['income_end_time']) && empty($this->params['income_start_time'])) {
$where['d.income_time'] = ['>', $this->params['income_end_time'] . ' 23:59:59'];
}
if (!empty($this->params['income_start_time']) && !empty($this->params['income_end_time'])) {
$where['d.income_time'] = ['between', [$this->params['income_start_time'] . ' 00:00:00', $this->params['income_end_time'] . ' 23:59:59']];
}
if (isset($this->params['type']) && $this->params['type'] != -1) {
$where['a.type'] = $this->params['type'];
}
if (!empty($this->params['order_id'])) {
$where['a.order_id'] = $this->params['order_id'];
}
if (!empty($this->params['id'])) {
$where['a.id'] = $this->params['id'];
}
if (!empty($this->params['house_id'])) {
$where['b.house_id'] = $this->params['house_id'];
}
if (!empty($this->params['address'])) {
$house_id = $m_house->getHouseColumn('id', ['internal_address' => ['LIKE', '%' . trim($this->params['address']) . '%']]);
if (isset($where['b.house_id'])) {
$house_id[] = $where['b.house_id'];
}
if (!empty($house_id)) {
$where['b.house_id'] = ['in', $house_id];
}
}
if (!empty($this->params['district_id'])) {
$where['c.district_id'] = $this->params['district_id'];
}
if (!empty($this->params['store_id'])) {
$where['c.store_id'] = $this->params['store_id'];
}
if (!empty($this->params['agent_id'])) {
$where['a.agent_id'] = $this->params['agent_id'];
}
if (!empty($this->params['pay_log_id'])) {
$where['a.pay_log_id'] = $this->params['pay_log_id'];
}
if (isset($this->params['is_self']) && $this->params['is_self'] != -1) {
if ($this->params['is_self']) {
$where['e.operation_id'] = $this->userId;
} else {
$where[] = ['EXP', 'a.id NOT IN (SELECT refund_id FROM o_refund_log WHERE operation_id =' . $this->userId . ')'];
}
}
//案场费和中介费是否开业
if (isset($this->params['is_open'])) {
if ($this->params['is_open'] == 1) {
$where['d.is_open'] = 1;
} else {
$where['d.is_open'] = 0;
}
if (!isset($where['a.type'])) {
$where['a.type'] = ['in', '4,5'];
}
}
$fields = 'a.create_time,a.id,a.order_id,a.pay_log_id,a.refund_money,a.type,a.agent_id,a.agent_name,b.house_id,a.status,';
$fields .= 'd.income_time,a.type,c.store_id';
$list = $refund->getCheckRefundList($pageNo, $pageSize, 'a.id DESC', $fields, $where);
foreach ($list as $k => $v) {
$store_id[] = $v['store_id'];
$house_id[] = $v['house_id'];
}
if (isset($store_id)) {
$store_id = array_unique($store_id);
$store_id = array_filter($store_id);
$store_data = $m_store->getColumn('id,store_name', ['id'=>['in', $store_id]]);
} else {
$store_data = [];
}
if (isset($house_id)) {
$house_id = array_unique($house_id);
$house_id = array_filter($house_id);
$house_data = $m_house->getHouseColumn('id,internal_address', ['id'=>['in', $house_id]]);
} else {
$house_data = [];
}
foreach($list as $k2=>$v2) {
$list[$k2]['store_name'] = array_key_exists($v2['store_id'], $store_data) ? $store_data[$v2['store_id']] : '';
$list[$k2]['address'] = array_key_exists($v2['house_id'], $house_data) ? $house_data[$v2['house_id']] : '';
$list[$k2]['income_time'] = empty($v2['income_time']) ? '':$v2['income_time'];
$list[$k2]['pay_log_id'] = empty($v2['pay_log_id']) ? '':$v2['pay_log_id'];
}
$data['data']['list'] = $list;
$data['data']['total_money'] = $refund->getSumMoney($where);
$data['data']['total'] = $refund->getCheckRefundListTotal($where);
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 退款列表-导出excel
* @return string
*/
public function refundListExcel()
{
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
$refund = new ORefundModel();
$m_house = new GHouses();
$m_store = new AStore();
$where['a.is_del'] = 0;
if (isset($this->params['status']) && $this->params['status'] != -1) {
if ($this->params['status'] == 1) {
$where['a.status'] = ['in', '0,1'];
} else {
$where['a.status'] = $this->params['status'];
}
}
if (!empty($this->params['start_time']) && empty($this->params['end_time'])) {
$where['a.create_time'] = ['>', $this->params['start_time'] . ' 00:00:00'];
}
if (!empty($this->params['end_time']) && empty($this->params['start_time'])) {
$where['a.create_time'] = ['>', $this->params['end_time'] . ' 23:59:59'];
}
if (!empty($this->params['start_time']) && !empty($this->params['end_time'])) {
$where['a.create_time'] = ['between', [$this->params['start_time'] . ' 00:00:00', $this->params['end_time'] . ' 23:59:59']];
}
if (!empty($this->params['income_start_time']) && empty($this->params['income_end_time'])) {
$where['d.income_time'] = ['>', $this->params['income_start_time'] . ' 00:00:00'];
}
if (!empty($this->params['income_end_time']) && empty($this->params['income_start_time'])) {
$where['d.income_time'] = ['>', $this->params['income_end_time'] . ' 23:59:59'];
}
if (!empty($this->params['income_start_time']) && !empty($this->params['income_end_time'])) {
$where['d.income_time'] = ['between', [$this->params['income_start_time'] . ' 00:00:00', $this->params['income_end_time'] . ' 23:59:59']];
}
if (is_numeric($this->params['type']) && $this->params['type'] != -1) {
$where['a.type'] = $this->params['type'];
}
if (!empty($this->params['order_id'])) {
$where['a.order_id'] = $this->params['order_id'];
}
if (!empty($this->params['id'])) {
$where['a.id'] = $this->params['id'];
}
if (!empty($this->params['house_id'])) {
$where['b.house_id'] = $this->params['house_id'];
}
if (!empty($this->params['address'])) {
$m_house = new GHouses();
$house_id = $m_house->getHouseColumn('id', ['internal_address' => ['LIKE', '%' . trim($this->params['address']) . '%']]);
if (isset($where['b.house_id'])) {
$house_id[] = $where['b.house_id'];
}
if (!empty($house_id)) {
$where['b.house_id'] = ['in', $house_id];
}
}
if (!empty($this->params['district_id'])) {
$where['c.district_id'] = $this->params['district_id'];
}
if (!empty($this->params['store_id'])) {
$where['c.store_id'] = $this->params['store_id'];
}
if (!empty($this->params['agent_id'])) {
$where['a.agent_id'] = $this->params['agent_id'];
}
if (!empty($this->params['pay_log_id'])) {
$where['a.pay_log_id'] = $this->params['pay_log_id'];
}
if (is_numeric($this->params['is_self']) && $this->params['is_self'] != -1) {
if ($this->params['is_self']) {
$where['e.operation_id'] = $this->userId;
} else {
$where[] = ['EXP', 'a.id NOT IN (SELECT refund_id FROM o_refund_log WHERE operation_id =' . $this->userId . ')'];
}
}
$fields = 'a.create_time,a.id,a.type,a.order_id,a.pay_log_id,a.refund_money,';
$fields .= 'd.income_time,a.status,c.store_id,a.agent_name,b.house_id';
$list = $refund->getCheckRefundListForExcel('a.id DESC', $fields, $where);
foreach ($list as $k => $v) {
if (($v['status'] == 0) or ($v['status'] == 1)) {
$v['status'] = '审核中';
} elseif ($v['status'] == 2) {
$v['status'] = '退款成功';
} elseif ($v['status'] == 3) {
$v['status'] = '已审核';
} elseif ($v['status'] == 4) {
$v['status'] = '驳回';
} else {
$v['status'] = '';
}
if ($v['type'] == 1) {
$v['type'] = '意向金转定';
} elseif ($v['type'] == 2) {
$v['type'] = '退保管金';
} elseif ($v['type'] == 3) {
$v['type'] = '保管金转定';
} elseif ($v['type'] == 4) {
$v['type'] = '退中介费';
} elseif ($v['type'] == 5) {
$v['type'] = '退案场费';
} elseif ($v['type'] == 0) {
$v['type'] = '退意向金';
} else {
$v['type'] = '';
}
if (empty($v['house_id'])) {
$v['address'] = '';
} else {
$v['address'] = $m_house->getHouseValue('internal_address', ['id' => $v['house_id']]);
}
if (empty($v['store_id'])) {
$v['store_name'] = '';
} else {
$v['store_name'] = $m_store->getStoreKeyById('store_name', ['id' => $v['store_id']]);
}
$excel_data_ = [];
$excel_data_[] = $v['create_time'];
$excel_data_[] = $v['id'];
$excel_data_[] = $v['status'];
$excel_data_[] = $v['order_id'];
$excel_data_[] = $v['pay_log_id'];
$excel_data_[] = $v['refund_money'];
$excel_data_[] = $v['income_time'];
$excel_data_[] = $v['type'];
$excel_data_[] = $v['agent_name'];
$excel_data_[] = $v['store_name'];
$excel_data_[] = $v['house_id'];
$excel_data_[] = $v['address'];
$excel_data[] = $excel_data_;
}
$total_money = $refund->getSumMoney($where);
if (empty($excel_data)) {
return '<script>alert("导出失败");window.close();</script>';
}
$export = new ExportExcelUntil();
$title = ['提交时间', '退款ID', '状态', '订单ID', '收款ID', '退款金额', '入账日期', '退款类型', '提交人', '所属门店', '商铺ID', '商铺地址'];
$export->exportTable('退款审核明细表', $excel_data, 11, '退款审核明细表 (退款总计:' . $total_money . ')', $title);
return '';
}
/**
* 删除退款
*
* @return \think\Response
*/
public function delRefund()
{
$code = 101;
if (empty($this->params['refund_id'])) {
return $this->response($code, '参数错误');
}
try {
$where['id'] = $this->params['refund_id'];
$where['status'] = ['<>', 2];
$m_refund = new ORefundModel();
$m_refund_log = new ORefundLogModel();
$data = $m_refund->getFind('id', $where);
if (empty($data['id'])) {
return $this->response($code, '退款信息错误');
}
$num = $m_refund->updateData(['is_del' => 1], ['id' => $this->params['refund_id']]);
$msg = '删除失败';
if ($num) {
$m_refund_log->updateData(['is_del' => 1], ['refund_id' => $this->params['refund_id']]);
$code = 200;
$msg = '删除成功';
}
} catch (\Exception $e) {
$msg = '内部错误:' . $e->getMessage();
}
return $this->response($code, $msg, []);
}
/**
* 退款详情
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function refundDetail()
{
if (empty($this->params['refund_id'])) {
return $this->response(101, '参数错误');
}
$code = 200;
$msg = '';
$m_refund = new ORefundModel();
$m_refund_log = new ORefundLogModel();
$m_pay_log = new OPayLogModel();
$m_img = new OImg();
$field = 'id,refund_money,receipt_number,type,refund_cause,refund_way,card_no,bank,name,phone,agent_id,status,pay_log_id,create_time';
$refund_data = $m_refund->selectRefundByOrderNo($field, ['id' => $this->params['refund_id'], 'is_del' => 0]);
if (empty($refund_data[0])) {
return $this->response(101, '退款信息错误');
}
$data = $refund_data[0];
if ($data['agent_id']) {
$m_store = new AAgents();
$store_name = $m_store->getAgentsStoreById(['a.id' => $data['agent_id']], 'a.name,b.store_name');
$data['store_name'] = $store_name['store_name'];
$data['agent_name'] = $store_name['name'];
} else {
$data['store_name'] = '';
$data['agent_name'] = '';
}
if ($data['pay_log_id']) {
$pay_field = 'a.income_time,c.internal_address as address,a.create_time,a.order_id,b.house_id';
$pay_data = $m_pay_log->getOrderHouse($pay_field, ['a.id' => $data['pay_log_id']]);
$data['address'] = $pay_data[0]['address'] ? $pay_data[0]['address'] : '';
$data['income_time'] = $pay_data[0]['income_time'];
$data['pay_create_time'] = $pay_data[0]['create_time'];
$data['order_id'] = $pay_data[0]['order_id'];
$data['house_id'] = $pay_data[0]['house_id'];
} else {
$data['address'] = '';
$data['income_time'] = '';
}
$img_where['img_id'] = $this->params['refund_id'];
$img_where['img_type'] = 3;
$img_where['img_status'] = 1;
$data['img'] = $m_img->getImgList($img_where);
$data['log'] = $m_refund_log->getListAll('operation_name,create_time,status', ['refund_id' => $this->params['refund_id'], 'is_del' => 0]);
return $this->response($code, $msg, $data);
}
}
\ No newline at end of file
......@@ -243,8 +243,8 @@ Route::group('index', [
'backOutTwo/:check_status' => ['index/Finance/reportList', ['method' => 'get'], ['check_status' => 7]], //财务 成交报告-待撤销-第二级数据
'backOutThree/:check_status' => ['index/Finance/reportList', ['method' => 'get'], ['check_status' => 8]], //财务 成交报告-待撤销-第三级数据
'reportListUndone/:check_status' => ['index/Finance/reportList', ['method' => 'get'], ['check_status' => 6]], //财务 成交报告-已撤销
'refundList' => ['index/Finance/refundList', ['method' => 'get']], //退款列表-专员审核
'refundListExcel' => ['index/Finance/refundListExcel', ['method' => 'get']], //退款列表-导出excel
'refundList' => ['index/Refund/refundList', ['method' => 'get']], //退款列表-专员审核
'refundListExcel' => ['index/Refund/refundListExcel', ['method' => 'get']], //退款列表-导出excel
'checkReportAttache/:check_status' => ['index/Finance/checkReport', ['method' => 'post'], ['check_status' => 1]], //审核成交报告-第一级审核
'checkReportManager/:check_status' => ['index/Finance/checkReport', ['method' => 'post'], ['check_status' => 2]], //审核成交报告-第二级审核
'checkReportMajordomo/:check_status' => ['index/Finance/checkReport', ['method' => 'post'], ['check_status' => 3]], //审核成交报告-第三级审核
......@@ -299,9 +299,9 @@ Route::group('index', [
'getPayLogTotalPrice' => ['index/Finance/getPayLogTotalPrice', ['method' => 'get']],//佣金统计
'delPayLog' => ['index/Finance/delPayLog', ['method' => 'POST']],//删除收款
'refundPayLog' => ['index/Finance/refundPayLog', ['method' => 'POST']],//退款
'checkRefund' => ['index/Finance/checkRefund', ['method' => 'POST']],//退款审核
'refundDetail' => ['index/Finance/refundDetail', ['method' => 'GET']],//退款详情
'delRefund' => ['index/Finance/delRefund', ['method' => 'POST']],//删除退款
'checkRefund' => ['index/Refund/checkRefund', ['method' => 'POST']],//退款审核
'refundDetail' => ['index/Refund/refundDetail', ['method' => 'GET']],//退款详情
'delRefund' => ['index/Refund/delRefund', ['method' => 'POST']],//删除退款
'recoveryBargain' => ['index/Finance/recoveryBargain', ['method' => 'POST']],//撤销列表-恢复成交报告
'payCheckList' => ['index/PayLogOpen/payCheckList', ['method' => 'GET']],//收款开业审核-视图
'payCheckListOne/:check_status' => ['index/PayLogOpen/payCheckList', ['method' => 'GET'], ['check_status' => 1]],//收款开业审核-财务一审
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment