diff --git a/app/common/repositories/system/merchant/MerchantAdminRepository.php b/app/common/repositories/system/merchant/MerchantAdminRepository.php index dccf143..ec509b4 100644 --- a/app/common/repositories/system/merchant/MerchantAdminRepository.php +++ b/app/common/repositories/system/merchant/MerchantAdminRepository.php @@ -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 diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index 5b4d261..cd41b35 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -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'] + ]); + } + } diff --git a/route/api.php b/route/api.php index b49e429..205406e 100644 --- a/route/api.php +++ b/route/api.php @@ -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');