Wallet.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\service\VipService;
  4. use app\api\service\WalletService;
  5. use app\api\validate\BaseApiValidate;
  6. use app\common\controller\Api;
  7. use think\Request;
  8. class Wallet extends Api
  9. {
  10. private $service;
  11. public function __construct(Request $request = null)
  12. {
  13. parent::__construct($request);
  14. $this->service = new WalletService();
  15. }
  16. public function fetchRechargeOption()
  17. {
  18. $this->success($this->service->fetchRechargeOption());
  19. }
  20. public function fetchVoucher()
  21. {
  22. $user = $this->auth->getUser();
  23. $params = (new BaseApiValidate([
  24. 'status' => 'require',
  25. 'page' => 'number',
  26. 'size' => 'number'
  27. ]))->checkBody();
  28. $r = $this->service->fetchVoucher($user->id, "*" === $params["status"] ? [\E_VOUCHER_STATUS::Normal, \E_VOUCHER_STATUS::Use, \E_VOUCHER_STATUS::Expire] : [$params["status"]], $params["page"], $params["size"]);
  29. $this->success($r);
  30. }
  31. public function rechargeBalance()
  32. {
  33. $user = $this->auth->getUser();
  34. $params = (new BaseApiValidate([
  35. "platform" => "require",
  36. 'payment_type' => 'require',
  37. 'amount' => 'require|between:1,100000'
  38. ], ["amount.between" => "充值面额必须在1~100000之间"])
  39. )->checkBody();
  40. if (!in_array($params["payment_type"], [\E_ORDER_PAY_TYPE::Wechat, \E_ORDER_PAY_TYPE::ALi]))
  41. $this->error("支付方式错误");
  42. if (!in_array($params["platform"], ["app", "web", "applet"]))
  43. $this->error("platform 错误");
  44. $r = $this->service->rechargeBalance($user->id, $params["payment_type"], $params["amount"], $params["platform"]);
  45. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  46. }
  47. public function renew()
  48. {
  49. $params = (new BaseApiValidate([
  50. "platform" => "require",
  51. 'payment_type' => 'require',
  52. 'membership_config_id' => 'require|number'
  53. ]))->checkBody();
  54. $user = $this->auth->getUser();
  55. $r = (new VipService())->renew($user->id, $params['membership_config_id'], $params["payment_type"], $params["platform"]);
  56. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  57. }
  58. public function fetchBill()
  59. {
  60. $user = $this->auth->getUser();
  61. $params = (new BaseApiValidate([
  62. 'currency_type' => 'require',
  63. 'change_types' => 'require',
  64. 'page' => 'require|number',
  65. 'size' => 'require|number',
  66. ]))->checkBody();
  67. if (!in_array($params["currency_type"], [\E_USER_BILL_CURRENCY_TYPE::Money, \E_USER_BILL_CURRENCY_TYPE::Score]))
  68. $this->error("currency_type error");
  69. $r = $this->service->fetchBill(
  70. $user->id,
  71. $params["currency_type"],
  72. explode(",", (string)$params["change_types"]),
  73. $params["page"],
  74. $params["size"]
  75. );
  76. $this->success($r);
  77. }
  78. public function delBills()
  79. {
  80. $user = $this->auth->getUser();
  81. $params = (new BaseApiValidate([
  82. 'bill_ids' => 'require',
  83. ]))->checkBody();
  84. $bill_ids = explode(",", $params["bill_ids"]);
  85. $r = $this->service->delBills($user->id, $bill_ids);
  86. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  87. }
  88. public function exchangeVoucher()
  89. {
  90. $user = $this->auth->getUser();
  91. $params = (new BaseApiValidate([
  92. 'voucher_id' => 'require|number'
  93. ]))->checkBody();
  94. $r = $this->service->exchangeVoucher($user->id, $params["voucher_id"]);
  95. $r->code() ? $this->success($r->data()) : $this->error($r->msg());
  96. }
  97. public function deposit()
  98. {
  99. $user = $this->auth->getUser();
  100. $params = (new BaseApiValidate([
  101. 'platform' => 'require',
  102. 'amount' => 'require|between:1,100000',
  103. ]))->checkBody();
  104. if (!in_array($params["platform"], [\E_ORDER_PAY_TYPE::Wechat, \E_ORDER_PAY_TYPE::ALi, \E_ORDER_PAY_TYPE::Bank]))
  105. $this->error("platform error");
  106. $r = $this->service->deposit(
  107. $user->id,
  108. $params["platform"],
  109. fixed2Float($params["amount"])
  110. );
  111. $r->code() == 1 ? $this->success($r->data(), $r->msg()) : $this->error($r->msg(), null, $r->code());
  112. }
  113. }