LoginController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 17/2/22
  6. * Time: 上午11:56
  7. */
  8. namespace app\frontend\modules\member\controllers;
  9. use app\common\components\ApiController;
  10. use app\common\events\member\MemberLoginEvent;
  11. use app\common\facades\RichText;
  12. use app\common\helpers\Client;
  13. use app\common\helpers\Url;
  14. use app\common\models\Member;
  15. use app\common\models\Protocol;
  16. use app\common\services\Session;
  17. use app\frontend\models\MemberShopInfo;
  18. use app\frontend\modules\member\services\factory\MemberFactory;
  19. use app\frontend\modules\member\services\MemberService;
  20. use Illuminate\Contracts\Encryption\DecryptException;
  21. class LoginController extends ApiController
  22. {
  23. protected $publicController = ['Login'];
  24. protected $publicAction = ['index', 'phoneSetGet', 'chekAccount', 'loginMode','newLoginMode'];
  25. protected $ignoreAction = ['index', 'phoneSetGet', 'chekAccount', 'loginMode','newLoginMode'];
  26. public function index()
  27. {
  28. $type = request()->input('type');
  29. $uniacid = \YunShop::app()->uniacid;
  30. $mid = Member::getMid();
  31. //判断是否开启微信登录
  32. if (\YunShop::request()->show_wechat_login) {
  33. return $this->init_login();
  34. }
  35. if (!empty($type)) {
  36. $member = MemberFactory::create($type);
  37. if ($member !== null) {
  38. $msg = $member->login();
  39. if (!empty($msg)) {
  40. if ($msg['status'] == 1 || $msg['status'] == 11) {
  41. $url = Url::absoluteApp('member', ['i' => $uniacid, 'mid' => $mid]);
  42. if (isset($msg['json']['redirect_url'])) {
  43. $url = $msg['json']['redirect_url'];
  44. }
  45. if (isset($msg['variable']['url'])) {
  46. $url = $msg['variable']['url'];
  47. }
  48. $data = $msg['variable'];
  49. $data['status'] = $msg['status'];
  50. $data['url'] = $url;
  51. $this->updateLastLoginTime($msg['json']['uid']);
  52. return $this->successJson($msg['json'], $data);
  53. } else {
  54. return $this->errorJson($msg['json'], ['status' => $msg['status']]);
  55. }
  56. } else {
  57. return $this->errorJson('登录失败', ['status' => 3]);
  58. }
  59. } else {
  60. return $this->errorJson('登录异常', ['status' => 2]);
  61. }
  62. } else {
  63. return $this->errorJson('客户端类型错误', ['status' => 0]);
  64. }
  65. }
  66. /**
  67. * 初始化登录,判断是否开启微信登录
  68. *
  69. * @return \Illuminate\Http\JsonResponse
  70. */
  71. private function init_login()
  72. {
  73. $weixin_oauth = \Setting::get('shop_app.pay.weixin_oauth');
  74. return $this->successJson('', ['status' => 1, 'wetach_login' => $weixin_oauth]);
  75. }
  76. public function updateLastLoginTime($uid)
  77. {
  78. event(new MemberLoginEvent($uid));
  79. MemberShopInfo::where('member_id', $uid)->update(['last_login_time' => time()]);
  80. }
  81. public function phoneSetGet()
  82. {
  83. $phone_oauth = \Setting::get('shop_app.pay.phone_oauth');
  84. if (empty($phone_oauth)) {
  85. $phone_oauth = '0';
  86. }
  87. return $this->successJson('ok', ['phone_oauth' => $phone_oauth]);
  88. }
  89. public function chekAccount()
  90. {
  91. $type = \YunShop::request()->type;
  92. if (1 == $type) {
  93. $member = MemberFactory::create($type);
  94. $member->chekAccount();
  95. }
  96. }
  97. public function checkLogin()
  98. {
  99. return $this->successJson('已登录');
  100. }
  101. public function loginMode()
  102. {
  103. $data = [];
  104. //增加验证码功能
  105. $status = \Setting::get('shop.sms.status');
  106. if (extension_loaded('fileinfo')) {
  107. if ($status == 1) {
  108. $captcha = self::captcha();
  109. $result['captcha'] = $captcha;
  110. $result['captcha']['status'] = $status;
  111. } else {
  112. $result['captcha']['status'] = $status;
  113. }
  114. }
  115. $data['yun_sign'] = [];
  116. if (app('plugins')->isEnabled('yun-sign')) {
  117. $yun_sign = [
  118. 'login_type' => 5,
  119. 'redirect_url' => '',
  120. 'tel' => ''
  121. ];
  122. $redirect_url = Session::get('ys_short_url_redirect_url');
  123. $redirect_tel = intval(Session::get('ys_short_url_redirect_tel'));
  124. if ($redirect_url && $redirect_tel) {
  125. $yun_sign = [
  126. 'login_type' => 10,
  127. 'redirect_url' => $redirect_url,
  128. 'tel' => $redirect_tel
  129. ];
  130. }
  131. $data['yun_sign'] = $yun_sign;
  132. }
  133. $data['sms'] = $result;
  134. $registerSet = \Setting::get('shop.register');
  135. $data['mobile_login_code'] = !$registerSet['login_mode'] || in_array('mobile_code',$registerSet['login_mode']) ? 1 : 0;
  136. $data['mobile_code_login'] = !$registerSet['login_mode'] || in_array('mobile_code',$registerSet['login_mode']) ? 1 : 0;//开启手机验证码登录
  137. $data['password_login'] = !$registerSet['login_mode'] || in_array('password',$registerSet['login_mode']) ? 1 : 0;//开启密码登录
  138. $data['logo'] = !empty(\Setting::get('shop.shop')['logo']) ? yz_tomedia(\Setting::get('shop.shop')['logo']) : 0;
  139. $data['protocol_title'] = Protocol::uniacid()->value('title') ?: '平台用户协议';
  140. $data['country_code'] = \Setting::get('shop.sms')['country_code']?1:0;
  141. if (!is_null(\app\common\modules\shop\ShopConfig::current()->get('wechat_qrcode_config'))) {
  142. $class = array_get(\app\common\modules\shop\ShopConfig::current()->get('wechat_qrcode_config'), 'class');
  143. $function = array_get(\app\common\modules\shop\ShopConfig::current()->get('wechat_qrcode_config'), 'function');
  144. $wechat_qrcode_config = $class::$function();
  145. $data['wechat_qrcode_config'] = [
  146. 'is_open' => $wechat_qrcode_config['is_open'],
  147. 'is_wechat_login' => $wechat_qrcode_config['is_wechat_login'],
  148. 'callback' => $wechat_qrcode_config['callback'],
  149. 'wechat_login_type' => $wechat_qrcode_config['wechat_login_type'],
  150. ];
  151. unset($wechat_qrcode_config);
  152. }
  153. return $this->successJson('ok', $data);
  154. }
  155. /**
  156. * 新版登录页接口
  157. * @return \Illuminate\Http\JsonResponse
  158. */
  159. public function newLoginMode()
  160. {
  161. //增加验证码功能
  162. $status = \Setting::get('shop.sms.status');
  163. if (extension_loaded('fileinfo')) {
  164. if ($status == 1) {
  165. $captcha = self::captcha();
  166. $result['captcha'] = $captcha;
  167. $result['captcha']['status'] = $status;
  168. } else {
  169. $result['captcha']['status'] = $status;
  170. }
  171. }
  172. $data['yun_sign'] = [];
  173. if (app('plugins')->isEnabled('yun-sign')) {
  174. $yun_sign = [
  175. 'login_type' => 5,
  176. 'redirect_url' => '',
  177. 'tel' => ''
  178. ];
  179. $redirect_url = Session::get('ys_short_url_redirect_url');
  180. $redirect_tel = intval(Session::get('ys_short_url_redirect_tel'));
  181. if ($redirect_url && $redirect_tel) {
  182. $yun_sign = [
  183. 'login_type' => 10,
  184. 'redirect_url' => $redirect_url,
  185. 'tel' => $redirect_tel
  186. ];
  187. }
  188. $data['yun_sign'] = $yun_sign;
  189. }
  190. $data['is_wallet_log'] = 0;
  191. if (app('plugins')->isEnabled('love-speed-pool')) {
  192. //钱包登录入口
  193. $data['is_wallet_log'] = \Setting::get('plugin.love_speed_pool.is_wallet_log');
  194. }
  195. $data['sms'] = $result ? : [];
  196. $shopSet = \Setting::get('shop.shop');
  197. $registerSet = \Setting::get('shop.register');
  198. $memberSet = \Setting::get('shop.member');
  199. $data['get_register'] = $memberSet['get_register'] ? 1 : 0;
  200. $data['shop_name'] = $shopSet['name']?:'商城';
  201. $data['logo'] = $shopSet['logo'] ? yz_tomedia($shopSet['logo']) : "";
  202. $data['title1'] = $registerSet['title1'] ? : '欢迎来到['.($shopSet['name']?:'商城').']';
  203. $data['title2'] = $registerSet['title2'] ? : '登录尽享各种优惠权益!';
  204. $registerSet['login_mode'] || $registerSet['login_mode'] = [];
  205. $data['mobile_code_login'] = !$registerSet['login_mode'] || in_array('mobile_code',$registerSet['login_mode']) ? 1 : 0;//开启手机验证码登录
  206. $data['register_status'] = $registerSet['get_register'] == 1 ? 1 : 0;//注册状态/
  207. $data['password_login'] = !$registerSet['login_mode'] || in_array('password',$registerSet['login_mode']) ? 1 : 0;//开启密码登录
  208. $data['country_code'] = \Setting::get('shop.sms')['country_code']?1:0;
  209. $agreement = RichText::get('shop.agreement');
  210. $data['platform_agreement'] = [
  211. 'status' => $shopSet['is_agreement'] ? 1 : 0,
  212. 'title' => $shopSet['agreement_name'] ? : "平台协议",
  213. 'content' => $agreement ? : ""
  214. ];
  215. $protocol = Protocol::uniacid()->first();
  216. $data['register_agreement'] = [
  217. 'status' => $protocol->status ? : 0,
  218. 'title' => $protocol->title ? : "会员注册协议",
  219. 'default_tick' => $protocol->default_tick ? : 0,
  220. 'content' => $protocol->content ? : ""
  221. ];
  222. if (!is_null(\app\common\modules\shop\ShopConfig::current()->get('wechat_qrcode_config'))) {
  223. $class = array_get(\app\common\modules\shop\ShopConfig::current()->get('wechat_qrcode_config'), 'class');
  224. $function = array_get(\app\common\modules\shop\ShopConfig::current()->get('wechat_qrcode_config'), 'function');
  225. $wechat_qrcode_config = $class::$function();
  226. $data['wechat_qrcode_config'] = [
  227. 'is_open' => $wechat_qrcode_config['is_open'],
  228. 'is_wechat_login' => $wechat_qrcode_config['is_wechat_login'],
  229. 'callback' => $wechat_qrcode_config['callback'],
  230. 'wechat_login_type' => $wechat_qrcode_config['wechat_login_type'],
  231. ];
  232. unset($wechat_qrcode_config);
  233. }
  234. return $this->successJson('ok', $data);
  235. }
  236. //增加验证码功能
  237. public function captcha()
  238. {
  239. $captcha = app('captcha');
  240. $captcha_base64 = $captcha->create('default', true);
  241. return $captcha_base64;
  242. }
  243. }