Refund.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. return $a;
  17. }
  18. public function refund(){
  19. if(!isset($this->types[$this->type])){
  20. throw_user('此付款方式不支持退款');
  21. }
  22. $this->{$this->types[$this->type]}();
  23. }
  24. public function getAmount(){
  25. return $this->mobileOrder['amount_refund']*100;
  26. }
  27. public function wechat(){
  28. $res=Service::getApp('wechat',Service::refundUrl('wechat',$this->mobileOrder['pay_no']))->refund([
  29. 'transaction_id'=>$this->mobileOrder['pay_no'],
  30. 'out_refund_no'=>$this->mobileOrder['refund_no'],
  31. 'total_fee'=>$this->mobileOrder['amount'],
  32. 'refund_fee'=>$this->getAmount(),
  33. 'op_user_id'=>Service::getWechatOpUser(),
  34. ]);
  35. if($res['return_code']!=='SUCCESS'){
  36. throw_user($res['return_msg']);
  37. }
  38. if($res['result_code']!='SUCCESS'){
  39. throw_user($res['err_code_des']);
  40. }
  41. }
  42. }