...
|
...
|
@@ -10,6 +10,7 @@ namespace api\portal\controller; |
|
|
|
|
|
|
|
|
use api\portal\model\AgencyModel;
|
|
|
use api\portal\model\OrderModel;
|
|
|
use api\portal\model\UserNeedModel;
|
|
|
use cmf\controller\HomeBaseController;
|
|
|
use api\portal\model\PortalPostModel;
|
...
|
...
|
@@ -264,6 +265,8 @@ class ThirdsendController extends HomeBaseController |
|
|
}else{
|
|
|
$change_final['id'] = $getv;
|
|
|
$change_final['status'] = 3;
|
|
|
// 中介报价未进入决赛,执行订单退款
|
|
|
$refund_result = $this->agency_order_refund($getv,'中介报价未进入决赛圈退款');
|
|
|
}
|
|
|
$agencyModel = new AgencyModel();
|
|
|
$fianl_AgsaveFirst = $agencyModel->isUpdate(true)->save($change_final);
|
...
|
...
|
@@ -291,18 +294,21 @@ class ThirdsendController extends HomeBaseController |
|
|
if(!$fianl_AgsaveNext){
|
|
|
Db::rollback();
|
|
|
}
|
|
|
// 中介报价订单退款
|
|
|
$refund_result = $this->agency_order_refund($changeva,'中介报价少于3人退款');
|
|
|
|
|
|
// 退回中介保证金
|
|
|
$add_a['user_id'] = $changeva['agency_id'];
|
|
|
$add_a['title'] = '报价人数不足';
|
|
|
$add_a['type'] = 1;
|
|
|
$add_a['reason'] = 1;
|
|
|
$add_a['money'] = $changeva['deposit'];
|
|
|
$add_a['create_time'] = time();
|
|
|
$add_a['update_time'] = time();
|
|
|
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
|
|
|
if (!$amoney_id) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
// $add_a['user_id'] = $changeva['agency_id'];
|
|
|
// $add_a['title'] = '报价人数不足';
|
|
|
// $add_a['type'] = 1;
|
|
|
// $add_a['reason'] = 1;
|
|
|
// $add_a['money'] = $changeva['deposit'];
|
|
|
// $add_a['create_time'] = time();
|
|
|
// $add_a['update_time'] = time();
|
|
|
// $amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
|
|
|
// if (!$amoney_id) {
|
|
|
// Db::rollback();
|
|
|
// }
|
|
|
// 用户表增加金额
|
|
|
$where_member['type'] = 2;
|
|
|
$where_member['id'] = $changeva['agency_id'];
|
...
|
...
|
@@ -320,21 +326,24 @@ class ThirdsendController extends HomeBaseController |
|
|
Db::rollback();
|
|
|
}
|
|
|
|
|
|
// 用户需求订单退款
|
|
|
$refund_result = $this->need_order_refund($userNeedList,'报价人数不足');
|
|
|
|
|
|
// 退回保证金
|
|
|
// 用户
|
|
|
// 加用户金额明细表
|
|
|
$add_del['need_id'] = $userNeedList['id'];
|
|
|
$add_del['user_id'] = $userNeedList['user_id'];
|
|
|
$add_del['title'] = '报价人数不足';
|
|
|
$add_del['reason'] = 1;
|
|
|
$add_del['type'] = 1;
|
|
|
$add_del['money'] = $userNeedList['pay_money'];
|
|
|
$add_del['create_time'] = time();
|
|
|
$add_del['update_time'] = time();
|
|
|
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
|
|
|
if (!$umoney_id) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
// $add_del['need_id'] = $userNeedList['id'];
|
|
|
// $add_del['user_id'] = $userNeedList['user_id'];
|
|
|
// $add_del['title'] = '报价人数不足';
|
|
|
// $add_del['reason'] = 1;
|
|
|
// $add_del['type'] = 1;
|
|
|
// $add_del['money'] = $userNeedList['pay_money'];
|
|
|
// $add_del['create_time'] = time();
|
|
|
// $add_del['update_time'] = time();
|
|
|
// $umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
|
|
|
// if (!$umoney_id) {
|
|
|
// Db::rollback();
|
|
|
// }
|
|
|
$where_memberNext['type'] = 1;
|
|
|
$where_memberNext['id'] = $userNeedList['user_id'];
|
|
|
$add_moneyNext = Db::name('Member')->where($where_memberNext)->setInc('money',$userNeedList['pay_money']);
|
...
|
...
|
@@ -351,22 +360,24 @@ class ThirdsendController extends HomeBaseController |
|
|
if(!$fianl_Ussave){
|
|
|
Db::rollback();
|
|
|
}
|
|
|
// 用户需求订单退款
|
|
|
$refund_result = $this->need_order_refund($userNeedList,'报价人数不足');
|
|
|
|
|
|
// 退回保证金
|
|
|
// 用户
|
|
|
// 加用户金额明细表
|
|
|
$add_del['need_id'] = $userNeedList['id'];
|
|
|
$add_del['user_id'] = $userNeedList['user_id'];
|
|
|
$add_del['title'] = '报价人数不足';
|
|
|
$add_del['type'] = 1;
|
|
|
$add_del['money'] = $userNeedList['pay_money'];
|
|
|
$add_del['create_time'] = time();
|
|
|
$add_del['update_time'] = time();
|
|
|
$umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
|
|
|
if (!$umoney_id) {
|
|
|
Db::rollback();
|
|
|
$this->apiResponse('0','金额明细添加失败');
|
|
|
}
|
|
|
// $add_del['need_id'] = $userNeedList['id'];
|
|
|
// $add_del['user_id'] = $userNeedList['user_id'];
|
|
|
// $add_del['title'] = '报价人数不足';
|
|
|
// $add_del['type'] = 1;
|
|
|
// $add_del['money'] = $userNeedList['pay_money'];
|
|
|
// $add_del['create_time'] = time();
|
|
|
// $add_del['update_time'] = time();
|
|
|
// $umoney_id = Db::name('UmoenyDetail')->insertGetId($add_del);
|
|
|
// if (!$umoney_id) {
|
|
|
// Db::rollback();
|
|
|
// $this->apiResponse('0','金额明细添加失败');
|
|
|
// }
|
|
|
$where_memberNext['type'] = 1;
|
|
|
$where_memberNext['id'] = $userNeedList['user_id'];
|
|
|
$add_moneyNext = Db::name('Member')->where($where_memberNext)->setInc('money',$userNeedList['pay_money']);
|
...
|
...
|
@@ -426,6 +437,10 @@ class ThirdsendController extends HomeBaseController |
|
|
if (!$agency_result) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
foreach ($agency_list as $agency_key=>$agency_val) {
|
|
|
// 中介报价订单退款
|
|
|
$refund_result = $this->agency_order_refund($agency_val,'用户未选择中标中介退款');
|
|
|
}
|
|
|
}
|
|
|
$where_needUpdate['id'] = $userNeedList['id'];
|
|
|
$needUpdate['status'] = 6;
|
...
|
...
|
@@ -446,25 +461,25 @@ class ThirdsendController extends HomeBaseController |
|
|
Db::rollback();
|
|
|
}
|
|
|
// 中介金额明细表
|
|
|
foreach ($agency_list as $agenk=>$agenv){
|
|
|
$add_a['ag_id'] = $agenv['id'];
|
|
|
$add_a['user_id'] = $agenv['agency_id'];
|
|
|
$add_a['title'] = '用户未选择中介';
|
|
|
$add_a['type'] = 1;
|
|
|
$add_a['money'] = $agenv['deposit'];
|
|
|
$add_a['create_time'] = time();
|
|
|
$add_a['update_time'] = time();
|
|
|
$amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
|
|
|
if (!$amoney_id) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
$where_member['type'] = 2;
|
|
|
$where_member['id'] = $agenv['agency_id'];
|
|
|
$add_money = Db::name('Member')->where($where_member)->setInc('money',$agenv['deposit']);
|
|
|
if (!$add_money) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
}
|
|
|
// foreach ($agency_list as $agenk=>$agenv){
|
|
|
// $add_a['ag_id'] = $agenv['id'];
|
|
|
// $add_a['user_id'] = $agenv['agency_id'];
|
|
|
// $add_a['title'] = '用户未选择中介';
|
|
|
// $add_a['type'] = 1;
|
|
|
// $add_a['money'] = $agenv['deposit'];
|
|
|
// $add_a['create_time'] = time();
|
|
|
// $add_a['update_time'] = time();
|
|
|
// $amoney_id = Db::name('AmoenyDetail')->insertGetId($add_a);
|
|
|
// if (!$amoney_id) {
|
|
|
// Db::rollback();
|
|
|
// }
|
|
|
// $where_member['type'] = 2;
|
|
|
// $where_member['id'] = $agenv['agency_id'];
|
|
|
// $add_money = Db::name('Member')->where($where_member)->setInc('money',$agenv['deposit']);
|
|
|
// if (!$add_money) {
|
|
|
// Db::rollback();
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -949,6 +964,105 @@ class ThirdsendController extends HomeBaseController |
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 需求订单退款
|
|
|
* @param needInfo 用户需求信息
|
|
|
* @param reason 退款原因
|
|
|
*/
|
|
|
private function need_order_refund($needInfo,$reason) {
|
|
|
$order_model = new OrderModel();
|
|
|
$where = [
|
|
|
'user_id' => $needInfo['user_id'],
|
|
|
'type' => 1,
|
|
|
'need_id' => $needInfo['id'],
|
|
|
'is_get' => 2,
|
|
|
'status' => 2
|
|
|
];
|
|
|
// 根据不同订单类型执行退款操作
|
|
|
$orderInfo = $order_model->where($where)->find();
|
|
|
$transaction_id = $orderInfo['transaction_id'];
|
|
|
$order_sn = $orderInfo['order_sn'];
|
|
|
$money = $orderInfo['money'];
|
|
|
$out_refund_no = cmf_get_order_sn();
|
|
|
// 微信
|
|
|
$refund_result = false;
|
|
|
if($orderInfo['pay_type'] == 1 || $orderInfo['pay_type'] == 2) {
|
|
|
$refund_result = $this->wxpay_refund($transaction_id,$out_refund_no,$money,$money,$reason);
|
|
|
}
|
|
|
// 支付宝
|
|
|
if($orderInfo['pay_type'] == 3 || $orderInfo['pay_type'] == 4) {
|
|
|
$refund_result = $this->alipay_refund($transaction_id,$order_sn,$money,$reason);
|
|
|
}
|
|
|
return $refund_result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 中介报价退款
|
|
|
* @param agencyInfo 中介报价信息
|
|
|
* @param reason 退款原因
|
|
|
*/
|
|
|
private function agency_order_refund($agencyInfo,$reason) {
|
|
|
$order_model = new OrderModel();
|
|
|
$where = [
|
|
|
'user_id' => $agencyInfo['agency_id'],
|
|
|
'type' => 2,
|
|
|
'need_id' => $agencyInfo['id'],
|
|
|
'is_get' => 2,
|
|
|
'status' => 2
|
|
|
];
|
|
|
// 根据不同订单类型执行退款操作
|
|
|
$orderInfo = $order_model->where($where)->find();
|
|
|
$transaction_id = $orderInfo['transaction_id'];
|
|
|
$order_sn = $orderInfo['order_sn'];
|
|
|
$money = $orderInfo['money'];
|
|
|
$out_refund_no = cmf_get_order_sn();
|
|
|
$refund_result = false;
|
|
|
// 微信
|
|
|
if($orderInfo['pay_type'] == 1 || $orderInfo['pay_type'] == 2) {
|
|
|
$refund_result = $this->wxpay_refund($transaction_id,$out_refund_no,$money,$money,$reason);
|
|
|
}
|
|
|
// 支付宝
|
|
|
if($orderInfo['pay_type'] == 3 || $orderInfo['pay_type'] == 4) {
|
|
|
$refund_result = $this->alipay_refund($transaction_id,$order_sn,$money,$reason);
|
|
|
}
|
|
|
return $refund_result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 支付宝退款接口(两个订单号不能同时为空)
|
|
|
* @param trade_no 支付宝交易号
|
|
|
* @param out_trade_no 商户支付订单号
|
|
|
* @param refund_amount 退款金额
|
|
|
* @param refund_reason 退款原因
|
|
|
* @param out_request_no 如需部分退款,传此参数
|
|
|
*/
|
|
|
private function alipay_refund($trade_no = null, $out_trade_no = null, $refund_amount, $refund_reason, $out_request_no = null) {
|
|
|
$refund = controller('Alipay','controller');
|
|
|
$data = [
|
|
|
'trade_no' => $trade_no,
|
|
|
'out_trade_no' => $out_trade_no,
|
|
|
'refund_amount' => $refund_amount,
|
|
|
'refund_reason' => $refund_reason,
|
|
|
'out_request_no' => $out_request_no
|
|
|
];
|
|
|
return $refund->refund($data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 微信退款接口(两个订单号不能同时为空)
|
|
|
* @param transaction_id 微信业务订单号
|
|
|
* @param out_refund_no 商户退款订单号
|
|
|
* @param total_fee 订单金额
|
|
|
* @param refund_fee 退款金额
|
|
|
* @param refund_desc 退款原因
|
|
|
*/
|
|
|
private function wxpay_refund($transaction_id = null, $out_refund_no = null, $total_fee, $refund_fee, $refund_desc) {
|
|
|
require_once VENDOR_PATH.'WxpayAPI/WxRefund.php';
|
|
|
$refund = new \WxRefund(Config::get('wx_appid'),Config::get('wx_mch_id'),Config::get('wx_key'),$transaction_id,
|
|
|
$out_refund_no,$total_fee,$refund_fee,$refund_desc);
|
|
|
return $refund->pay();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|