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.

119 lines
2.9 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. use App\Common\Token;
  4. class User extends BaseModel
  5. {
  6. //用户模型
  7. protected $table = 'user';
  8. public $timestamps = false;
  9. /**
  10. * 不能被批量赋值的属性
  11. *
  12. * @var array
  13. */
  14. protected $guarded = [];
  15. protected $hidden = ['password'];
  16. /**
  17. * 获取关联到用户的角色
  18. */
  19. public function userrole()
  20. {
  21. return $this->belongsTo(UserRole::class, 'role_id', 'id');
  22. }
  23. //签到
  24. public static function signin()
  25. {
  26. $user = self::where(['id'=>Token::$uid])->first();
  27. $signin_time='';
  28. if(!empty($user->signin_time)){$signin_time = date('Ymd',strtotime($user->signin_time));} //签到时间
  29. $today = date('Ymd',time()); //今日日期
  30. if($signin_time==$today){return '今日已签到!';}
  31. $signin_point = (int)Sysconfig::where(['varname'=>'CMS_SIGN_POINT'])->value('value'); //签到积分
  32. User::where(['id'=>Token::$uid])->update(['point'=>($user->point+$signin_point),'signin_time'=>date('Y-m-d H:i:s')]); //更新用户积分,及签到时间
  33. UserPoint::insert(['type'=>1,'point'=>$signin_point,'des'=>'签到','user_id'=>Token::$uid]); //添加签到积分记录
  34. return true;
  35. }
  36. //获取列表
  37. public static function getList(array $param)
  38. {
  39. extract($param); //参数:limit,offset
  40. $where = '';
  41. $limit = isset($limit) ? $limit : 10;
  42. $offset = isset($offset) ? $offset : 0;
  43. $model = new User;
  44. if(isset($group_id)){$where['group_id'] = $group_id;}
  45. if($where != '')
  46. {
  47. $model = $model->where($where);
  48. }
  49. $res['count'] = $model->count();
  50. $res['list'] = array();
  51. if($res['count']>0)
  52. {
  53. $res['list'] = $model->select('id','user_name','email','sex','money','point','mobile','nickname','add_time')->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray();
  54. }
  55. else
  56. {
  57. return false;
  58. }
  59. return $res;
  60. }
  61. //用户信息
  62. public static function getOne($id)
  63. {
  64. $user = self::where('id', $id)->first();
  65. if(!$user){return false;}
  66. $user['reciever_address'] = UserAddress::getOne($user->address_id);
  67. return $user;
  68. }
  69. public static function add(array $data)
  70. {
  71. if ($id = self::insertGetId($data))
  72. {
  73. return $id;
  74. }
  75. return false;
  76. }
  77. public static function modify($where, array $data)
  78. {
  79. if (self::where($where)->update($data))
  80. {
  81. return true;
  82. }
  83. return false;
  84. }
  85. //删除一条记录
  86. public static function remove($id)
  87. {
  88. if (!self::whereIn('id', explode(',', $id))->delete())
  89. {
  90. return false;
  91. }
  92. return true;
  93. }
  94. }