<?php
// +----------------------------------------------------------------------
// | onezan-admin 快速开发的管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.onezan.cn
// +----------------------------------------------------------------------
// | onezan团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: 543885307@qq.com
// +----------------------------------------------------------------------
namespace app\adminapi\controller\user;

use app\adminapi\controller\BaseAdminController;
use app\service\admin\user\UserService;
use app\service\admin\user\UserVerifyService;
use app\validate\admin\UserValidator;
use app\validate\domain\UserDomainValidator;
use think\Request;


/**
 * C端用户管理
 * 用户列表、详情、认证、重置密码、设置等级、余额调整
 * @package app\adminapi\controller\user
 */
class User extends BaseAdminController
{
    /**
     * 获取用户列表
     * @param Request $request
     * @return \think\response\Json
     */
    public function list(Request $request)
    {
        $this->validate($request->get(), UserValidator::class . '.list');
        return json($this->app->make(UserService::class)->list($request));
    }

    /**
     * 获取用户详情
     * @param Request $request
     * @return \think\response\Json
     */
    public function detail(Request $request)
    {
        $this->validate($request->get(), UserValidator::class . '.detail');
        return json($this->app->make(UserService::class)->detail($request));
    }

    /**
     * 认证用户
     * @param Request $request
     * @return \think\response\Json
     */
    public function verify(Request $request)
    {
        $params = $request->post();
        $this->validate($params, UserValidator::class . '.verify');
        $this->validateDomain($this->app->make(UserDomainValidator::class), $params, 'verify');
        return json($this->app->make(UserVerifyService::class)->review($request));
    }


    /**
     * 设置用户等级
     * @param Request $request
     * @return \think\response\Json
     */
    public function setLevel(Request $request)
    {
        $params = $request->post();
        $this->validate($params, UserValidator::class . '.set_level');
        $this->validateDomain($this->app->make(UserDomainValidator::class), $params, 'set_level');
        return json($this->app->make(UserService::class)->setLevel($request));
    }


    /**
     * 余额调整
     * @param Request $request
     * @return \think\response\Json
     */
    public function balanceAdjust(Request $request)
    {
        $params = $request->post();
        $this->validate($params, UserValidator::class . '.balance_adjust');
        $this->validateDomain($this->app->make(UserDomainValidator::class), $params, 'balance_adjust');
        return json($this->app->make(UserService::class)->balanceAdjust($request));
    }

    /**
     * 积分调整
     * @param Request $request
     * @return \think\response\Json
     */
    public function pointsAdjust(Request $request)
    {
        $params = $request->post();
        $this->validate($params, UserValidator::class . '.points_adjust');
        $this->validateDomain($this->app->make(UserDomainValidator::class), $params, 'points_adjust');
        return json($this->app->make(UserService::class)->pointsAdjust($request));
    }

    /**
     * 重置用户密码
     * @param Request $request
     * @return \think\response\Json
     */
    public function resetPassword(Request $request)
    {
        $params = $request->post();
        $this->validate($params, UserValidator::class . '.reset_password');
        $this->validateDomain($this->app->make(UserDomainValidator::class), $params, 'reset_password');
        return json($this->app->make(UserService::class)->resetPassword($request));
    }
}