LoginLogic.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\shop\logic;
  20. use app\common\basics\Logic;
  21. use app\common\model\shop\ShopAdmin;
  22. use app\common\server\ConfigServer;
  23. use think\facade\Cookie;
  24. /**
  25. * 商家登录逻辑
  26. * Class LoginLogic
  27. * @package app\shop\logic
  28. */
  29. class LoginLogic extends Logic
  30. {
  31. /**
  32. * Notes: 登录
  33. * @param $post
  34. * @author 段誉(2021/4/10 10:40)
  35. * @return bool
  36. */
  37. public static function login($post)
  38. {
  39. $adminModel = new ShopAdmin();
  40. $admin_info = $adminModel->alias('a')
  41. ->join('shop s', 's.id = a.shop_id')
  42. ->field(['a.id', 'a.account', 'a.name', 'role_id', 'shop_id', 's.name' => 'shop_name'])
  43. ->where(['a.account' => $post['account'], 'a.del' => 0])
  44. ->findOrEmpty()->toArray();
  45. //session
  46. session('shop_info', $admin_info);
  47. //登录信息更新
  48. $adminModel->where(['account' => $post['account']])
  49. ->update([
  50. 'login_ip' => request()->ip(),
  51. 'login_time' => time()
  52. ]);
  53. //记住账号
  54. if (isset($post['remember_account']) && $post['remember_account'] == 'on') {
  55. Cookie::set('account', $post['account']);
  56. } else {
  57. Cookie::delete('account');
  58. }
  59. return true;
  60. }
  61. /**
  62. * Notes: 退出
  63. * @author 段誉(2021/4/10 10:40)
  64. */
  65. public static function logout()
  66. {
  67. session('shop_info', null);
  68. }
  69. public static function config()
  70. {
  71. $config = [
  72. 'company_name' => ConfigServer::get('copyright', 'company_name'),
  73. 'number' => ConfigServer::get('copyright', 'number'),
  74. 'link' => ConfigServer::get('copyright', 'link'),
  75. 'login_logo' => ConfigServer::get('website_shop', 'shop_login_logo'),
  76. 'login_image' => ConfigServer::get('website_shop', 'shop_login_image'),
  77. 'login_title' => ConfigServer::get('website_shop', 'shop_login_title'),
  78. 'name' => ConfigServer::get('website', 'name'),
  79. 'web_favicon' => ConfigServer::get('website', 'web_favicon'),
  80. ];
  81. return $config;
  82. }
  83. }