| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace app\api\controller;
- use app\api\service\VipService;
- use app\api\service\WalletService;
- use app\api\validate\BaseApiValidate;
- use app\common\controller\Api;
- use think\Request;
- class Wallet extends Api
- {
- private $service;
- public function __construct(Request $request = null)
- {
- parent::__construct($request);
- $this->service = new WalletService();
- }
- public function fetchRechargeOption()
- {
- $this->success($this->service->fetchRechargeOption());
- }
- public function fetchVoucher()
- {
- $user = $this->auth->getUser();
- $params = (new BaseApiValidate([
- 'status' => 'require',
- 'page' => 'number',
- 'size' => 'number'
- ]))->checkBody();
- $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"]);
- $this->success($r);
- }
- public function rechargeBalance()
- {
- $user = $this->auth->getUser();
- $params = (new BaseApiValidate([
- "platform" => "require",
- 'payment_type' => 'require',
- 'amount' => 'require|between:1,100000'
- ], ["amount.between" => "充值面额必须在1~100000之间"])
- )->checkBody();
- if (!in_array($params["payment_type"], [\E_ORDER_PAY_TYPE::Wechat, \E_ORDER_PAY_TYPE::ALi]))
- $this->error("支付方式错误");
- if (!in_array($params["platform"], ["app", "web", "applet"]))
- $this->error("platform 错误");
- $r = $this->service->rechargeBalance($user->id, $params["payment_type"], $params["amount"], $params["platform"]);
- $r->code() ? $this->success($r->data()) : $this->error($r->msg());
- }
- public function renew()
- {
- $params = (new BaseApiValidate([
- "platform" => "require",
- 'payment_type' => 'require',
- 'membership_config_id' => 'require|number'
- ]))->checkBody();
- $user = $this->auth->getUser();
- $r = (new VipService())->renew($user->id, $params['membership_config_id'], $params["payment_type"], $params["platform"]);
- $r->code() ? $this->success($r->data()) : $this->error($r->msg());
- }
- public function fetchBill()
- {
- $user = $this->auth->getUser();
- $params = (new BaseApiValidate([
- 'currency_type' => 'require',
- 'change_types' => 'require',
- 'page' => 'require|number',
- 'size' => 'require|number',
- ]))->checkBody();
- if (!in_array($params["currency_type"], [\E_USER_BILL_CURRENCY_TYPE::Money, \E_USER_BILL_CURRENCY_TYPE::Score]))
- $this->error("currency_type error");
- $r = $this->service->fetchBill(
- $user->id,
- $params["currency_type"],
- explode(",", (string)$params["change_types"]),
- $params["page"],
- $params["size"]
- );
- $this->success($r);
- }
- public function delBills()
- {
- $user = $this->auth->getUser();
- $params = (new BaseApiValidate([
- 'bill_ids' => 'require',
- ]))->checkBody();
- $bill_ids = explode(",", $params["bill_ids"]);
- $r = $this->service->delBills($user->id, $bill_ids);
- $r->code() ? $this->success($r->data()) : $this->error($r->msg());
- }
- public function exchangeVoucher()
- {
- $user = $this->auth->getUser();
- $params = (new BaseApiValidate([
- 'voucher_id' => 'require|number'
- ]))->checkBody();
- $r = $this->service->exchangeVoucher($user->id, $params["voucher_id"]);
- $r->code() ? $this->success($r->data()) : $this->error($r->msg());
- }
- public function deposit()
- {
- $user = $this->auth->getUser();
- $params = (new BaseApiValidate([
- 'platform' => 'require',
- 'amount' => 'require|between:1,100000',
- ]))->checkBody();
- if (!in_array($params["platform"], [\E_ORDER_PAY_TYPE::Wechat, \E_ORDER_PAY_TYPE::ALi, \E_ORDER_PAY_TYPE::Bank]))
- $this->error("platform error");
- $r = $this->service->deposit(
- $user->id,
- $params["platform"],
- fixed2Float($params["amount"])
- );
- $r->code() == 1 ? $this->success($r->data(), $r->msg()) : $this->error($r->msg(), null, $r->code());
- }
- }
|