LoginLogic.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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\admin\logic;
  20. use app\common\basics\Logic;
  21. use app\common\model\Admin;
  22. use app\common\server\ConfigServer;
  23. use think\facade\Cookie;
  24. /**
  25. * 后台登录 逻辑
  26. * Class LoginLogic
  27. * @Author FZR
  28. * @package app\admin\logic
  29. */
  30. class LoginLogic extends Logic
  31. {
  32. /**
  33. * Notes: 登录
  34. * @param $post
  35. * @author 段誉(2021/4/10 10:40)
  36. * @return bool
  37. */
  38. public static function login($post)
  39. {
  40. $adminModel = new Admin();
  41. $admin_info = $adminModel
  42. ->field(['id', 'account', 'name', 'role_id'])
  43. ->where(['account' => $post['account'], 'del' => 0])
  44. ->findOrEmpty()->toArray();
  45. //session
  46. session('admin_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('admin_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_platform', 'platform_login_logo'),
  76. 'login_image' => ConfigServer::get('website_platform', 'platform_login_image'),
  77. 'login_title' => ConfigServer::get('website_platform', 'platform_login_title'),
  78. 'name' => ConfigServer::get('website', 'name'),
  79. 'web_favicon' => ConfigServer::get('website', 'web_favicon'),
  80. ];
  81. return $config;
  82. }
  83. }