1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace app\common\service;
- use addons\epay\library\Service;
- use app\common\model\MobileOrder;
- class Refund{
- protected $type;
- protected $mobileOrder;
- protected $types=[
- 1=>'wechat',
- 2=>'alipay',
- ];
- public static function setType(MobileOrder $mobileOrder){
- $a=new self;
- $a->mobileOrder=$mobileOrder;
- $a->type=$mobileOrder['pay_type'];
- }
- public function refund(){
- if(!isset($this->types[$this->type])){
- throw_user('此付款方式不支持退款');
- }
- $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']);
- }
- }
- }
|