No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EyouUsers.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海口快推科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\common\model;
  14. use think\Db;
  15. use think\Model;
  16. /**
  17. * 公共会员模型
  18. */
  19. class EyouUsers extends Model
  20. {
  21. //初始化
  22. protected function initialize()
  23. {
  24. // 需要调用`Model`的`initialize`方法
  25. parent::initialize();
  26. }
  27. // 更新会员级别信息
  28. public function UpUsersLevelData($users_id = null)
  29. {
  30. if (!empty($users_id)) {
  31. $LevelData = [];
  32. /*查询系统初始的默认级别*/
  33. $LevelWhere = [
  34. 'level_id' => 1,
  35. 'is_system' => 1,
  36. ];
  37. $level = Db::name('users_level')->where($LevelWhere)->field('level_id,level_name,level_value')->find();
  38. if (empty($level)) $level = ['level'=>1, 'level_name'=>'注册会员', 'level_value'=>10];
  39. /* END */
  40. /*更新信息*/
  41. $LevelData = [
  42. 'level' => $level['level_id'],
  43. 'open_level_time' => 0,
  44. 'level_maturity_days' => 0,
  45. 'update_time' => getTime(),
  46. ];
  47. $return = Db::name('users')->where('users_id', $users_id)->update($LevelData);
  48. /* END */
  49. if (!empty($return)) {
  50. $LevelData['level_name'] = $level['level_name'];
  51. $LevelData['level_value'] = $level['level_value'];
  52. return $LevelData;
  53. }
  54. }
  55. return [];
  56. }
  57. // 会员登录之后的业务逻辑
  58. public function loginAfter($users)
  59. {
  60. session('users', $users);
  61. session('users_id', $users['users_id']);
  62. session('users_login_expire', getTime()); // 登录有效期
  63. cookie('users_id', $users['users_id']);
  64. $data = [
  65. // 'last_ip' => clientIP(),
  66. 'last_ip' => getClientIP(),
  67. 'last_login' => getTime(),
  68. 'login_count' => Db::raw('login_count+1'),
  69. ];
  70. Db::name('users')->where('users_id', $users['users_id'])->update($data);
  71. }
  72. }