添加:移动端商户模拟登录接口 支持根据商户ID免登录进入商户管理中心

This commit is contained in:
wuhui_zzw 2024-04-22 14:08:54 +08:00
parent 0636425c66
commit bd08cda5d2
3 changed files with 74 additions and 2 deletions

View File

@ -219,6 +219,49 @@ class MerchantAdminRepository extends BaseRepository
return $adminInfo;
}
/**
* Common: 根据商户id 模拟登录
* Author: wu-hui
* Time: 2024/04/22 13:54
* @param $merId
* @return array|Model
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function simulationLogin($merId){
$adminInfo = $this->dao->search($merId,['status' => 1],0)->findOrEmpty();
if ($adminInfo['status'] != 1) throw new ValidateException('账号已关闭');
/**
* @var MerchantRepository $merchantRepository
*/
$merchantRepository = app()->make(MerchantRepository::class);
$merchant = $merchantRepository->get($adminInfo->mer_id);
if (!$merchant) throw new ValidateException('商户不存在');
if (!$merchant['status']) throw new ValidateException('商户已被锁定');
$adminInfo->last_time = date('Y-m-d H:i:s');
$adminInfo->last_ip = app('request')->ip();
$adminInfo->login_count++;
$adminInfo->save();
event('admin.merLogin',compact('adminInfo'));
$adminInfo->merchant_type = $merchant->merchant_type ?? 0;
$adminInfo->mer_name = $merchant->mer_name ?? '';
$adminInfo->mer_avatar = $merchant->mer_avatar ?? '';
return $adminInfo;
}
/**
* @param string $token

View File

@ -152,7 +152,7 @@ class Merchant extends BaseController
return app('json')->fail('小程序码生成失败!');
}
/**
* Common: 商户登录移动端
* Common: 移动端商户登录 - 账号密码登录
* Author: wu-hui
* Time: 2024/02/28 17:30
* @return mixed
@ -180,6 +180,35 @@ class Merchant extends BaseController
'mer_avatar' => $admin['mer_avatar']
]);
}
/**
* Common: 移动端商户登录 - 模拟登录
* Author: wu-hui
* Time: 2024/04/22 13:55
* @param $merId
* @return mixed
*/
public function simulationLogin($merId){
// 参数获取
if($merId <= 0) throw new ValidateException('无有效门店!');
// 判断登录是否成功
$repository = app()->make(MerchantAdminRepository::class);
$adminInfo = $repository->simulationLogin($merId);
$tokenInfo = $repository->createToken($adminInfo);
$admin = $adminInfo->toArray();
// 判断:这里仅允许酒道馆和普通商户登录
if($admin['merchant_type'] == 2) throw new ValidateException('当前账号禁止登录!');
return app('json')->success([
'token' => $tokenInfo['token'],
'exp' => $tokenInfo['exp'],
'mer_id' => $admin['mer_id'],
'merchant_type' => $admin['merchant_type'],
'mer_name' => $admin['mer_name'],
'mer_avatar' => $admin['mer_avatar']
]);
}
}

View File

@ -598,7 +598,7 @@ Route::group('api/', function () {
Route::get('/local', 'Merchant/localLst');
// 酒道馆登录相关
Route::get('/login', 'Merchant/storeLogin');
Route::get('/simulation_login/:merId', 'Merchant/simulationLogin');
})->prefix('api.store.merchant.');
Route::post('store/certificate/:merId', 'api.Auth/getMerCertificate');