BalanceRechargeSetService.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2022/2/18
  8. * Time: 11:36
  9. */
  10. namespace app\frontend\modules\finance\services;
  11. use app\common\facades\Setting;
  12. use app\common\services\PayFactory;
  13. class BalanceRechargeSetService
  14. {
  15. private $rechargeSet;
  16. public function __construct()
  17. {
  18. $this->rechargeSet = Setting::get('finance.balance_recharge_set') ? : [
  19. 'appoint_pay' => 0 //默认关闭
  20. ];
  21. }
  22. public function getRechargeSet()
  23. {
  24. if (!$this->rechargeSet) {
  25. $this->rechargeSet = Setting::get('finance.balance_recharge_set');
  26. }
  27. return $this->rechargeSet;
  28. }
  29. /**
  30. * 指定支付开关
  31. * @return bool
  32. */
  33. public function getAppointPay()
  34. {
  35. return $this->getRechargeSet()['appoint_pay'] ? true : false;
  36. }
  37. /**
  38. * 获取可以使用的支付code
  39. * @return array
  40. */
  41. public function getCanUsePayment()
  42. {
  43. $code = [];
  44. if ($this->getRechargeSet()['wechat']) {
  45. $code = array_merge($code,['wechatPay','wechatApp','wechatCpsAppPay','WechatFace','wechatH5','WechatJsapi','wechatMicroPay','wechatMinPay','wechatNative','WechatScan']);
  46. }
  47. if ($this->getRechargeSet()['alipay']) {
  48. $code = array_merge($code,['alipay','alipayApp','AlipayFace','AlipayJsapi','AlipayScan']);
  49. }
  50. if ($this->getRechargeSet()['pay_wechat_hj']) {
  51. $code = array_merge($code,['convergePayWechat']);
  52. }
  53. if ($this->getRechargeSet()['pay_alipay_hj']) {
  54. $code = array_merge($code,['convergePayAlipay']);
  55. }
  56. if ($this->getRechargeSet()['converge_quick_pay']) {
  57. $code = array_merge($code,['convergeQuickPay']);
  58. }
  59. return $code;
  60. }
  61. /**
  62. * 判断是否符合充值
  63. * @param $pay_type //支付方式
  64. * @param $recharge_money //充值金额
  65. * @return bool|string
  66. */
  67. public function verifyRecharge($pay_type,$recharge_money)
  68. {
  69. if (!$this->getAppointPay()) {
  70. return true;
  71. }
  72. $errStr = '不支持该支付方式进行充值';
  73. switch ($pay_type) {
  74. case PayFactory::PAY_WEACHAT:
  75. case PayFactory::PAY_Huanxun_Wx:
  76. case PayFactory::PAY_APP_WEACHAT:
  77. case PayFactory::PAY_CLOUD_WEACHAT:
  78. case PayFactory::PAY_YUN_WEACHAT:
  79. case PayFactory::PAY_WECHAT_JUEQI:
  80. case PayFactory::PAY_WECHAT_SCAN_HJ:
  81. case PayFactory::PAY_WECHAT_FACE_HJ:
  82. case PayFactory::WECHAT_SCAN_PAY:
  83. case PayFactory::WECHAT_JSAPI_PAY:
  84. case PayFactory::WECHAT_H5:
  85. case PayFactory::WECHAT_NATIVE:
  86. case PayFactory::WECHAT_CPS_APP_PAY:
  87. case PayFactory::WECHAT_MICRO_PAY:
  88. case PayFactory::WECHAT_MIN_PAY:
  89. if (!$this->getRechargeSet()['wechat']) {
  90. return $errStr;
  91. }
  92. $max = $this->getRechargeSet()['wechat_limit'];
  93. $pay_name = '微信';
  94. break;
  95. case PayFactory::PAY_APP_ALIPAY:
  96. case PayFactory::PAY_ALIPAY:
  97. case PayFactory::PAY_CLOUD_ALIPAY:
  98. case PayFactory::PAY_YUN_ALIPAY:
  99. case PayFactory::ALIPAY_FACE_PAY:
  100. case PayFactory::ALIPAY_SCAN_PAY:
  101. case PayFactory::ALIPAY_JSAPI_PAY:
  102. if (!$this->getRechargeSet()['alipay']) {
  103. return $errStr;
  104. }
  105. $max = $this->getRechargeSet()['alipay_limit'];
  106. $pay_name = '支付宝';
  107. break;
  108. case PayFactory::PAY_WECHAT_HJ:
  109. if (!$this->getRechargeSet()['pay_wechat_hj']) {
  110. return $errStr;
  111. }
  112. $max = $this->getRechargeSet()['apay_wechat_hj_limit'];
  113. $pay_name = '汇聚微信';
  114. break;
  115. case PayFactory::PAY_ALIPAY_HJ:
  116. if (!$this->getRechargeSet()['pay_alipay_hj']) {
  117. return $errStr;
  118. }
  119. $max = $this->getRechargeSet()['pay_alipay_hj_limit'];
  120. $pay_name = '汇聚支付宝';
  121. break;
  122. case PayFactory::CONVERGE_QUICK_PAY:
  123. if (!$this->getRechargeSet()['converge_quick_pay']) {
  124. return $errStr;
  125. }
  126. $max = $this->getRechargeSet()['converge_quick_pay_limit'];
  127. $pay_name = '汇聚快捷支付';
  128. break;
  129. case PayFactory::LSP_PAY:
  130. // 基础设置没有限制
  131. break;
  132. default:
  133. return $errStr;
  134. }
  135. if (!empty($max) && $recharge_money > $max) {
  136. return '已超过' . $pay_name . '单笔最大充值金额'.$max.'元';
  137. }
  138. return true;
  139. }
  140. }