fix:客户模块业务逻辑修改,不需要账号统一使用邮箱来充当客户唯一标识值

This commit is contained in:
xjh 2023-07-13 15:21:46 +08:00
parent 8d6f430d79
commit 71a0b282b9
5 changed files with 26 additions and 27 deletions

View File

@ -30,11 +30,11 @@ class Customer extends BaseController
{
$con = Tool::getOptionalQuery(
['customer_name', 'LIKE'],
['customer_account', 'LIKE'],
['customer_phone', 'LIKE'],
['customer_email', 'LIKE'],
['customer_sex', '='],
['customer_blacklist', '='],
['customer_create_time', 'BETWEEN', 'date_time'],
);
$query = ModelCustomer::where($con)
@ -42,15 +42,15 @@ class Customer extends BaseController
'customer_id',
'customer_guid',
'customer_name',
'customer_account',
'customer_phone',
'customer_email',
'customer_sex',
'customer_blacklist'
'customer_blacklist',
'customer_create_time',
])
->order('customer_update_time', 'desc');
return msg("获取客户列表成功!", $query);
return msg("获取客户列表成功!", $query);
}
/**
@ -67,12 +67,11 @@ class Customer extends BaseController
$params = $request->param();
$this->validate($params, [
'customer_name|客户昵称' => 'require',
'customer_account|客户账号' => 'require|alphaNum|min:10',
'customer_email|客户邮箱' => 'require|email',
'customer_password|客户密码' => 'require|alphaNum|min:8'
]);
ModelCustomer::create($params, [
'customer_name',
'customer_account',
'customer_password',
'customer_phone',
'customer_email',
@ -101,7 +100,8 @@ class Customer extends BaseController
'customer_guid|客户guid' => 'require',
]);
$model = ModelCustomer::where('customer_guid', $params['customer_guid'])->find();
if (!$model) throwErrorMsg("该客户不存在", 1);
if (!$model)
throwErrorMsg("该客户不存在", 1);
$model->allowField([
'customer_name',
'customer_phone',
@ -152,7 +152,8 @@ class Customer extends BaseController
'customer_password|客户密码' => 'require|alphaNum|min:8'
]);
$model = ModelCustomer::where('customer_guid', $params['customer_guid'])->find();
if (!$model) throwErrorMsg("该客户不存在", 1);
if (!$model)
throwErrorMsg("该客户不存在", 1);
$model->allowField(['customer_password'])->save($params);
return msg('编辑成功!');
}
@ -169,10 +170,10 @@ class Customer extends BaseController
public function getCustomerOptionList(Request $request): array
{
$select = ModelCustomer::scope('blacklist')
->field(['customer_guid', 'customer_name', 'customer_account'])
->field(['customer_guid', 'customer_name', 'customer_email'])
->append(['customer_show_text'])
->order('customer_update_time', 'desc')
->select();
return msg(0, '获取客户下拉选项数据成功!', ['data' => $select]);
}
}
}

View File

@ -25,7 +25,7 @@ class CodeModuleCategory
['cmc.code_module_category_name', 'LIKE'],
['cmc.code_module_category_ps', 'LIKE'],
['cmc.code_module_category_library_type', '='],
['cust.customer_name|cust.customer_account', 'LIKE', 'customer'],
['cust.customer_name|cust.customer_email', 'LIKE', 'customer'],
['cmc.code_module_category_audit', '='],
);

View File

@ -41,15 +41,15 @@ class Login extends BaseController
*/
public function accountLoginRegister(Request $request): array
{
$params = Validate::param([
'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 {
$params = Validate::param([
'customer_email|客户邮箱' => 'require|email',
'customer_password|客户密码' => 'require|alphaNum|min:8',
// 'captcha|验证码' => $request->isProd() ? 'require|captcha' : false
]);
$customer = ModelCustomer::where('customer_email', $params['customer_email'])->find();
$token = null;
//登录
if ($customer) {
$token = LogicCustomerLogin::accountLogin($params);

View File

@ -31,7 +31,7 @@ class CustomerLogin
BaseModel::setUserGuid(false);
$customer_create = ModelCustomer::create([
'customer_name' => ModelCustomer::DEFAULT_NAME,
'customer_account' => $params['customer_account'],
'customer_email' => $params['customer_email'],
'customer_password' => $params['customer_password'],
]);
return self::handleTokenData($customer_create->customer_guid);
@ -49,9 +49,9 @@ class CustomerLogin
public static function accountLogin(array $params): ModelToken
{
BaseModel::setUserGuid(false);
$customer = ModelCustomer::where('customer_account', $params['customer_account'])->find();
$customer = ModelCustomer::where('customer_email', $params['customer_email'])->find();
if (!$customer) {
throwErrorMsg("账号不存在!");
throwErrorMsg("该邮箱并未注册过!");
}
if ($customer->customer_password != LogicCustomer::encryptPassword($params['customer_password'])) {
throwErrorMsg("密码错误!");
@ -82,8 +82,7 @@ class CustomerLogin
return ModelToken::login(
$customer_guid,
ModelToken::CUSTOMER_TYPE,
['menu' => $menus, 'api' => $api,
]
['menu' => $menus, 'api' => $api]
);
}
}

View File

@ -26,7 +26,6 @@ class Customer extends BaseModel
'customer_id' => 'int',
'customer_guid' => 'string',
'customer_name' => 'string',
'customer_account' => 'string',
'customer_password' => 'string',
'customer_phone' => 'string',
'customer_email' => 'string',
@ -106,8 +105,8 @@ class Customer extends BaseModel
self::class,
$model->customer_guid,
$model->getData(),
['customer_account' => '账号'],
['customer_account' => "账号已存在!"]
['customer_email' => '邮箱'],
['customer_email' => "邮箱已注册!"]
);
}
@ -150,6 +149,6 @@ class Customer extends BaseModel
*/
public function getCustomerShowTextAttr($value, $data): string
{
return "客户名称:【{$data['customer_name']}账号:【{$data['customer_account']}";
return "客户名称:【{$data['customer_name']}邮箱:【{$data['customer_email']}";
}
}