UserRechargeController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\v1\user;
  12. use app\dao\system\config\SystemConfigDao;
  13. use app\Request;
  14. use app\services\pay\PayServices;
  15. use app\services\system\config\SystemConfigServices;
  16. use app\services\user\UserRechargeServices;
  17. /**
  18. * 充值类
  19. * Class UserRechargeController
  20. * @package app\api\controller\user
  21. */
  22. class UserRechargeController
  23. {
  24. protected $services = NUll;
  25. /**
  26. * UserRechargeController constructor.
  27. * @param UserRechargeServices $services
  28. */
  29. public function __construct(UserRechargeServices $services)
  30. {
  31. $this->services = $services;
  32. }
  33. /**
  34. * 用户充值
  35. * @param Request $request
  36. * @return mixed
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function recharge(Request $request)
  42. {
  43. [$price, $recharId, $type, $from] = $request->postMore([
  44. ['price', 0],
  45. ['rechar_id', 0],
  46. ['type', 0],
  47. ['from', 'weixin']
  48. ], true);
  49. if (!$price || $price <= 0) return app('json')->fail(410122);
  50. if (!in_array($type, [0, 1])) return app('json')->fail(410123);
  51. if (!in_array($from, [PayServices::WEIXIN_PAY, 'weixinh5', 'routine', PayServices::ALIAPY_PAY])) return app('json')->fail(410123);
  52. $storeMinRecharge = sys_config('store_user_min_recharge');
  53. if (!$recharId && $price < $storeMinRecharge) return app('json')->fail(410124, null, ['money' => $storeMinRecharge]);
  54. $uid = (int)$request->uid();
  55. $re = $this->services->recharge($uid, $price, $recharId, $type, $from, true);
  56. if ($re) {
  57. $payType = $re['pay_type'] ?? '';
  58. unset($re['pay_type']);
  59. return app('json')->status($payType, 410125, $re);
  60. }
  61. return app('json')->fail(410126);
  62. }
  63. /**
  64. * TODO 小程序充值 弃用
  65. * @param Request $request
  66. * @return mixed
  67. */
  68. public function routine(Request $request)
  69. {
  70. list($price, $recharId, $type) = $request->postMore([['price', 0], ['rechar_id', 0], ['type', 0]], true);
  71. if (!$price || $price <= 0) return app('json')->fail(410122);
  72. $storeMinRecharge = sys_config('store_user_min_recharge');
  73. if ($price < $storeMinRecharge) return app('json')->fail(410124, null, ['money' => $storeMinRecharge]);
  74. $from = 'routine';
  75. $uid = (int)$request->uid();
  76. $re = $this->services->recharge($uid, $price, $recharId, $type, $from);
  77. if ($re) {
  78. unset($re['msg']);
  79. return app('json')->success(410125, $re['data']);
  80. }
  81. return app('json')->fail(410126);
  82. }
  83. /**
  84. * TODO 公众号充值 弃用
  85. * @param Request $request
  86. * @return mixed
  87. */
  88. public function wechat(Request $request)
  89. {
  90. list($price, $recharId, $from, $type) = $request->postMore([['price', 0], ['rechar_id', 0], ['from', 'weixin'], ['type', 0]], true);
  91. if (!$price || $price <= 0) return app('json')->fail(410122);
  92. $storeMinRecharge = sys_config('store_user_min_recharge');
  93. if ($price < $storeMinRecharge) return app('json')->fail(410124, null, ['money' => $storeMinRecharge]);
  94. $uid = (int)$request->uid();
  95. $re = $this->services->recharge($uid, $price, $recharId, $type, $from);
  96. if ($re) {
  97. unset($re['msg']);
  98. return app('json')->success(410125, $re);
  99. }
  100. return app('json')->fail(410126);
  101. }
  102. /**
  103. * 充值额度选择
  104. * @return mixed
  105. */
  106. public function index()
  107. {
  108. $rechargeQuota = sys_data('user_recharge_quota') ?? [];
  109. $data['recharge_quota'] = $rechargeQuota;
  110. $recharge_attention = sys_config('recharge_attention');
  111. $recharge_attention = explode("\n", $recharge_attention);
  112. $data['recharge_attention'] = $recharge_attention;
  113. return app('json')->success($data);
  114. }
  115. /**
  116. * 获取手续费配置
  117. * @return mixed
  118. */
  119. public function getFeeConfig()
  120. {
  121. // 直接从数据库查询配置值,不使用缓存
  122. /** @var SystemConfigDao $dao */
  123. $dao = app()->make(SystemConfigDao::class);
  124. $configs = $dao->getConfigAll(['yue_transfer_fee', 'transfer_fee', 'withdrawal_fee']);
  125. $data = [
  126. 'yue_transfer_fee' => $configs['yue_transfer_fee'] ?? 10, // 佣金转余额手续费比例
  127. 'transfer_fee' => $configs['transfer_fee'] ?? 7, // 佣金互转手续费比例
  128. 'withdrawal_fee' => $configs['withdrawal_fee'] ?? 0 // 提现手续费比例
  129. ];
  130. return app('json')->success($data);
  131. }
  132. }