|
|
@@ -3,6 +3,8 @@
|
|
|
namespace app\controller\exe;
|
|
|
|
|
|
use app\extra\basic\Base;
|
|
|
+use app\middleware\ExeMiddleware;
|
|
|
+use app\model\saas\SaasAgent;
|
|
|
use app\model\system\SystemUser;
|
|
|
use LinFly\Annotation\Route\Controller;
|
|
|
use LinFly\Annotation\Route\Route;
|
|
|
@@ -11,6 +13,7 @@ use support\Request;
|
|
|
use support\Response;
|
|
|
use think\facade\Db;
|
|
|
use Tinywan\Captcha\Captcha;
|
|
|
+use Webman\Annotation\Middleware;
|
|
|
|
|
|
|
|
|
#[Controller(prefix: "/exe/login")]
|
|
|
@@ -29,16 +32,78 @@ class Login extends Base
|
|
|
$param = $this->_valid([
|
|
|
"username.require" => trans("empty.user"),
|
|
|
"password.require" => trans("empty.passwd"),
|
|
|
- "code.require" => trans("empty.code"),
|
|
|
- "key.require" => trans("empty.data"),
|
|
|
],"post");
|
|
|
if (!is_array($param)) return error($param);
|
|
|
- if (Captcha::check($param['code'],$param['key']) === false) return errorTrans("error.captcha");
|
|
|
$map = ["is_deleted" => 0,"username" => $param['username']];
|
|
|
- return successTrans("success.login");
|
|
|
+ [$state,$msg,$user] = $this->checkLogin($map,2,$param);
|
|
|
+ if (!$state) return error($msg);
|
|
|
+ return successTrans("success.login",$user);
|
|
|
} catch (\Throwable $throwable) {
|
|
|
return error($throwable->getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 登录验证处理
|
|
|
+ * @param array $map
|
|
|
+ * @param int $type
|
|
|
+ * @param array $param
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ protected function checkLogin(array $map = [],int $type = 1,array $param = []): array
|
|
|
+ {
|
|
|
+ $user = (new SystemUser)->where($map)->findOrEmpty();
|
|
|
+ if ($user->isEmpty()) return [0,trans("error.user-empty"),[]];
|
|
|
+ if ($user['status'] <> 1) return [0,trans("error.user-status"),[]];
|
|
|
+ if ($user['type'] > 1) {
|
|
|
+ $typeUser = $this->getTypeUser($user['agent_id']);
|
|
|
+ if (empty($typeUser)) return [0,trans("empty.agent"),[]];
|
|
|
+ if ($typeUser['status'] <> 0) return [0,trans("error.agent"),[]];
|
|
|
+ if (time() > strtotime($typeUser['vip_end'])) return [0,trans("error.agent-out"),[]];
|
|
|
+ $user['shop_name'] = $typeUser['shop_name'];
|
|
|
+ }
|
|
|
+ if ($type == 2) {
|
|
|
+ if (md5(md5($param['password']).$user['salt']) <> $user['password']) return [0,trans("error.passwd"),[]];
|
|
|
+ }
|
|
|
+ $user->login_at = getDateFull();
|
|
|
+ $user->login_ip = request()->getRealIp();
|
|
|
+ $user->login_num = Db::raw("login_num+1");
|
|
|
+ $user->save();
|
|
|
+ return [1,'success',$user->toArray()];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取代理信息
|
|
|
+ * @param int $agentId
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ protected function getTypeUser(int $agentId = 0): array
|
|
|
+ {
|
|
|
+ return (new SaasAgent)->where("agent_id",$agentId)->findOrEmpty()->toArray();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ #[Route(path: "profile",methods: "get"),Middleware(ExeMiddleware::class)]
|
|
|
+ public function getLoginUser(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $agent = (new SaasAgent)->where("agent_id",$request->uuid)->findOrEmpty();
|
|
|
+ return successTrans("success.data",[
|
|
|
+ "vip_at" => empty($agent['vip_end'])?'无限期':date('Y-m-d',strtotime($agent['vip_end'])),
|
|
|
+ "agent_id" => $agent['agent_id'],
|
|
|
+ "shop" => $agent['shop_name']??'',
|
|
|
+ "address" => $agent['shop_address']??'',
|
|
|
+ "sys" => sConf("service.title"),
|
|
|
+ "logo" => sConf("service.logo")
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $exception){
|
|
|
+ return error($exception->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|