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

137 lines
4.7 KiB
PHP

<?php
namespace app\api\controller\user;
use app\api\controller\BaseApiController;
use app\api\logic\user\UserLogic;
use app\api\validate\UserValidate;
use app\common\enum\PayEnum;
use app\common\logic\PaymentLogic;
/**
* 用户控制器
* Class UserController
* @package app\api\controller
*/
class UserController extends BaseApiController
{
// #[
// 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"),
// ]
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());
}
$data = UserLogic::info($this->userId);
return $this->success('绑定成功', $data, 1, 1);
}
// #[
// 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"),
// ]
public function info()
{
return $this->success('success', UserLogic::info($this->userId));
}
// #[
// ApiDoc\Title('充值金额'),
// ApiDoc\url('/api/user/user/rechange_amount'),
// ApiDoc\Method('Get'),
// ApiDoc\Param(),
// ApiDoc\NotHeaders(),
// ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
// ApiDoc\ResponseSuccess("data", type: "array"),
// ]
public function rechange_amount()
{
$res = UserLogic::rechange_level();
return $this->success('ok',$res);
}
// #[
// 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';
$result = PaymentLogic::pay(PayEnum::WECHAT_PAY_MINI, 'recharge', $order, $this->userInfo['terminal'], $redirectUrl);
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
return $this->success('', $result);
}
// #[
// ApiDoc\Title('会员账户详情'),
// ApiDoc\url('/api/user/user/capital_flow'),
// ApiDoc\Method('POST'),
// ApiDoc\Param(name: "page_no", type: "int", require: true, desc: "默认1页数"),
// ApiDoc\Param(name: "page_size", type: "int", require: false, desc: "条数默认15"),
// ApiDoc\NotHeaders(),
// ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
// ApiDoc\ResponseSuccess("data", type: "array"),
// ]
public function capital_flow()
{
$page_no = (int)$this->request->post('page_no',1);
$page_size = (int)$this->request->post('page_size',15);
$params['page_no'] = $page_no;
$params['page_size'] = $page_size;
if(empty($page_no) || empty($page_size)){
$params['page_no'] = 1;
$params['page_size'] = 15;
}
$res = UserLogic::capital_list($this->userId,$params);
$res['page_no'] =$params['page_no'];
$res['page_size'] =$params['page_size'];
return $this->success('ok',$res);
}
// #[
// ApiDoc\Title('会员账户统计'),
// ApiDoc\url('/api/user/user/capital_count'),
// ApiDoc\Method('POST'),
// ApiDoc\Param(),
// ApiDoc\NotHeaders(),
// ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
// ApiDoc\ResponseSuccess("data", type: "array"),
// ]
public function capital_count()
{
$res = UserLogic::capital_count($this->userId);
return $this->success('ok',$res);
}
}