UserRechargeController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v1\user;
  12. use app\Request;
  13. use app\services\user\UserRechargeServices;
  14. /**
  15. * 充值类
  16. * Class UserRechargeController
  17. * @package app\controller\api\user
  18. */
  19. class UserRechargeController
  20. {
  21. protected $services = NUll;
  22. /**
  23. * UserRechargeController constructor.
  24. * @param UserRechargeServices $services
  25. */
  26. public function __construct(UserRechargeServices $services)
  27. {
  28. $this->services = $services;
  29. }
  30. public function recharge(Request $request)
  31. {
  32. [$price, $recharId, $type, $from] = $request->postMore([
  33. ['price', 0],
  34. ['rechar_id', 0],
  35. ['type', 0],
  36. ['from', 'weixin']
  37. ], true);
  38. if (!$price || $price <= 0) return app('json')->fail('充值金额不能为0元!');
  39. if (!in_array($type, [0, 1])) return app('json')->fail('充值方式不支持!');
  40. if (!in_array($from, ['weixin', 'weixinh5', 'routine', 'alipay'])) return app('json')->fail('充值方式不支持');
  41. $storeMinRecharge = sys_config('store_user_min_recharge');
  42. if ($price < $storeMinRecharge) return app('json')->fail('充值金额不能低于' . $storeMinRecharge);
  43. $uid = (int)$request->uid();
  44. $re = $this->services->recharge($uid, $price, $recharId, $type, $from);
  45. if ($re) {
  46. $msg = $re['msg'];
  47. unset($re['msg']);
  48. return app('json')->successful($msg, $re);
  49. }
  50. return app('json')->fail('充值失败');
  51. }
  52. /**
  53. * 小程序充值
  54. *
  55. * @param Request $request
  56. * @return mixed
  57. */
  58. public function routine(Request $request)
  59. {
  60. [$price, $recharId, $type] = $request->postMore([
  61. ['price', 0],
  62. ['rechar_id', 0],
  63. ['type', 0]
  64. ], true);
  65. if (!$price || $price <= 0) return app('json')->fail('充值金额不能为0元!');
  66. $storeMinRecharge = sys_config('store_user_min_recharge');
  67. if ($price < $storeMinRecharge) return app('json')->fail('充值金额不能低于' . $storeMinRecharge);
  68. $from = 'routine';
  69. $uid = (int)$request->uid();
  70. $re = $this->services->recharge($uid, $price, $recharId, $type, $from);
  71. if ($re) {
  72. $msg = $re['msg'];
  73. unset($re['msg']);
  74. return app('json')->successful($msg, $re['data']);
  75. }
  76. return app('json')->fail('充值失败');
  77. }
  78. /**
  79. * 公众号充值
  80. * @param Request $request
  81. * @return mixed
  82. */
  83. public function wechat(Request $request)
  84. {
  85. [$price, $recharId, $from, $type] = $request->postMore([
  86. ['price', 0],
  87. ['rechar_id', 0],
  88. ['from', 'weixin'],
  89. ['type', 0]
  90. ], true);
  91. if (!$price || $price <= 0) return app('json')->fail('充值金额不能为0元!');
  92. $storeMinRecharge = sys_config('store_user_min_recharge');
  93. if ($price < $storeMinRecharge) return app('json')->fail('充值金额不能低于' . $storeMinRecharge);
  94. $uid = (int)$request->uid();
  95. $re = $this->services->recharge($uid, $price, $recharId, $type, $from);
  96. if ($re) {
  97. $msg = $re['msg'];
  98. unset($re['msg']);
  99. return app('json')->successful($msg, $re);
  100. }
  101. return app('json')->fail('充值失败');
  102. }
  103. /**
  104. * 充值额度选择
  105. * @return mixed
  106. */
  107. public function index()
  108. {
  109. $rechargeQuota = sys_data('user_recharge_quota') ?? [];
  110. $data['recharge_quota'] = $rechargeQuota;
  111. $recharge_attention = sys_config('recharge_attention');
  112. $recharge_attention = explode("\n", $recharge_attention);
  113. $data['recharge_attention'] = $recharge_attention;
  114. return app('json')->successful($data);
  115. }
  116. }