|
@@ -2,17 +2,20 @@
|
|
|
namespace app\common\service;
|
|
|
|
|
|
|
|
|
+use addons\epay\library\Service;
|
|
|
+use app\common\model\MobileOrder;
|
|
|
+
|
|
|
class Refund{
|
|
|
protected $type;
|
|
|
- protected $amount;
|
|
|
+ protected $mobileOrder;
|
|
|
protected $types=[
|
|
|
1=>'wechat',
|
|
|
2=>'alipay',
|
|
|
];
|
|
|
- public static function setType($type,$amount){
|
|
|
+ public static function setType(MobileOrder $mobileOrder){
|
|
|
$a=new self;
|
|
|
- $a->type=$type;
|
|
|
- $a->amount=$amount;
|
|
|
+ $a->mobileOrder=$mobileOrder;
|
|
|
+ $a->type=$mobileOrder['pay_type'];
|
|
|
}
|
|
|
public function refund(){
|
|
|
if(!isset($this->types[$this->type])){
|
|
@@ -20,7 +23,22 @@ class Refund{
|
|
|
}
|
|
|
$this->{$this->types[$this->type]}();
|
|
|
}
|
|
|
+ public function getAmount(){
|
|
|
+ return $this->mobileOrder['amount_refund']*100;
|
|
|
+ }
|
|
|
public function wechat(){
|
|
|
-
|
|
|
+ $res=Service::getApp('wechat',Service::refundUrl('wechat',$this->mobileOrder['pay_no']))->refund([
|
|
|
+ 'transaction_id'=>$this->mobileOrder['pay_no'],
|
|
|
+ 'out_refund_no'=>$this->mobileOrder['refund_no'],
|
|
|
+ 'total_fee'=>$this->mobileOrder['amount'],
|
|
|
+ 'refund_fee'=>$this->getAmount(),
|
|
|
+ 'op_user_id'=>Service::getWechatOpUser(),
|
|
|
+ ]);
|
|
|
+ if($res['return_code']!=='SUCCESS'){
|
|
|
+ throw_user($res['return_msg']);
|
|
|
+ }
|
|
|
+ if($res['result_code']!='SUCCESS'){
|
|
|
+ throw_user($res['err_code_des']);
|
|
|
+ }
|
|
|
}
|
|
|
}
|