Commit 76619ab7 authored by clone's avatar clone

1

parent 609a955a
<?php
namespace app\api_broker\controller;
use app\api_broker\extend\Basic;
use app\api_broker\service\OfficePayLogService;
use app\api_broker\service\PayLogService;
use think\Request;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/12/13
* Time : 3:41 PM
* Intro:
*/
class OfficePayLog extends Basic
{
private $service_;
public function __construct(Request $request = null)
{
parent::__construct($request);
$this->service_ = new OfficePayLogService();
}
/**
* 获取上次提交收款的门牌号等
* @return \think\Response
*/
public function getBeForNum()
{
$params = $this->params;
/* $params = array(
"order_id" => 15523, //关联order表id
);*/
if (!isset($params["order_id"])) {
return $this->response("101", "订单编号不能为空");
}
$billInfo = $this->service_->getBeForNum($params["order_id"]);
if (count($billInfo) > 0) {
return $this->response("200", "request success", $billInfo[0]);
} else {
return $this->response("200", "request null");
}
}
/**
* 剩余可以调整或退款的钱
* @return \think\Response
*/
public function adjustment()
{
$params = $this->params;
/* $params = array(
"pay_id" => 1,
);*/
if (empty($params["pay_id"])) {
return $this->response("101", "请求参数错误");
}
$result = $this->service_->adjustment($params["pay_id"]);
if ($result == -1) {
return $this->response("101", "不存在此条记录");
}
return $this->response("200", "success", ["residue_money" => $result]);
}
/**
* 新增或编辑退款申请
* @return \think\Response
* @throws \think\Exception
*/
public function refund()
{
$params = $this->params;
if (!isset($params["agent_id"]) || !isset($params["agent_name"]) || !isset($params["report_id"]) ||
!isset($params["order_id"]) || !isset($params["order_no"]) || !isset($params["name"]) || !isset($params["phone"])
|| !isset($params["refund_money"]) || !isset($params["bank"]) || !isset($params["card_no"])
|| !isset($params["receipt_number"]) || !isset($params["type"])
|| !isset($params["refund_cause"]) || !isset($params["refund_way"])) {
return $this->response("101", "请求参数错误");
}
/* $params = array(
"agent_id" => 1,//退款经纪人id
"agent_name" => 1,//退款经纪人id
"report_id" => 1,//报备id
"order_id" => 1, //关联order表id
"order_no" => "12312312312312", //订单no
"refund_money" => 1200, //退款金额
"name" => "qweqwe", //收款人姓名
"phone" => "123123123", //收款人电话
"bank" => "asdasdasd", //收款人银行
"card_no" => "123123123123", //银行卡号
"remark" => "没什么备注", //其他说明
"remark_img" => "12312312312",
"receipt_number" => "12312312312",
"type" => "12312312312", //退款类型:0退意向金1意向金转定2退保管金3保管金转定4退中介费5退案场费
"refund_cause" => "12312312312", //退款原因
"pay_log_id" => 1, //支付id
"refund_way" => 0, //退款方式:0银行卡
);*/
$refund_id = isset($params["refund_id"]) ? $params["refund_id"] : 0;
if($refund_id == 0 && !isset($params["remark_img"])){
return $this->response("101", "请上传图片");
}
$agent_id = $params["agent_id"];
$agent_name = $params["agent_name"];
$report_id = $params["report_id"];
$order_id = $params["order_id"];
$order_no = $params["order_no"];
$refund_money = $params["refund_money"];
$name = $params["name"];
$phone = $params["phone"];
$bank = $params["bank"];
$card_no = $params["card_no"];
$receipt_number = $params["receipt_number"];
$type = $params["type"];
$refund_cause = $params["refund_cause"];
$pay_log_id = $params["pay_log_id"];
$refund_way = $params["refund_way"];
$remark = isset($params["remark"]) ? $params["remark"] : "";
$remark_img = isset($params["remark_img"]) ? json_decode($params["remark_img"], true) : "";
$del_img =isset($params["del_img"]) ? $params["del_img"] : "";
//todo 判断此单是否有付款
$is_ok = $this->service_->addRefund($agent_id, $agent_name, $report_id, $order_id, $order_no, $refund_money, $name,
$phone, $bank, $card_no, $receipt_number, $type, $refund_cause, $pay_log_id, $refund_way, $remark, $remark_img
,$refund_id,$del_img);
if ($is_ok > 0) {
return $this->response("200", "request success", []);
} elseif ($is_ok == -2) {
return $this->response("101", "退款金不能大于剩余的支付金额");
} elseif ($is_ok == -3) {
return $this->response("101", "有财务驳回退款,请在原退款上修改.");
}
return $this->response("101", "request faild");
}
/**
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getRefund(){
$params = $this->params;
/* $params = array(
"refund_id" =>1
);*/
if(!isset($params["refund_id"])){
return $this->response("101","请求参数错误");
}
$result = $this->service_->getRefundDetail($params["refund_id"]);
if($result["code"] == 200){
return $this->response("200","success",$result["data"]);
}elseif($result["code"] == 101){
return $this->response("101",$result["msg"]);
}
}
}
\ No newline at end of file
<?php
namespace app\api_broker\service;
use app\model\OfficeOPayLogAdjustment;
use app\model\OfficeOPayLogModel;
use app\model\OfficeORefundModel;
use app\model\OImg;
use app\model\OPayLogAdjustment;
use app\model\OPayLogModel;
use app\model\ORefundModel;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/12/13
* Time : 3:45 PM
* Intro:
*/
class OfficePayLogService
{
private $payLogModel;
private $payLogAdjustmentModel;
private $oRefundModel;
public function __construct()
{
$this->payLogModel = new OfficeOPayLogModel();
$this->payLogAdjustmentModel = new OfficeOPayLogAdjustment();
$this->oRefundModel = new OfficeORefundModel();
}
public function getBeForNum($order_id)
{
$filed = "house_number,industry_type";
return $this->payLogModel->getBeforeBillInfo($filed, ["order_id" => $order_id]);
}
/**
* 计算可以分佣的金额
* @param $pay_id
* @param $type
* @return int
*/
public function adjustment($pay_id,$type = 1)
{
//todo 1.计算剩余金额 查询调整表 2.减去退款 3.减去转账
$filed = "id,money";
$pay_log_arr = $this->payLogModel->getBeforeBillInfo($filed, ["id" => $pay_id]);
if (count($pay_log_arr) < 0) {
return -1;
}
$pay_log_arr = $pay_log_arr[0];
$where_["paylog_id"] = $pay_id;
$where_["is_del"] = 0;
//调整
$adjustment_sum = $this->payLogAdjustmentModel->getAdjustmentSum("money", $where_);
//减去退款
$refund_params["pay_log_id"] = $pay_id;
if($type == 2){
//驳回退款 不会改变入账的状态,驳回退款是为了让店长重新编辑上传的东西。
$refund_params["status"] = array("neq", 4);
}
$refund_sum = $this->oRefundModel->getRefundSum("refund_money", $refund_params);
$residue_money = $pay_log_arr["money"] - $adjustment_sum - $refund_sum;
return $residue_money;
}
/**
* @param $new_pay_id
* @param $pay_id
* @param $money
* @param $type
* @param $agent_id
* @return int
*/
public function addAdjustment($new_pay_id, $pay_id, $money, $type, $agent_id)
{
$filed = "id,type";
$pay_log_arr = $this->payLogModel->getBeforeBillInfo($filed, ["id" => $pay_id]);
if (count($pay_log_arr) < 0) {
return -1;
}
$oPayLogAdjustment = new OPayLogAdjustment();
$where_ = $this->adjustmentBin($new_pay_id, $pay_id, $money, $type, $agent_id, $pay_log_arr[0]["type"]);
$oPayLogAdjustment->addAdjustment($where_);
}
/**
* @param $new_pay_id
* @param $pay_id
* @param $money
* @param $type
* @param $agent_id
* @param $old_type
* @return mixed
*/
private function adjustmentBin($new_pay_id, $pay_id, $money, $type, $agent_id, $old_type)
{
$arr["paylog_id"] = $pay_id;
$arr["new_paylog_id"] = $new_pay_id;
$arr["money"] = $money;
$val = 0;
if ($old_type == 10) {//意向金
switch ($type) {
case 10:
$val = 3;
break;
case 91:
$val = 1;
break;
case 92:
$val = 2;
break;
case 30:
$val = 7;
break;
default:
}
} elseif ($old_type == 30) {//保管金
switch ($type) {
case 30:
$val = 6;
break;
case 91:
$val = 4;
break;
case 92:
$val = 5;
break;
default:
}
}
$arr["type"] = $val;
$arr["operation_id"] = $agent_id;
$arr["create_time"] = date("Y-m-d H:i:s", time());
$arr["update_time"] = date("Y-m-d H:i:s", time());
return $arr;
}
/**
* 退款
* @param $agent_id
* @param $agent_name
* @param $report_id
* @param $order_id
* @param $order_no
* @param $refund_money
* @param $name
* @param $phone
* @param $bank
* @param $card_no
* @param $receipt_number
* @param $type
* @param $refund_cause
* @param $pay_log_id
* @param $refund_way
* @param $remark
* @param $remark_img
* @return int|string
* @throws \think\Exception
*/
public function addRefund($agent_id, $agent_name, $report_id, $order_id, $order_no, $refund_money, $name,
$phone, $bank, $card_no, $receipt_number, $type, $refund_cause, $pay_log_id,
$refund_way, $remark, $remark_img, $refund_id, $del_img)
{
if (empty($refund_id)) {
$where['pay_log_id'] = $pay_log_id;
$where['status'] = 4;
$where['is_del'] = 0;
$id = $this->oRefundModel->getFind('id', $where);
if ($id['id'] > 0) {
return -3; //在驳回上修改
}
}
//验证金额是否合法
$payLogService = new PayLogService();
$residue_money = $payLogService->adjustment($pay_log_id,2);
if ($residue_money < $refund_money) {
return -2;
}
$insert_id = 0;
$arr = $this->refundBin($agent_id, $agent_name, $report_id, $order_id, $order_no, $refund_money, $name,
$phone, $bank, $card_no, $receipt_number, $type, $refund_cause, $pay_log_id,$refund_way, $remark,$refund_id);
if ($refund_id <= 0) {
$insert_id = $this->oRefundModel->addRefund($arr);
} else {
$insert_id = $this->oRefundModel->updateRefund($arr);
$insert_id = $refund_id;
}
if ($insert_id > 0 && $remark_img) {
$this->addOImg($insert_id, 3, $remark_img);
}
if($del_img){
$this->delOImg(3,$del_img);
}
$service_push = new PushMessageService();
$service_push->pushRefund($agent_id, $report_id, $order_id);
return $insert_id;
}
/**
* @param $agent_id
* @param $agent_name
* @param $report_id
* @param $order_id
* @param $order_no
* @param $refund_money
* @param $name
* @param $phone
* @param $bank
* @param $card_no
* @param $receipt_number
* @param $type
* @param $refund_cause
* @param $pay_log_id
* @param $refund_way
* @param $remark
* @return mixed
*/
private function refundBin($agent_id, $agent_name, $report_id, $order_id, $order_no, $refund_money, $name,
$phone, $bank, $card_no, $receipt_number, $type, $refund_cause, $pay_log_id,
$refund_way, $remark,$refund_id)
{
if($refund_id > 0){ //修改
$arr["id"] = $refund_id;
}else{
$arr["create_time"] = date("Y-m-d H:i:s", time());
}
$arr["report_id"] = $report_id;
$arr["agent_id"] = $agent_id;
$arr["agent_name"] = $agent_name;
$arr["order_no"] = $order_no;
$arr["order_id"] = $order_id;
$arr["refund_money"] = $refund_money;
$arr["name"] = $name;
$arr["phone"] = $phone;
$arr["status"] = 0;
$arr["bank"] = $bank;
$arr["card_no"] = $card_no;
$arr["remark"] = $remark;
$arr["receipt_number"] = $receipt_number;
$arr["type"] = $type;
$arr["refund_cause"] = $refund_cause;
$arr["pay_log_id"] = $pay_log_id;
$arr["refund_way"] = $refund_way;
$arr["update_time"] = date("Y-m-d H:i:s", time());
return $arr;
}
/**
* @param $id
* @param $type
* @param $transfer_img
* @throws \think\Exception
*/
private function addOImg($id, $type, $transfer_img)
{
$oImgModel = new OImg();
$oImgModel->addImgAll($id, $type, $transfer_img);
}
/**
* @param $id
* @param $img_type
* @return false|\PDOStatement|string|\think\Collection
*/
private function getOImg($id, $img_type)
{
//查询图片
$oImgModel = new OImg();
$params["img_id"] = $id;
$params["img_type"] = $img_type;
$img_arr = $oImgModel->getImgList($params);
return $img_arr;
}
/**
* @param $type
* @param $del_img
*/
private function delOImg($type, $del_img){
$oImgModel = new OImg();
$ids = rtrim($del_img, ",");
$where_["id"] = array("in",$ids);
$where_["img_type"] = $type;
$params["img_status"] = 1;
$oImgModel->updateImgs($where_, $params);
}
/**
* @param $refund_id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getRefundDetail($refund_id)
{
$field = "a.id,a.report_id,a.agent_id,a.agent_name,a.order_no,a.order_id,a.refund_money,a.status,a.name
,a.phone,a.bank,a.card_no, a.remark,a.receipt_number,a.type,a.refund_cause,a.pay_log_id,a.refund_way,
a.create_time,b.income_time";
$params["id"] = $refund_id;
$params["is_del"] = 0;
$result = $this->oRefundModel->selectRefundDetailByOrderNo($field, $params);
if (count($result) > 0) {
$item = $result[0];
$item["img_path"] = CHAT_IMG_URL;
$item["img_arr"] = $this->getOImg($item["id"], 3);
return ["code" => 200, "data" => $item];
} else {
return ["code" => 101, "msg" => "没有找到此条退款数据"];
}
}
/**
* 计算收款-退款
*
* @param $bargain_id
* @return bool|float|int
*/
public function getPayLogRefundSurplusMoney($bargain_id) {
if (empty($bargain_id)) {
return false;
}
$pay_id = $this->payLogModel->getFieldColumn('id', ['bargain_id'=>$bargain_id]);
if (empty($pay_id)) {
return false;
}
$money = $this->payLogModel->getSum('money', ['id'=> ['in', $pay_id]]);
if ($money > 0) {
$refund_money = $this->oRefundModel->getRefundSum('refund_money', ['pay_log_id'=>['in', $pay_id]]);
$result = $money - $refund_money;
} else {
$result = 0;
}
return $result;
}
/**
* @param $bargain_id
* @return bool
*/
public function checkPayLogAdjustment($bargain_id) {
if (empty($bargain_id)) {
return false;
}
$result = false;
$pay_id = $this->payLogModel->getFieldColumn('id', ['bargain_id'=>$bargain_id]);
$id = $this->payLogAdjustmentModel->getFieldValue('id', ['paylog_id'=> ['in', $pay_id]]);
if ($id > 0) {
$result = true;
}
return $result;
}
}
\ No newline at end of file
......@@ -929,6 +929,8 @@ Route::group('broker', [
'getOpenList' => ['api_broker/PayLogOpen/getOpenList', ['method' => 'GET|POST']],
'openCheck' => ['api_broker/PayLogOpen/openCheck', ['method' => 'GET|POST']],
'refund' => ['api_broker/PayLogOpen/refund', ['method' => 'get|post']],
'getRefund' => ['api_broker/PayLogOpen/getRefund', ['method' => 'get|post']],
]);
......@@ -988,9 +990,12 @@ Route::group('office', [
'reportListForPc' => ['api_broker/OfficeReport/reportListForPc', ['method' => 'get']],
'appAgentAuth' => ['api_broker/OfficeReport/appAgentAuth', ['method' => 'get']],
'getRoomListByReport' => ['api_broker/OfficeRoom/getRoomListByReport', ['method' => 'get|post']],
'addShopFollowUp' => ['api_broker/OfficeRoom/addShopFollowUp', ['method' => 'get|post']],
'getMyBuildingRoom' => ['api_broker/OfficeRoom/getMyBuildingRoom', ['method' => 'get|post']],
'getRoomListByReport' => ['api_broker/OfficeRoom/getRoomListByReport', ['method' => 'get|post']],
'addShopFollowUp' => ['api_broker/OfficeRoom/addShopFollowUp', ['method' => 'get|post']],
'getMyBuildingRoom' => ['api_broker/OfficeRoom/getMyBuildingRoom', ['method' => 'get|post']],
'getBeForNum' => ['api_broker/OfficePayLog/getBeForNum', ['method' => 'get|post']],
'adjustment' => ['api_broker/OfficePayLog/adjustment', ['method' => 'get|post']],
]);
Route::group('office_index', [
......
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