multi-store/app/api/controller/user/UserController.php

85 lines
2.7 KiB
PHP
Raw Normal View History

2024-05-30 21:37:55 +08:00
<?php
namespace app\api\controller\user;
use app\api\controller\BaseApiController;
use app\api\logic\user\UserLogic;
use app\api\validate\UserValidate;
2024-06-04 23:15:30 +08:00
use app\common\enum\PayEnum;
use app\common\logic\PaymentLogic;
2024-06-04 16:51:26 +08:00
use hg\apidoc\annotation as ApiDoc;
2024-06-04 23:15:30 +08:00
use taoser\Validate;
#[ApiDoc\title('用户')]
2024-05-30 21:37:55 +08:00
/**
* 用户控制器
* Class UserController
* @package app\api\controller
*/
class UserController extends BaseApiController
{
2024-06-04 23:15:30 +08:00
#[
ApiDoc\Title('获取小程序手机号'),
ApiDoc\url('/api/user/user/getMobileByMnp'),
ApiDoc\Method('POST'),
ApiDoc\Param(name: "code", type: "string", require: true, desc: "换取手机的code"),
ApiDoc\NotHeaders(),
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
ApiDoc\ResponseSuccess("data", type: "array"),
]
2024-05-30 21:37:55 +08:00
public function getMobileByMnp()
{
$params = (new UserValidate())->post()->goCheck('getMobileByMnp');
$params['user_id'] = $this->userId;
$result = UserLogic::getMobileByMnp($params);
if ($result === false) {
return $this->fail(UserLogic::getError());
}
2024-06-04 15:26:45 +08:00
$data = UserLogic::info($this->userId);
return $this->success('绑定成功', $data, 1, 1);
2024-05-30 21:37:55 +08:00
}
2024-06-04 23:15:30 +08:00
#[
ApiDoc\Title('用户个人信息'),
ApiDoc\url('/api/user/user/info'),
ApiDoc\Method('POST'),
ApiDoc\Param(),
ApiDoc\NotHeaders(),
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
ApiDoc\ResponseSuccess("data", type: "array"),
]
2024-06-04 11:12:28 +08:00
public function info()
{
return $this->success('success', UserLogic::info($this->userId));
}
2024-06-04 23:15:30 +08:00
#[
ApiDoc\Title('小程序充值'),
ApiDoc\url('/api/user/user/recharge'),
ApiDoc\Method('POST'),
ApiDoc\Param(name: "price", type: "string", require: true, desc: "金额"),
ApiDoc\NotHeaders(),
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function recharge()
{
$params = (new UserValidate())->post()->goCheck('rechargeMoney');
$params['uid'] = $this->userId;
$params['channel_type'] = $this->userInfo['terminal'];
$order = UserLogic::recharge($params);
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
2024-06-05 13:37:25 +08:00
$result = PaymentLogic::pay(PayEnum::WECHAT_PAY, 'recharge', $order, $this->userInfo['terminal'], $redirectUrl);
2024-06-04 23:15:30 +08:00
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
return $this->success('', $result);
}
2024-06-04 11:12:28 +08:00
2024-06-04 16:51:26 +08:00
}