UserRechargeController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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\api\controller\v1\user;
  12. use app\Request;
  13. use app\services\pay\PayServices;
  14. use app\services\user\UserRechargeServices;
  15. /**
  16. * 充值类
  17. * Class UserRechargeController
  18. * @package app\api\controller\user
  19. */
  20. class UserRechargeController
  21. {
  22. protected $services = NUll;
  23. /**
  24. * UserRechargeController constructor.
  25. * @param UserRechargeServices $services
  26. */
  27. public function __construct(UserRechargeServices $services)
  28. {
  29. $this->services = $services;
  30. }
  31. /**
  32. * 用户充值
  33. * @param Request $request
  34. * @return mixed
  35. */
  36. public function recharge(Request $request)
  37. {
  38. [$price, $recharId, $type, $from] = $request->postMore([
  39. ['price', 0],
  40. ['rechar_id', 0],
  41. ['type', 0],
  42. ['from', 'weixin']
  43. ], true);
  44. if (!$price || $price <= 0) return app('json')->fail(410122);
  45. if (!in_array($type, [0, 1])) return app('json')->fail(410123);
  46. if (!in_array($from, [PayServices::WEIXIN_PAY, 'weixinh5', 'routine', PayServices::ALIAPY_PAY])) return app('json')->fail(410123);
  47. $storeMinRecharge = sys_config('store_user_min_recharge');
  48. if ($price < $storeMinRecharge) return app('json')->fail(410124, null, ['money' => $storeMinRecharge]);
  49. $uid = (int)$request->uid();
  50. $re = $this->services->recharge($uid, $price, $recharId, $type, $from);
  51. if ($re) {
  52. unset($re['msg']);
  53. return app('json')->success(410125, $re);
  54. }
  55. return app('json')->fail(410126);
  56. }
  57. /**
  58. * 小程序充值
  59. * @param Request $request
  60. * @return mixed
  61. */
  62. public function routine(Request $request)
  63. {
  64. list($price, $recharId, $type) = $request->postMore([['price', 0], ['rechar_id', 0], ['type', 0]], true);
  65. if (!$price || $price <= 0) return app('json')->fail(410122);
  66. $storeMinRecharge = sys_config('store_user_min_recharge');
  67. if ($price < $storeMinRecharge) return app('json')->fail(410124, null, ['money' => $storeMinRecharge]);
  68. $from = 'routine';
  69. $uid = (int)$request->uid();
  70. $re = $this->services->recharge($uid, $price, $recharId, $type, $from);
  71. if ($re) {
  72. unset($re['msg']);
  73. return app('json')->success(410125, $re['data']);
  74. }
  75. return app('json')->fail(410126);
  76. }
  77. /**
  78. * 公众号充值
  79. * @param Request $request
  80. * @return mixed
  81. */
  82. public function wechat(Request $request)
  83. {
  84. list($price, $recharId, $from, $type) = $request->postMore([['price', 0], ['rechar_id', 0], ['from', 'weixin'], ['type', 0]], true);
  85. if (!$price || $price <= 0) return app('json')->fail(410122);
  86. $storeMinRecharge = sys_config('store_user_min_recharge');
  87. if ($price < $storeMinRecharge) return app('json')->fail(410124, null, ['money' => $storeMinRecharge]);
  88. $uid = (int)$request->uid();
  89. $re = $this->services->recharge($uid, $price, $recharId, $type, $from);
  90. if ($re) {
  91. unset($re['msg']);
  92. return app('json')->success(410125, $re);
  93. }
  94. return app('json')->fail(410126);
  95. }
  96. /**
  97. * 充值额度选择
  98. * @return mixed
  99. */
  100. public function index()
  101. {
  102. $rechargeQuota = sys_data('user_recharge_quota') ?? [];
  103. $data['recharge_quota'] = $rechargeQuota;
  104. $recharge_attention = sys_config('recharge_attention');
  105. $recharge_attention = explode("\n", $recharge_attention);
  106. $data['recharge_attention'] = $recharge_attention;
  107. return app('json')->success($data);
  108. }
  109. }