WithdrawService.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\backend\modules\finance\services;
  3. use app\backend\modules\finance\services\BalanceService;
  4. use app\common\exceptions\AppException;
  5. use app\common\exceptions\ShopException;
  6. use app\common\models\Member;
  7. use app\common\services\credit\ConstService;
  8. use app\common\services\finance\BalanceChange;
  9. use app\common\services\finance\Withdraw;
  10. use app\common\services\PayFactory;
  11. /**
  12. * Created by PhpStorm.
  13. * Author: 芸众商城 www.yunzshop.com
  14. * Date: 2017/3/31
  15. * Time: 下午3:13
  16. */
  17. class WithdrawService extends Withdraw
  18. {
  19. public static function createStatusService($withdraw)
  20. {
  21. switch ($withdraw->status) {
  22. case -1:
  23. return '无效';
  24. break;
  25. case 0:
  26. return '未审核';
  27. break;
  28. case 1:
  29. return '未打款';
  30. break;
  31. case 2:
  32. return '已打款';
  33. break;
  34. case 3:
  35. return '驳回';
  36. break;
  37. }
  38. }
  39. public static function balanceWithdrawPay($withdraw, $remark)
  40. {
  41. $data = array(
  42. /* 'member_id' => $withdraw->member_id,
  43. 'money' => $withdraw->actual_amounts,
  44. 'serial_number' => '',
  45. 'operator' => '-2',
  46. 'operator_id' => $withdraw->id,
  47. 'remark' => $remark,
  48. 'service_type' => \app\common\models\finance\Balance::BALANCE_INCOME,*/
  49. 'member_id' => $withdraw->member_id,
  50. 'remark' => $remark,
  51. 'source' => ConstService::SOURCE_INCOME,
  52. 'relation' => '',
  53. 'operator' => ConstService::OPERATOR_MEMBER,
  54. 'operator_id' => $withdraw->id,
  55. 'change_value' => $withdraw->actual_amounts
  56. );
  57. return (new BalanceChange())->income($data);
  58. }
  59. public static function wechatWithdrawPay($withdraw, $remark)
  60. {
  61. $memberId = $withdraw->member_id;
  62. $sn = $withdraw->withdraw_sn;
  63. $amount = $withdraw->actual_amounts;
  64. $memberModel = Member::uniacid()->where('uid', $withdraw->member_id)->with(['hasOneFans', 'hasOneMiniApp', 'hasOneWechat'])->first();
  65. //优先使用微信会员打款
  66. if ($memberModel->hasOneFans->openid) {
  67. $result = PayFactory::create(PayFactory::PAY_WEACHAT)->doWithdraw($memberId, $sn, $amount, $remark);
  68. //微信会员openid不存在时,假设使用小程序会员openid
  69. } elseif (app('plugins')->isEnabled('min-app') && $memberModel->hasOneMiniApp->openid) {
  70. $result = PayFactory::create(PayFactory::PAY_WE_CHAT_APPLET)->doWithdraw($memberId, $sn, $amount, $remark);
  71. } elseif (app('plugins')->isEnabled('app-set') && $memberModel->hasOneWechat->openid) {
  72. $result = PayFactory::create(PayFactory::PAY_APP_WEACHAT)->doWithdraw($memberId, $sn, $amount, $remark);
  73. } else {
  74. throw new ShopException("余额提现ID:{$withdraw->id},提现失败:提现会员openid错误");
  75. }
  76. return $result;
  77. }
  78. public static function alipayWithdrawPay($withdraw, $remark)
  79. {
  80. if (is_array($withdraw)) {
  81. $result = PayFactory::create(2)->doBatchWithdraw($withdraw);
  82. } else {
  83. $result = PayFactory::create(2)->doWithdraw($withdraw->member_id, $withdraw->withdraw_sn, $withdraw->actual_amounts, $remark);
  84. }
  85. if (is_array($result)) {
  86. return $result;
  87. }
  88. redirect($result)->send();
  89. }
  90. public static function eupWithdrawPay($withdraw)
  91. {
  92. return PayFactory::create(PayFactory::PAY_EUP)->doWithdraw($withdraw->member_id, $withdraw->withdraw_sn, $withdraw->actual_amounts);
  93. }
  94. //blank 易宝余额提现
  95. public static function yopWithdrawPay($withdraw)
  96. {
  97. return PayFactory::create(PayFactory::YOP)->doWithdraw($withdraw->member_id, $withdraw->withdraw_sn, $withdraw->actual_amounts);
  98. }
  99. public static function huanxunPayment($withdraw)
  100. {
  101. return PayFactory::create(PayFactory::PAY_Huanxun_Quick)->doWithdraw($withdraw->member_id, $withdraw->withdraw_sn, $withdraw->actual_amounts);
  102. }
  103. /**
  104. * 汇聚余额提现
  105. *
  106. * @param $withdraw
  107. * @param $remark
  108. * @return array|mixed
  109. * @throws AppException
  110. */
  111. public static function convergePayMent($withdraw, $remark)
  112. {
  113. return PayFactory::create(PayFactory::PAY_WECHAT_HJ)->doWithdraw($withdraw->member_id, $withdraw->withdraw_sn, $withdraw->actual_amounts, $remark);
  114. }
  115. public static function highLightWithdrawPay($withdraw)
  116. {
  117. return PayFactory::create(PayFactory::HIGH_LIGHT)->doWithdraw($withdraw->member_id, $withdraw->withdraw_sn, $withdraw->actual_amounts,'',$withdraw->pay_way);
  118. }
  119. public static function workerWithdrawPay($withdraw)
  120. {
  121. return PayFactory::create(PayFactory::WORK_WITHDRAW_PAY)->doWithdraw($withdraw->member_id, $withdraw->withdraw_sn, $withdraw->actual_amounts,'',$withdraw->pay_way);
  122. }
  123. public static function eplusWithdrawPay($withdraw)
  124. {
  125. return PayFactory::create(PayFactory::EPLUS_MINI_PAY)->doWithdraw($withdraw->member_id, $withdraw->withdraw_sn, $withdraw->actual_amounts, '', $withdraw->pay_way);
  126. }
  127. public static function silverPointWithdrawPayment($withdraw)
  128. {
  129. return PayFactory::create(PayFactory::SILVER_POINT_PAYMENT)->doWithdraw($withdraw->member_id, $withdraw->withdraw_sn, $withdraw->actual_amounts, '', $withdraw->pay_way);
  130. }
  131. }