Refund.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\common\service;
  3. use addons\epay\library\Service;
  4. use app\common\model\MobileOrder;
  5. class Refund{
  6. protected $type;
  7. protected $mobileOrder;
  8. protected $types=[
  9. 1=>'wechat',
  10. 2=>'alipay',
  11. ];
  12. public static function setType(MobileOrder $mobileOrder){
  13. $a=new self;
  14. $a->mobileOrder=$mobileOrder;
  15. $a->type=$mobileOrder['pay_type'];
  16. }
  17. public function refund(){
  18. if(!isset($this->types[$this->type])){
  19. throw_user('此付款方式不支持退款');
  20. }
  21. $this->{$this->types[$this->type]}();
  22. }
  23. public function getAmount(){
  24. return $this->mobileOrder['amount_refund']*100;
  25. }
  26. public function wechat(){
  27. $res=Service::getApp('wechat',Service::refundUrl('wechat',$this->mobileOrder['pay_no']))->refund([
  28. 'transaction_id'=>$this->mobileOrder['pay_no'],
  29. 'out_refund_no'=>$this->mobileOrder['refund_no'],
  30. 'total_fee'=>$this->mobileOrder['amount'],
  31. 'refund_fee'=>$this->getAmount(),
  32. 'op_user_id'=>Service::getWechatOpUser(),
  33. ]);
  34. if($res['return_code']!=='SUCCESS'){
  35. throw_user($res['return_msg']);
  36. }
  37. if($res['result_code']!='SUCCESS'){
  38. throw_user($res['err_code_des']);
  39. }
  40. }
  41. }