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

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