fxi:客户登录注册模块接口修改、代码类目模型层库类型名称获取器修改

This commit is contained in:
xjh 2023-07-07 11:03:11 +08:00
parent 4382c5a091
commit 71f2e376b7
4 changed files with 33 additions and 63 deletions

View File

@ -6,6 +6,7 @@ use app\common\arw\adjfut\src\Validate;
use app\BaseController;
use app\common\logic\Login\CustomerLogin as LogicCustomerLogin;
use app\common\model\Token as ModelToken;
use app\common\model\Customer\Customer as ModelCustomer;
use app\Request;
use think\captcha\facade\Captcha;
use think\middleware\SessionInit;
@ -30,25 +31,33 @@ class Login extends BaseController
}
/**
* 客户账号注册接口
*
* 客户账号登录/注册接口
*
* @param Request $request
* @return array
* @date 2023-06-25
* @date 2023-07-07
* @author xjh
* @since 1.0.0
*/
public function accountRegistration(Request $request): array
public function accountLoginRegister(Request $request): array
{
$params = Validate::param([
'customer_name|客户昵称' => 'require',
'customer_account|客户账号' => 'require|alphaNum|min:10',
'customer_account|客户账号' => 'require|alphaNum|min:10',
'customer_password|客户密码' => 'require|alphaNum|min:8',
// 'captcha|验证码' => $request->isProd() ? 'require|captcha' : false
]);
$customer = ModelCustomer::where('customer_account', $params['customer_account'])->find();
$token = null;
Db::startTrans();
try {
Db::startTrans();
$token = LogicCustomerLogin::accountRegistration($params);
//登录
if ($customer) {
$token = LogicCustomerLogin::accountLogin($params);
}
//注册
else {
$token = LogicCustomerLogin::accountRegistration($params);
}
Db::commit();
return [
'code' => 0,
@ -56,45 +65,11 @@ class Login extends BaseController
'token' => $token->token_content,
'exp_time' => $token->token_exp_time,
],
'msg' => '注册成功!'
'msg' => $customer ? '登录成功!' : '注册成功!'
];
} catch (\Throwable $th) {
Db::rollback();
throwErrorMsg($th->getMessage());
}
}
/**
* 客户账号登录接口
*
* @param Request $request
* @return array
* @date 2023-06-25
* @author xjh
* @since 1.0.0
*/
public function accountLogin(Request $request): array
{
$params = Validate::param([
'customer_account|客户账号' => 'require|alphaNum|min:10',
'customer_password|客户密码' => 'require|alphaNum|min:8',
// 'captcha|验证码' => $request->isProd() ? 'require|captcha' : false
]);
try {
Db::startTrans();
$token = LogicCustomerLogin::accountLogin($params);
Db::commit();
return [
'code' => 0,
'data' => [
'token' => $token->token_content,
'exp_time' => $token->token_exp_time,
],
'msg' => '登录成功!'
];
} catch (\Throwable $th) {
Db::rollback();
throwErrorMsg($th->getMessage());
throw $th;
}
}
@ -124,4 +99,4 @@ class Login extends BaseController
{
return Captcha::create();
}
}
}

View File

@ -29,8 +29,8 @@ class CustomerLogin
public static function accountRegistration(array $params): ModelToken
{
BaseModel::setUserGuid(false);
$customer_create = ModelCustomer::create([
'customer_name' => $params['customer_name'],
$customer_create = ModelCustomer::create([
'customer_name' => ModelCustomer::DEFAULT_NAME,
'customer_account' => $params['customer_account'],
'customer_password' => $params['customer_password'],
]);
@ -53,10 +53,10 @@ class CustomerLogin
if (!$customer) {
throwErrorMsg("账号不存在!");
}
if ($customer->customer_password != LogicCustomer::encryptPassword($params['customer_password'])) {
if ($customer->customer_password != LogicCustomer::encryptPassword($params['customer_password'])) {
throwErrorMsg("密码错误!");
}
return self::handleTokenData($customer->customer_guid);
return self::handleTokenData($customer->customer_guid);
}
/**
@ -82,7 +82,8 @@ class CustomerLogin
return ModelToken::login(
$customer_guid,
ModelToken::CUSTOMER_TYPE,
['menu' => $menus, 'api' => $api,]
['menu' => $menus, 'api' => $api,
]
);
}
}
}

View File

@ -225,21 +225,13 @@ class CodeModuleCategory extends BaseModel
* 获取库类型名称
*
* @param string $value
* @return array
* @return string
* @date 2023-07-01
* @author lwh
* @since 1.0.0
*/
public function getLibraryTypeAttr($value, $data)
{
$library = $data['code_module_category_library_type'];
$library_arr = explode(',', $library);
$library_name_arr = [];
foreach ($library_arr as $key => $value) {
$library_type = ModelDictionary::getDictionaryData('library_type');
$library_name_arr[] = ModelDictionary::getDataDictionaryName($library_type, $value);
}
return $library_name_arr;
return ModelDictionary::getDataDictionaryName(ModelDictionary::getDictionaryData('library_type'), $data['code_module_category_library_type']);
}
}

View File

@ -59,6 +59,8 @@ class Customer extends BaseModel
const BLACKLIST_ENABLE = 1;
// 是否黑名单 否
const BLACKLIST_DISABLE = 2;
// 新客户默认名
const DEFAULT_NAME = "新客户";
/**
* 新增前
@ -104,7 +106,7 @@ class Customer extends BaseModel
self::class,
$model->customer_guid,
$model->getData(),
['customer_account' => '账号',],
['customer_account' => '账号'],
['customer_account' => "账号已存在!"]
);
}
@ -150,4 +152,4 @@ class Customer extends BaseModel
{
return "客户名称:【{$data['customer_name']}】 账号:【{$data['customer_account']}";
}
}
}