88 lines
2.5 KiB
PHP
88 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace app\common\logic\Login;
|
|
|
|
use app\common\model\Token;
|
|
use app\common\model\Customer\Customer as ModelCustomer;
|
|
use app\common\model\Token as ModelToken;
|
|
use app\BaseModel;
|
|
use app\common\logic\Customer\Customer as LogicCustomer;
|
|
use think\facade\Config;
|
|
use think\facade\Request;
|
|
use think\helper\Arr;
|
|
use think\Response;
|
|
use think\response\Redirect;
|
|
use app\common\arw\adjfut\src\Curl;
|
|
use app\common\arw\adjfut\src\Tool;
|
|
|
|
class CustomerLogin
|
|
{
|
|
/**
|
|
* 客户注册
|
|
*
|
|
* @param array $params 客户数据
|
|
* @return ModelToken
|
|
* @date 2023-06-25
|
|
* @author xjh
|
|
* @since 1.0.0
|
|
*/
|
|
public static function accountRegistration(array $params): ModelToken
|
|
{
|
|
BaseModel::setUserGuid(false);
|
|
$customer_create = ModelCustomer::create([
|
|
'customer_name' => ModelCustomer::DEFAULT_NAME,
|
|
'customer_email' => $params['customer_email'],
|
|
'customer_password' => $params['customer_password'],
|
|
]);
|
|
return self::handleTokenData($customer_create->customer_guid);
|
|
}
|
|
|
|
/**
|
|
* 客户登录
|
|
*
|
|
* @param array $params 客户数据
|
|
* @return ModelToken
|
|
* @date 2023-06-25
|
|
* @author xjh
|
|
* @since 1.0.0
|
|
*/
|
|
public static function accountLogin(array $params): ModelToken
|
|
{
|
|
BaseModel::setUserGuid(false);
|
|
$customer = ModelCustomer::where('customer_email', $params['customer_email'])->find();
|
|
if (!$customer) {
|
|
throwErrorMsg("该邮箱并未注册过!");
|
|
}
|
|
if ($customer->customer_password != LogicCustomer::encryptPassword($params['customer_password'])) {
|
|
throwErrorMsg("密码错误!");
|
|
}
|
|
return self::handleTokenData($customer->customer_guid);
|
|
}
|
|
|
|
/**
|
|
* 客户Token数据处理
|
|
*
|
|
* @param string $customer_guid 客户guid
|
|
* @return ModelToken
|
|
* @date 2023-06-25
|
|
* @author xjh
|
|
* @since 1.0.0
|
|
*/
|
|
private static function handleTokenData(string $customer_guid): ModelToken
|
|
{
|
|
$menus = ModelCustomer::getCustomerMenu();
|
|
$api = [];
|
|
foreach ($menus as $menu) {
|
|
$api = array_merge($api, explode(',', $menu['menu_api_url']));
|
|
}
|
|
$api = array_values(array_filter(array_unique($api)));
|
|
if (!$api) {
|
|
throwErrorMsg("无权登录");
|
|
}
|
|
return ModelToken::login(
|
|
$customer_guid,
|
|
ModelToken::CUSTOMER_TYPE,
|
|
['menu' => $menus, 'api' => $api]
|
|
);
|
|
}
|
|
} |