心理咨询网
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.

MemberModel.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * @copyright (C)2016-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2020年06月26日
  7. * 会员前台模型
  8. */
  9. namespace app\home\model;
  10. use core\basic\Model;
  11. use core\basic\Config;
  12. class MemberModel extends Model
  13. {
  14. // 会员登录
  15. public function login($where)
  16. {
  17. $field = array(
  18. 'a.id',
  19. 'a.ucode',
  20. 'a.username',
  21. 'a.useremail',
  22. 'a.usermobile',
  23. 'a.gid',
  24. 'a.status',
  25. 'b.gcode',
  26. 'b.gname'
  27. );
  28. $join = array(
  29. 'ay_member_group b',
  30. 'a.gid=b.id',
  31. 'LEFT'
  32. );
  33. if (! ! $user = parent::table('ay_member a')->field($field)
  34. ->join($join)
  35. ->where($where)
  36. ->find()) {
  37. $data = array(
  38. 'login_count' => '+=1',
  39. 'last_login_ip' => ip2long(get_user_ip()),
  40. 'last_login_time' => get_datetime()
  41. );
  42. // 登录积分
  43. $score = Config::get('login_score') ?: 0;
  44. if (is_numeric($score) && $score > 0) {
  45. $data['score'] = '+=' . $score;
  46. }
  47. // 更新登录信息
  48. parent::table('ay_member')->where('id=' . $user->id)->update($data);
  49. }
  50. return $user;
  51. }
  52. // 会员注册
  53. public function register($data)
  54. {
  55. return parent::table('ay_member')->insert($data);
  56. }
  57. // 检查会员名称
  58. public function checkUsername($where)
  59. {
  60. return parent::table('ay_member')->where($where)->find();
  61. }
  62. // 读取会员字段
  63. public function getField()
  64. {
  65. return parent::table('ay_member_field')->field('name,description,required')
  66. ->where('status=1')
  67. ->order('sorting,id')
  68. ->select();
  69. }
  70. // 获取最后一个code
  71. public function getLastUcode()
  72. {
  73. return parent::table('ay_member')->order('id DESC')->value('ucode');
  74. }
  75. // 获取当前会员信息
  76. public function getUser()
  77. {
  78. $field = array(
  79. 'a.*',
  80. 'b.gcode',
  81. 'b.gname'
  82. );
  83. $join = array(
  84. 'ay_member_group b',
  85. 'a.gid=b.id',
  86. 'LEFT'
  87. );
  88. return parent::table('ay_member a')->field($field)
  89. ->join($join)
  90. ->where("a.id='" . session('pboot_uid') . "'")
  91. ->find();
  92. }
  93. // 修改会员资料
  94. public function modUser($data)
  95. {
  96. return parent::table('ay_member')->where("id='" . session('pboot_uid') . "'")->update($data);
  97. }
  98. // 获取第一个等级
  99. public function getFirstGroup()
  100. {
  101. return parent::table('ay_member_group')->order('gcode asc')->find();
  102. }
  103. // 获取等级ID
  104. public function getGroupID($gcode)
  105. {
  106. return parent::table('ay_member_group')->where("gcode='$gcode'")->value('id');
  107. }
  108. //未登录状态下找回密码
  109. public function updatePassword($where,$data){
  110. return parent::table('ay_member')->where($where)->update($data);
  111. }
  112. public function getImage()
  113. {
  114. return parent::table('ay_member')->column('headpic');
  115. }
  116. }