UserRechargeController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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\user\UserRechargeServices;
  14. /**
  15. * 充值类
  16. * Class UserRechargeController
  17. * @package app\api\controller\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'])) 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. list($price, $recharId, $type) = $request->postMore([['price', 0], ['rechar_id', 0], ['type', 0]], true);
  61. if (!$price || $price <= 0) return app('json')->fail('充值金额不能为0元!');
  62. $storeMinRecharge = sys_config('store_user_min_recharge');
  63. if ($price < $storeMinRecharge) return app('json')->fail('充值金额不能低于' . $storeMinRecharge);
  64. $from = 'routine';
  65. $uid = (int)$request->uid();
  66. $re = $this->services->recharge($uid, $price, $recharId, $type, $from);
  67. if ($re) {
  68. $msg = $re['msg'];
  69. unset($re['msg']);
  70. return app('json')->successful($msg, $re['data']);
  71. }
  72. return app('json')->fail('充值失败');
  73. }
  74. /**
  75. * 公众号充值
  76. * @param Request $request
  77. * @return mixed
  78. */
  79. public function wechat(Request $request)
  80. {
  81. list($price, $recharId, $from, $type) = $request->postMore([['price', 0], ['rechar_id', 0], ['from', 'weixin'], ['type', 0]], true);
  82. if (!$price || $price <= 0) return app('json')->fail('充值金额不能为0元!');
  83. $storeMinRecharge = sys_config('store_user_min_recharge');
  84. if ($price < $storeMinRecharge) return app('json')->fail('充值金额不能低于' . $storeMinRecharge);
  85. $uid = (int)$request->uid();
  86. $re = $this->services->recharge($uid, $price, $recharId, $type, $from);
  87. if ($re) {
  88. $msg = $re['msg'];
  89. unset($re['msg']);
  90. return app('json')->successful($msg, $re);
  91. }
  92. return app('json')->fail('充值失败');
  93. }
  94. /**
  95. * 充值额度选择
  96. * @return mixed
  97. */
  98. public function index()
  99. {
  100. $rechargeQuota = sys_data('user_recharge_quota') ?? [];
  101. $data['recharge_quota'] = $rechargeQuota;
  102. $recharge_attention = sys_config('recharge_attention');
  103. $recharge_attention = explode("\n", $recharge_attention);
  104. $data['recharge_attention'] = $recharge_attention;
  105. return app('json')->successful($data);
  106. }
  107. }