...
|
...
|
@@ -11,6 +11,7 @@ namespace api\portal\controller; |
|
|
|
|
|
use api\portal\model\AgencyModel;
|
|
|
use api\portal\model\OrderModel;
|
|
|
use api\portal\model\RefundModel;
|
|
|
use api\portal\model\UserNeedModel;
|
|
|
use cmf\controller\HomeBaseController;
|
|
|
use api\portal\model\PortalPostModel;
|
...
|
...
|
@@ -181,6 +182,7 @@ class ThirdsendController extends HomeBaseController |
|
|
if(!$userNeedList){
|
|
|
$this->apiResponse('0','需求状态不正确');
|
|
|
}
|
|
|
$userNeedList['user_type'] = Db::name('Member')->where(['id'=>$userNeedList['user_id']])->value('type');
|
|
|
$time = time();
|
|
|
// 查询相应报价
|
|
|
$final_time = $userNeedList['pay_time'] + $userNeedList['quotation_time'] * 86400;
|
...
|
...
|
@@ -195,24 +197,23 @@ class ThirdsendController extends HomeBaseController |
|
|
$agency_list = Db::name('Agency')->alias('a')
|
|
|
->where($where_agency)
|
|
|
->join("hp_Member m", 'm.id = a.agency_id')
|
|
|
->field('a.*,m.company')
|
|
|
->field('a.*,m.company,m.type as user_type')
|
|
|
->select()->toArray();
|
|
|
// 查询品牌企业
|
|
|
$where_brand['status'] = 1;
|
|
|
$band_list = Db::name('Brand')->where($where_brand)->column('name');
|
|
|
$agen_arr = array();
|
|
|
$agen_arr = $is_trueMoney = array();
|
|
|
if ($agency_list) {
|
|
|
$get_list = array();
|
|
|
// 删除十万以内报价
|
|
|
foreach ($agency_list as $tenk=>$tenv){
|
|
|
$ten_money = $tenv['housing_price'] * 10000 + $tenv['assessment_tax'] + $tenv['security_tax'] + $tenv['else_tax'] + $tenv['service_charge'];
|
|
|
if($ten_money > 1000000){
|
|
|
if($ten_money > 100000){
|
|
|
$is_trueMoney[] = $tenv;
|
|
|
}
|
|
|
}
|
|
|
// 判断是否超过三个报价人
|
|
|
if (count($is_trueMoney) >= 3) {
|
|
|
|
|
|
|
|
|
// 查询三人中是否有品牌中介
|
|
|
// 循环匹配品牌企业
|
|
|
foreach ($is_trueMoney as $agencyk => $agencyv) {
|
...
|
...
|
@@ -257,6 +258,8 @@ class ThirdsendController extends HomeBaseController |
|
|
}else{
|
|
|
$get_list = $fin_arr;
|
|
|
}
|
|
|
}else{
|
|
|
$get_list = $fin_arr;
|
|
|
}
|
|
|
foreach ($else_changeList as $getk=>$getv){
|
|
|
if(in_array($getv,$get_list)){
|
...
|
...
|
@@ -266,7 +269,12 @@ class ThirdsendController extends HomeBaseController |
|
|
$change_final['id'] = $getv;
|
|
|
$change_final['status'] = 3;
|
|
|
// 中介报价未进入决赛,执行订单退款
|
|
|
$refund_result = $this->agency_order_refund($getv,'中介报价未进入决赛圈退款');
|
|
|
$agencyInfo = Db::name('Agency')->alias('a')
|
|
|
->where(['a.id'=>$getv])
|
|
|
->join("hp_Member m", 'm.id = a.agency_id')
|
|
|
->field('a.*,m.company,m.type as user_type')
|
|
|
->find();
|
|
|
$refund_result = $this->agency_order_refund($agencyInfo,'中介报价未进入决赛圈退款',2);
|
|
|
}
|
|
|
$agencyModel = new AgencyModel();
|
|
|
$fianl_AgsaveFirst = $agencyModel->isUpdate(true)->save($change_final);
|
...
|
...
|
@@ -275,7 +283,7 @@ class ThirdsendController extends HomeBaseController |
|
|
}
|
|
|
}
|
|
|
// 报价成功,更改状态
|
|
|
$userSave_statusFirst['id'] = $userNeedList['need_id'];
|
|
|
$userSave_statusFirst['id'] = $userNeedList['id'];
|
|
|
$userSave_statusFirst['status'] = 5;
|
|
|
$userSave_statusFirst['choose_time'] = time();
|
|
|
$userNeedModel = new UserNeedModel();
|
...
|
...
|
@@ -295,28 +303,7 @@ class ThirdsendController extends HomeBaseController |
|
|
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();
|
|
|
// }
|
|
|
// 用户表增加金额
|
|
|
$where_member['type'] = 2;
|
|
|
$where_member['id'] = $changeva['agency_id'];
|
|
|
$add_money = Db::name('Member')->where($where_member)->setInc('money',$changeva['deposit']);
|
|
|
if (!$add_money) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
|
|
|
$refund_result = $this->agency_order_refund($changeva,'中介报价少于3人退款',1);
|
|
|
}
|
|
|
$userSave_status['id'] = $userNeedList['id'];
|
|
|
$userSave_status['status'] = 4;
|
...
|
...
|
@@ -327,29 +314,7 @@ class ThirdsendController extends HomeBaseController |
|
|
}
|
|
|
|
|
|
// 用户需求订单退款
|
|
|
$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();
|
|
|
// }
|
|
|
$where_memberNext['type'] = 1;
|
|
|
$where_memberNext['id'] = $userNeedList['user_id'];
|
|
|
$add_moneyNext = Db::name('Member')->where($where_memberNext)->setInc('money',$userNeedList['pay_money']);
|
|
|
if (!$add_moneyNext) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
$refund_result = $this->need_order_refund($userNeedList,'报价人数不足',1);
|
|
|
}
|
|
|
} else {
|
|
|
// 没有报价
|
...
|
...
|
@@ -361,30 +326,7 @@ 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['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']);
|
|
|
if (!$add_moneyNext) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
|
|
|
$refund_result = $this->need_order_refund($userNeedList,'报价人数不足',1);
|
|
|
}
|
|
|
// 插入数据库
|
|
|
// 用户需求表
|
...
|
...
|
@@ -396,7 +338,6 @@ class ThirdsendController extends HomeBaseController |
|
|
}else{
|
|
|
$this->apiResponse('0','时间不正确');
|
|
|
}
|
|
|
|
|
|
// }
|
|
|
}
|
|
|
|
...
|
...
|
@@ -425,9 +366,13 @@ class ThirdsendController extends HomeBaseController |
|
|
if($userNeedList){
|
|
|
// foreach ($userNeedList as $needk=>$needv) {
|
|
|
if (time() >= ($userNeedList['choose_time'] + 259200)) {
|
|
|
$where_agency['need_id'] = $userNeedList['id'];
|
|
|
$where_agency['status'] = 4;
|
|
|
$agency_list = Db::name('Agency')->where($where_agency)->select()->toArray();
|
|
|
$where_agency['a.need_id'] = $userNeedList['id'];
|
|
|
$where_agency['a.status'] = 4;
|
|
|
$agency_list = Db::name('Agency')->alias('a')
|
|
|
->where($where_agency)
|
|
|
->join("hp_Member m", 'm.id = a.agency_id')
|
|
|
->field('a.*,m.company,m.type as user_type')
|
|
|
->select()->toArray();
|
|
|
if ($agency_list) {
|
|
|
$where_agencyUpdate['need_id'] = $userNeedList['id'];
|
|
|
$where_agencyUpdate['status'] = 4;
|
...
|
...
|
@@ -437,10 +382,6 @@ 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;
|
...
|
...
|
@@ -448,39 +389,12 @@ class ThirdsendController extends HomeBaseController |
|
|
if (!$need_result) {
|
|
|
Db::rollback();
|
|
|
} else {
|
|
|
// 加用户金额明细表
|
|
|
$add_del['need_id'] = $userNeedList['id'];
|
|
|
$add_del['user_id'] = $userNeedList['user_id'];
|
|
|
$add_del['title'] = '未选择中介';
|
|
|
$add_del['type'] = 2;
|
|
|
$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();
|
|
|
if ($agency_list) {
|
|
|
foreach ($agency_list as $agency_key => $agency_val) {
|
|
|
// 中介报价订单退款
|
|
|
$this->agency_order_refund($agency_val, '用户未选择中标中介退款',3);
|
|
|
}
|
|
|
}
|
|
|
// 中介金额明细表
|
|
|
// 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();
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
}
|
|
|
// }
|
...
|
...
|
@@ -530,18 +444,6 @@ class ThirdsendController extends HomeBaseController |
|
|
Db::rollback();
|
|
|
}
|
|
|
}
|
|
|
// 增加中介保证金变化
|
|
|
$add_a['ag_id'] = $agency['id'];
|
|
|
$add_a['user_id'] = $agency['agency_id'];
|
|
|
$add_a['title'] = '中介未确认';
|
|
|
$add_a['type'] = 2;
|
|
|
$add_a['money'] = $agency['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_needChange['id'] = $need_list['id'];
|
|
|
$update_need['status'] = 8;
|
...
|
...
|
@@ -550,24 +452,8 @@ class ThirdsendController extends HomeBaseController |
|
|
if (!$change_needFinal) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
// 增加用户保证金,余额
|
|
|
$add_del['need_id'] = $need_list['id'];
|
|
|
$add_del['user_id'] = $need_list['user_id'];
|
|
|
$add_del['title'] = '中介未确认';
|
|
|
$add_del['type'] = 1;
|
|
|
$add_del['money'] = $need_list['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_member['type'] = 1;
|
|
|
$where_member['id'] = $need_list['user_id'];
|
|
|
$add_money = Db::name('Member')->where($where_member)->setInc('money',$need_list['pay_money']);
|
|
|
if (!$add_money) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
$need_list['user_type'] = Db::name('Member')->where(['id'=>$need_list['user_id']])->value('type');
|
|
|
$this->need_order_refund($agency,'中介未确认成交退款',5);
|
|
|
}
|
|
|
// }
|
|
|
Db::commit();
|
...
|
...
|
@@ -640,7 +526,7 @@ class ThirdsendController extends HomeBaseController |
|
|
// 删除十万以内报价
|
|
|
foreach ($agency_list as $tenk=>$tenv){
|
|
|
$ten_money = $tenv['housing_price'] * 10000 + $tenv['assessment_tax'] + $tenv['security_tax'] + $tenv['else_tax'] + $tenv['service_charge'];
|
|
|
if($ten_money > 1000000){
|
|
|
if($ten_money > 100000){
|
|
|
$is_trueMoney[] = $tenv;
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -969,7 +855,7 @@ class ThirdsendController extends HomeBaseController |
|
|
* @param needInfo 用户需求信息
|
|
|
* @param reason 退款原因
|
|
|
*/
|
|
|
private function need_order_refund($needInfo,$reason) {
|
|
|
public function need_order_refund($needInfo,$reason,$reason_id) {
|
|
|
$order_model = new OrderModel();
|
|
|
$where = [
|
|
|
'user_id' => $needInfo['user_id'],
|
...
|
...
|
@@ -980,18 +866,20 @@ class ThirdsendController extends HomeBaseController |
|
|
];
|
|
|
// 根据不同订单类型执行退款操作
|
|
|
$orderInfo = $order_model->where($where)->find();
|
|
|
$orderInfo['user_type'] = $needInfo['user_type'];
|
|
|
$transaction_id = $orderInfo['transaction_id'];
|
|
|
$order_sn = $orderInfo['order_sn'];
|
|
|
$money = $orderInfo['money'];
|
|
|
// $money = $orderInfo['money'];
|
|
|
$money = 0.01;
|
|
|
$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);
|
|
|
$refund_result = $this->wxpay_refund($orderInfo, $transaction_id,$out_refund_no,$money*100,$money*100,$reason,$reason_id);
|
|
|
}
|
|
|
// 支付宝
|
|
|
if($orderInfo['pay_type'] == 3 || $orderInfo['pay_type'] == 4) {
|
|
|
$refund_result = $this->alipay_refund($transaction_id,$order_sn,$money,$reason);
|
|
|
$refund_result = $this->alipay_refund($orderInfo, $transaction_id,$order_sn,$money,$reason,$reason_id);
|
|
|
}
|
|
|
return $refund_result;
|
|
|
}
|
...
|
...
|
@@ -1001,7 +889,7 @@ class ThirdsendController extends HomeBaseController |
|
|
* @param agencyInfo 中介报价信息
|
|
|
* @param reason 退款原因
|
|
|
*/
|
|
|
private function agency_order_refund($agencyInfo,$reason) {
|
|
|
public function agency_order_refund($agencyInfo,$reason,$reason_id) {
|
|
|
$order_model = new OrderModel();
|
|
|
$where = [
|
|
|
'user_id' => $agencyInfo['agency_id'],
|
...
|
...
|
@@ -1012,18 +900,20 @@ class ThirdsendController extends HomeBaseController |
|
|
];
|
|
|
// 根据不同订单类型执行退款操作
|
|
|
$orderInfo = $order_model->where($where)->find();
|
|
|
$orderInfo['user_type'] = $agencyInfo['user_type'];
|
|
|
$transaction_id = $orderInfo['transaction_id'];
|
|
|
$order_sn = $orderInfo['order_sn'];
|
|
|
$money = $orderInfo['money'];
|
|
|
// $money = $orderInfo['money'];
|
|
|
$money = 0.01;
|
|
|
$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);
|
|
|
$refund_result = $this->wxpay_refund($orderInfo, $transaction_id,$out_refund_no,$money*100,$money*100,$reason,$reason_id);
|
|
|
}
|
|
|
// 支付宝
|
|
|
if($orderInfo['pay_type'] == 3 || $orderInfo['pay_type'] == 4) {
|
|
|
$refund_result = $this->alipay_refund($transaction_id,$order_sn,$money,$reason);
|
|
|
$refund_result = $this->alipay_refund($orderInfo, $transaction_id,$order_sn,$money,$reason,$reason_id);
|
|
|
}
|
|
|
return $refund_result;
|
|
|
}
|
...
|
...
|
@@ -1036,7 +926,64 @@ class ThirdsendController extends HomeBaseController |
|
|
* @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) {
|
|
|
private function alipay_refund($orderInfo, $trade_no = null, $out_trade_no = null, $refund_amount, $refund_reason,$reason_id, $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
|
|
|
];
|
|
|
$result = $refund->refund($data);
|
|
|
$refund_model = new RefundModel();
|
|
|
if($result->code == '10000' && $result->msg == 'Success') {
|
|
|
$insert = [
|
|
|
'order_id' => $orderInfo['id'],
|
|
|
'order_sn' => $result->out_trade_no,
|
|
|
'user_id' => $orderInfo['user_id'],
|
|
|
'user_type' => $orderInfo['user_type'],
|
|
|
'refund_id' => $result->trade_no,
|
|
|
'pay_type' => 2,
|
|
|
'status' => 2,
|
|
|
'reason' => $reason_id,
|
|
|
'create_time' => time(),
|
|
|
'update_time' => time(),
|
|
|
'refund_time' => strtotime($result->gmt_refund_pay),
|
|
|
'more' => json_encode($result)
|
|
|
];
|
|
|
$refund_result = $refund_model->insertGetId($insert);
|
|
|
if(!$refund_result) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
} else {
|
|
|
$insert = [
|
|
|
'order_id' => $orderInfo['id'],
|
|
|
'user_id' => $orderInfo['user_id'],
|
|
|
'user_type' => $orderInfo['user_type'],
|
|
|
'pay_type' => 2,
|
|
|
'status' => 4,
|
|
|
'reason' => $reason_id,
|
|
|
'create_time' => time(),
|
|
|
'update_time' => time(),
|
|
|
'refund_time' => time(),
|
|
|
'more' => json_encode($result)
|
|
|
];
|
|
|
$refund_model->insertGetId($insert);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 支付宝退款查询接口(两个订单号不能同时为空)
|
|
|
* @param trade_no 支付宝交易号
|
|
|
* @param out_trade_no 商户支付订单号
|
|
|
* @param refund_amount 退款金额
|
|
|
* @param refund_reason 退款原因
|
|
|
* @param out_request_no 如需部分退款,传此参数
|
|
|
*/
|
|
|
private function alipay_refundquery($trade_no = null, $out_trade_no = null, $refund_amount, $refund_reason, $out_request_no = null) {
|
|
|
$refund = controller('Alipay','controller');
|
|
|
$data = [
|
|
|
'trade_no' => $trade_no,
|
...
|
...
|
@@ -1050,19 +997,153 @@ class ThirdsendController extends HomeBaseController |
|
|
|
|
|
/**
|
|
|
* 微信退款接口(两个订单号不能同时为空)
|
|
|
* @param orderInfo 支付订单信息
|
|
|
* @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) {
|
|
|
private function wxpay_refund($orderInfo, $transaction_id = null, $out_refund_no = null, $total_fee, $refund_fee, $refund_desc,$reason_id) {
|
|
|
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();
|
|
|
$result = $refund->pay();
|
|
|
if($result['return_code'] == 'SUCCESS' && $result['return_msg'] == 'OK') {
|
|
|
$refund_model = new RefundModel();
|
|
|
// $refund = $refund_model->where(['order_sn'=>$result['out_refund_no_0']])->find();
|
|
|
// if(!empty($refund)) {
|
|
|
// return $this->wxpay_refundquery($transaction_id, $out_refund_no, $out_refund_no, $refund['refund_id']);
|
|
|
// }
|
|
|
if($result['result_code'] == 'SUCCESS') {
|
|
|
$insert = [
|
|
|
'order_id' => $orderInfo['id'],
|
|
|
'order_sn' => $result['out_refund_no'],
|
|
|
'user_id' => $orderInfo['user_id'],
|
|
|
'user_type' => $orderInfo['user_type'],
|
|
|
'refund_id' => $result['refund_id'],
|
|
|
'pay_type' => 1,
|
|
|
'reason' => $reason_id,
|
|
|
'create_time' => time(),
|
|
|
'update_time' => time()
|
|
|
];
|
|
|
$refund_result = $refund_model->insertGetId($insert);
|
|
|
if(!$refund_result) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
// return $this->wxpay_refundquery($transaction_id, $out_refund_no, $result['out_refund_no'], $insert['refund_id']);
|
|
|
} else {
|
|
|
Db::name('Test')->insert(['data'=>$result['return_msg']]);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 微信退款查询接口(四个订单号不能同时为空)
|
|
|
* @param transaction_id 微信业务订单号
|
|
|
* @param out_trade_no 商户退款订单号
|
|
|
* @param out_refund_no 商户退款订单号
|
|
|
* @param refund_id 微信退款单号
|
|
|
*/
|
|
|
private function wxpay_refundquery($transaction_id = null, $out_trade_no = null, $out_refund_no = null, $refund_id = null) {
|
|
|
require_once VENDOR_PATH.'WxpayAPI/WxRefundQuery.php';
|
|
|
$refund = new \WxRefundQuery(Config::get('wx_appid'),Config::get('wx_mch_id'),Config::get('wx_key'),$transaction_id,
|
|
|
$out_trade_no,$out_refund_no,$refund_id);
|
|
|
$result = $refund->pay();
|
|
|
$refund_model = new RefundModel();
|
|
|
$refund = $refund_model->where(['refund_id'=>$result['refund_id_0']])->find();
|
|
|
if($refund['status'] == 2) {
|
|
|
return true;
|
|
|
}
|
|
|
if($result['return_code'] == 'SUCCESS' && $result['return_msg'] == 'OK') {
|
|
|
Db::startTrans();
|
|
|
$refund_success_time = 0;
|
|
|
if(!empty($result['refund_success_time_0'])) {
|
|
|
$refund_success_time = strtotime($result['refund_success_time_0']);
|
|
|
}
|
|
|
$refund_update = [
|
|
|
'status' => 2,
|
|
|
'update_time' => time(),
|
|
|
'refund_time' => $refund_success_time
|
|
|
];
|
|
|
$refund_result = $refund_model->where(['id'=>$refund['id']])->update($refund_update);
|
|
|
if(!$refund_result) {
|
|
|
Db::rollback();
|
|
|
return false;
|
|
|
}
|
|
|
$order_model = new OrderModel();
|
|
|
$order_update = [
|
|
|
'status' => 4,
|
|
|
'update_time' => time(),
|
|
|
'refund_time' => $refund_success_time
|
|
|
];
|
|
|
$order_result = $order_model->where(['id'=>$refund['order_id']])->update($order_update);
|
|
|
if(!$order_result) {
|
|
|
Db::rollback();
|
|
|
return false;
|
|
|
}
|
|
|
Db::commit();
|
|
|
} else {
|
|
|
$refund_update = [
|
|
|
'status' => 5,
|
|
|
'update_time' => time(),
|
|
|
'remark' => $result['return_msg']
|
|
|
];
|
|
|
$refund_result = $refund_model->where(['id'=>$refund['id']])->update($refund_update);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 发布需求,匹配中介(暂未调用)
|
|
|
public function sendNeed($need_id){
|
|
|
header("Content-Type: text/html;charset=utf-8");
|
|
|
$where_need['id'] = $need_id;
|
|
|
$where_need['status'] = 3;
|
|
|
$need_list = Db::name('UserNeed')->where($where_need)->field("id,city,quarters")->find();
|
|
|
$final_arr = array();
|
|
|
$code = 'SMS_137674888';
|
|
|
$where_member['type'] = 2;
|
|
|
$where_member['status'] = array('neq','8,9');
|
|
|
// 查询,匹配:省市区县精确匹配,小区名模糊匹配(只要有连续字匹配,就算匹配)
|
|
|
$member_find = Db::name('Member')->where($where_member)->field("id,name,tel,city,quarters")->select()->toArray();
|
|
|
foreach ($member_find as $mek=>$mev){
|
|
|
if($need_list['city'] == $mev['city']){
|
|
|
$quarters = explode('+',$mev['quarters']);
|
|
|
foreach ($quarters as $quak=>$quav){
|
|
|
if(strstr($need_list['quarters'],$quav) !== false){
|
|
|
$final_arr[] = $mev;
|
|
|
$final_tel[] = $mev['tel'];
|
|
|
$middle_arr['name'] = $mev['name'];
|
|
|
$middle_arr['name2'] = $need_list['quarters'];
|
|
|
$final_mes[] = $middle_arr;
|
|
|
$final_autograph[] = '比房价';
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
$json_tel = json_encode($final_tel,JSON_UNESCAPED_UNICODE);
|
|
|
$json_mes = json_encode($final_mes,JSON_UNESCAPED_UNICODE);
|
|
|
$json_autograph = json_encode($final_autograph,JSON_UNESCAPED_UNICODE);
|
|
|
$res_mes = $this->sendLogin($json_tel,$code,$json_mes,$json_autograph);
|
|
|
if($res_mes != 'OK'){
|
|
|
$this->apiResponse('0',$res_mes);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 短信验证码
|
|
|
public function sendLogin($tel,$code,$modelVal,$json_autograph){
|
|
|
require_once VENDOR_PATH."aliyun-dysms-php-sdk/api_demo/SmsDemo.php";
|
|
|
set_time_limit(0);
|
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
|
$response = SmsDemo::sendBatchSms($tel,$code,$modelVal,$json_autograph);
|
|
|
return $response;
|
|
|
}
|
|
|
} |
...
|
...
|
|