Login.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. namespace app\controller\wap;
  3. use app\extra\basic\Base;
  4. use app\extra\wechat\WechatService;
  5. use app\middleware\WxMiddleware;
  6. use app\model\system\SystemUser;
  7. use app\model\system\SystemUserOpen;
  8. use LinFly\Annotation\Route\Controller;
  9. use LinFly\Annotation\Route\Middleware;
  10. use LinFly\Annotation\Route\Route;
  11. use Shopwwi\WebmanAuth\Auth;
  12. use support\Request;
  13. use support\Response;
  14. #[Controller(prefix: "/wap/login"),Middleware(WxMiddleware::class)]
  15. class Login extends Base
  16. {
  17. protected array $noNeedLogin = ["checkLogin"];
  18. #[Route(path: "check",methods: "post")]
  19. public function checkLogin(Request $request): Response
  20. {
  21. try {
  22. $source = $request->header("referer");
  23. // $userInfo = WechatService::getWebOauthInfo($source,1,false);
  24. $userInfo['openid'] = 123;
  25. if (empty($userInfo['openid'])) {
  26. return success("ok",['url' => $userInfo['url'],'type' => 1]); // 跳转
  27. } else {
  28. $user = (new SystemUserOpen)->where(['openid' => $userInfo['openid']])->findOrEmpty();
  29. if ($user->isEmpty())
  30. {
  31. return success("ok",['url' => '','type' => 2,'token' => ['access_token' => $userInfo['openid']]]); // 跳到绑定用户
  32. }
  33. $loginUser = (new SystemUser)->where(['id' => $user['uid']])->findOrEmpty();
  34. return success("ok",['url' => '','type' => 3,'menu' => $this->getMenu(),'token' => get_object_vars((new Auth)->guard("admin")->login($loginUser))]); // 正常登陆进入
  35. }
  36. } catch (\Throwable $th) {
  37. return error($th->getMessage());
  38. }
  39. }
  40. /**
  41. * @return array[]
  42. */
  43. protected function getMenu(): array
  44. {
  45. return [
  46. [
  47. "path" => "/dashboard",
  48. "name" => "dashboard",
  49. "component" => "dashboard",
  50. "meta" => [
  51. "icon" => "",
  52. "title" => "总揽",
  53. "type" => "menu"
  54. ]
  55. ],[
  56. "path" => "/shop/detail",
  57. "name" => "shop/detail",
  58. "component" => "shop/detail",
  59. "meta" => [
  60. "icon" => "",
  61. "title" => "店铺详情",
  62. "type" => "menu"
  63. ]
  64. ],[
  65. "path" => "/print",
  66. "name" => "print/index",
  67. "component" => "print/index",
  68. "meta" => [
  69. "icon" => "",
  70. "title" => "打印机",
  71. "type" => "menu"
  72. ]
  73. ],[
  74. "path" => "/print/price",
  75. "name" => "print/price",
  76. "component" => "print/price",
  77. "meta" => [
  78. "icon" => "",
  79. "title" => "价格设置",
  80. "type" => "menu"
  81. ]
  82. ],[
  83. "path" => "/print/discount",
  84. "name" => "print/discount",
  85. "component" => "print/discount",
  86. "meta" => [
  87. "icon" => "",
  88. "title" => "折扣设置",
  89. "type" => "menu"
  90. ]
  91. ],[
  92. "path" => "/order",
  93. "name" => "order/index",
  94. "component" => "order/index",
  95. "meta" => [
  96. "icon" => "",
  97. "title" => "实时订单",
  98. "type" => "menu"
  99. ]
  100. ],[
  101. "path" => "/turnover/index",
  102. "name" => "turnover/index",
  103. "component" => "turnover/index",
  104. "meta" => [
  105. "icon" => "",
  106. "title" => "营业额",
  107. "type" => "menu"
  108. ]
  109. ],[
  110. "path" => "/member/index",
  111. "name" => "member/index",
  112. "component" => "member/index",
  113. "meta" => [
  114. "icon" => "",
  115. "title" => "会员卡",
  116. "type" => "menu"
  117. ]
  118. ],[
  119. "path" => "/wallet/index",
  120. "name" => "wallet/index",
  121. "component" => "wallet/index",
  122. "meta" => [
  123. "icon" => "",
  124. "title" => "我的钱包",
  125. "type" => "menu"
  126. ]
  127. ],[
  128. "path" => "/shop/bind",
  129. "name" => "shop/bind",
  130. "component" => "shop/bind",
  131. "meta" => [
  132. "icon" => "",
  133. "title" => "绑定门店",
  134. "type" => "menu"
  135. ]
  136. ],[
  137. "path" => "/shop/change",
  138. "name" => "shop/change",
  139. "component" => "shop/change",
  140. "meta" => [
  141. "icon" => "",
  142. "title" => "切换门店",
  143. "type" => "menu"
  144. ]
  145. ],[
  146. "path" => "/shop/msg",
  147. "name" => "shop/msg",
  148. "component" => "shop/msg",
  149. "meta" => [
  150. "icon" => "",
  151. "title" => "消息开关",
  152. "type" => "menu"
  153. ]
  154. ]
  155. ];
  156. }
  157. /**
  158. * 获取当前请求的完整 URL
  159. * @param bool $withQuery 是否包含查询参数
  160. * @return string
  161. */
  162. protected function getFullUrl($withQuery = true) {
  163. // 1. 获取协议(支持代理)
  164. $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
  165. || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)
  166. ? 'https' : 'http';
  167. // 2. 获取主机名(支持代理)
  168. $host = $_SERVER['HTTP_X_FORWARDED_HOST']
  169. ?? $_SERVER['HTTP_HOST']
  170. ?? $_SERVER['SERVER_NAME']
  171. ?? 'localhost';
  172. // 3. 获取端口(支持代理)
  173. $port = $_SERVER['HTTP_X_FORWARDED_PORT']
  174. ?? $_SERVER['SERVER_PORT']
  175. ?? 80;
  176. // 4. 获取请求URI(包含路径和查询参数)
  177. $requestUri = $_SERVER['REQUEST_URI'] ?? '/';
  178. // 5. 构建基础URL
  179. $baseUrl = $protocol . '://' . $host;
  180. // 6. 如果不是标准端口,添加端口号
  181. $isStandardPort = ($protocol === 'http' && $port == 80)
  182. || ($protocol === 'https' && $port == 443);
  183. if (!$isStandardPort) {
  184. $baseUrl .= ':' . $port;
  185. }
  186. // 7. 返回完整URL
  187. return $baseUrl . $requestUri;
  188. }
  189. }