WithdrawWay.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wniu
  5. * Date: 2022/4/22
  6. * Time: 4:48 下午
  7. */
  8. namespace addons\JoinPay\common\global_func\withdraw_way;
  9. use common\components\payment\AlternativePay;
  10. use common\enums\PayTypeEnum;
  11. use common\models\common\PaymentTransfer;
  12. use services\common\PayService;
  13. class WithdrawWay
  14. {
  15. public static function getExtensionWithdrawWay()
  16. {
  17. $data = [
  18. 'joinpay' => '提现到银行卡-汇聚',
  19. ];
  20. return $data;
  21. }
  22. /**
  23. * 汇聚代付提现
  24. * User: wniu
  25. * Date: 2022/4/22
  26. * Time: 5:54 下午
  27. * * @param $cash
  28. * @throws \Exception
  29. */
  30. public static function extensionWithdrawPay($data): bool
  31. {
  32. $cash = $data['cash'];
  33. try {
  34. $paymentTransfer = new PaymentTransfer();
  35. $paymentTransfer->orderNo = PaymentTransfer::generate_order_no("TR");
  36. $paymentTransfer->title = $data['title']??'收益提现';
  37. $paymentTransfer->amount = $cash->actual_num;
  38. $paymentTransfer->transferType = PayTypeEnum::JOINPAY;
  39. $paymentTransfer->cashInfo = $cash;
  40. $paymentTransfer->source = $data['source']??1;
  41. $res = self::transfer($paymentTransfer);
  42. } catch (\Exception $e) {
  43. throw new \Exception($e->getMessage());
  44. }
  45. return $res;
  46. }
  47. public static function transfer($paymentTransfer): bool
  48. {
  49. $where = [
  50. 'order_no' => $paymentTransfer['orderNo'],
  51. 'user_id' => $paymentTransfer['user_id'],
  52. 'mall_id' => $paymentTransfer['mall_id']
  53. ];
  54. $model = PaymentTransfer::getOne([$where]);
  55. if (!$model) {
  56. $model = new PaymentTransfer();
  57. $model->transfer_order_no = $paymentTransfer->orderNo;
  58. $model->mall_id = $paymentTransfer->cashInfo->mall_id;
  59. $model->user_id = $paymentTransfer->cashInfo->user_id;
  60. $model->title = $paymentTransfer->title;
  61. $model->amount = $paymentTransfer->amount;
  62. $model->pay_type = $paymentTransfer->transferType;
  63. $model->is_pay = 0;
  64. $model->order_no = 'HM' . substr(md5($paymentTransfer->orderNo), 2);
  65. $model->created_at = time();
  66. $model->cashInfo = $paymentTransfer->cashInfo;
  67. $model->source = $paymentTransfer->source;
  68. }
  69. if ($model->is_pay == 1) {
  70. throw new \Exception('该订单号已经打款,请勿重复操作');
  71. }
  72. $t = \Yii::$app->db->beginTransaction();
  73. try {
  74. $obj = new AlternativePay([],$model->mall_id);
  75. $result =$obj->transfer($model, $paymentTransfer->user);
  76. if ($result) {
  77. $t->commit();
  78. return true;
  79. } else {
  80. throw new \Exception();
  81. }
  82. } catch (\Exception $e) {
  83. $t->rollBack();
  84. \Yii::error($e->getMessage());
  85. return false;
  86. }
  87. }
  88. }