| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- namespace app\controller\wap;
- use app\extra\basic\Base;
- use app\extra\wechat\WechatService;
- use app\middleware\WxMiddleware;
- use app\model\system\SystemUser;
- use app\model\system\SystemUserOpen;
- use LinFly\Annotation\Route\Controller;
- use LinFly\Annotation\Route\Middleware;
- use LinFly\Annotation\Route\Route;
- use Shopwwi\WebmanAuth\Auth;
- use support\Request;
- use support\Response;
- #[Controller(prefix: "/wap/login"),Middleware(WxMiddleware::class)]
- class Login extends Base
- {
- protected array $noNeedLogin = ["checkLogin"];
- #[Route(path: "check",methods: "post")]
- public function checkLogin(Request $request): Response
- {
- try {
- $source = $request->header("referer");
- // $userInfo = WechatService::getWebOauthInfo($source,1,false);
- $userInfo['openid'] = 123;
- if (empty($userInfo['openid'])) {
- return success("ok",['url' => $userInfo['url'],'type' => 1]); // 跳转
- } else {
- $user = (new SystemUserOpen)->where(['openid' => $userInfo['openid']])->findOrEmpty();
- if ($user->isEmpty())
- {
- return success("ok",['url' => '','type' => 2,'token' => ['access_token' => $userInfo['openid']]]); // 跳到绑定用户
- }
- $loginUser = (new SystemUser)->where(['id' => $user['uid']])->findOrEmpty();
- return success("ok",['url' => '','type' => 3,'menu' => $this->getMenu(),'token' => get_object_vars((new Auth)->guard("admin")->login($loginUser))]); // 正常登陆进入
- }
- } catch (\Throwable $th) {
- return error($th->getMessage());
- }
- }
- /**
- * @return array[]
- */
- protected function getMenu(): array
- {
- return [
- [
- "path" => "/dashboard",
- "name" => "dashboard",
- "component" => "dashboard",
- "meta" => [
- "icon" => "",
- "title" => "总揽",
- "type" => "menu"
- ]
- ],[
- "path" => "/shop/detail",
- "name" => "shop/detail",
- "component" => "shop/detail",
- "meta" => [
- "icon" => "",
- "title" => "店铺详情",
- "type" => "menu"
- ]
- ],[
- "path" => "/print",
- "name" => "print/index",
- "component" => "print/index",
- "meta" => [
- "icon" => "",
- "title" => "打印机",
- "type" => "menu"
- ]
- ],[
- "path" => "/print/price",
- "name" => "print/price",
- "component" => "print/price",
- "meta" => [
- "icon" => "",
- "title" => "价格设置",
- "type" => "menu"
- ]
- ],[
- "path" => "/print/discount",
- "name" => "print/discount",
- "component" => "print/discount",
- "meta" => [
- "icon" => "",
- "title" => "折扣设置",
- "type" => "menu"
- ]
- ],[
- "path" => "/order",
- "name" => "order/index",
- "component" => "order/index",
- "meta" => [
- "icon" => "",
- "title" => "实时订单",
- "type" => "menu"
- ]
- ],[
- "path" => "/turnover/index",
- "name" => "turnover/index",
- "component" => "turnover/index",
- "meta" => [
- "icon" => "",
- "title" => "营业额",
- "type" => "menu"
- ]
- ],[
- "path" => "/member/index",
- "name" => "member/index",
- "component" => "member/index",
- "meta" => [
- "icon" => "",
- "title" => "会员卡",
- "type" => "menu"
- ]
- ],[
- "path" => "/wallet/index",
- "name" => "wallet/index",
- "component" => "wallet/index",
- "meta" => [
- "icon" => "",
- "title" => "我的钱包",
- "type" => "menu"
- ]
- ],[
- "path" => "/shop/bind",
- "name" => "shop/bind",
- "component" => "shop/bind",
- "meta" => [
- "icon" => "",
- "title" => "绑定门店",
- "type" => "menu"
- ]
- ],[
- "path" => "/shop/change",
- "name" => "shop/change",
- "component" => "shop/change",
- "meta" => [
- "icon" => "",
- "title" => "切换门店",
- "type" => "menu"
- ]
- ],[
- "path" => "/shop/msg",
- "name" => "shop/msg",
- "component" => "shop/msg",
- "meta" => [
- "icon" => "",
- "title" => "消息开关",
- "type" => "menu"
- ]
- ]
- ];
- }
- /**
- * 获取当前请求的完整 URL
- * @param bool $withQuery 是否包含查询参数
- * @return string
- */
- protected function getFullUrl($withQuery = true) {
- // 1. 获取协议(支持代理)
- $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
- || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)
- ? 'https' : 'http';
- // 2. 获取主机名(支持代理)
- $host = $_SERVER['HTTP_X_FORWARDED_HOST']
- ?? $_SERVER['HTTP_HOST']
- ?? $_SERVER['SERVER_NAME']
- ?? 'localhost';
- // 3. 获取端口(支持代理)
- $port = $_SERVER['HTTP_X_FORWARDED_PORT']
- ?? $_SERVER['SERVER_PORT']
- ?? 80;
- // 4. 获取请求URI(包含路径和查询参数)
- $requestUri = $_SERVER['REQUEST_URI'] ?? '/';
- // 5. 构建基础URL
- $baseUrl = $protocol . '://' . $host;
- // 6. 如果不是标准端口,添加端口号
- $isStandardPort = ($protocol === 'http' && $port == 80)
- || ($protocol === 'https' && $port == 443);
- if (!$isStandardPort) {
- $baseUrl .= ':' . $port;
- }
- // 7. 返回完整URL
- return $baseUrl . $requestUri;
- }
- }
|