ThirdPartyRefundService.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace services\common;
  3. use common\components\payment\HuijuBill;
  4. use common\components\Service;
  5. use common\enums\AddonsEnum;
  6. use common\enums\PayTypeEnum;
  7. use Exception;
  8. use Yii;
  9. /**
  10. *
  11. * 订单第三方在线支付退款服务
  12. */
  13. class ThirdPartyRefundService extends Service
  14. {
  15. /**
  16. * 批量加入队列处理
  17. *
  18. * @param array $data
  19. * @return void
  20. */
  21. public static function batchHandleByQueue($data)
  22. {
  23. if (in_array($data['payment_type'], PayTypeEnum::thirdParty())) {
  24. throw new Exception('支付类型不符合');
  25. }
  26. // 检查是否存在处理方法
  27. $method = PayTypeEnum::action($data['payment_type']);
  28. if (!method_exists(self::class, $method)) {
  29. throw new Exception(PayTypeEnum::getValue($data['payment_type']) . '未定义退款处理方法');
  30. }
  31. return call_user_func([self::class, $method], $data);
  32. }
  33. /**
  34. * 汇聚分账退款
  35. *
  36. * @param array $data
  37. * @return void
  38. */
  39. public static function huiju_bill($data)
  40. {
  41. $config = Yii::$app->services->setting->addons->get($data['mall_id'], AddonsEnum::ADDONS_NAME_HUIJU_BILL, 'basic');
  42. $pay = Yii::$app->payment->huijuBill($config);
  43. // 发起退款
  44. return $pay->refund($data);
  45. }
  46. }