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.

83 lines
1.8 KiB

7 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. class UserMessage extends BaseModel
  4. {
  5. //用户消息
  6. protected $table = 'user_message';
  7. public $timestamps = false;
  8. /**
  9. * 不能被批量赋值的属性
  10. *
  11. * @var array
  12. */
  13. protected $guarded = array();
  14. //获取列表
  15. public static function getList(array $param)
  16. {
  17. extract($param); //参数:limit,offset
  18. $limit = isset($limit) ? $limit : 10;
  19. $offset = isset($offset) ? $offset : 0;
  20. $model = new self;
  21. if(isset($type)){$where['type'] = $type;}
  22. if(isset($status)){$where['status'] = $status;}
  23. $model = $model->whereIn('user_id',array(0,$user_id));
  24. if(isset($where)){$model = $model->where($where);}
  25. $res['count'] = $model->count();
  26. $res['list'] = array();
  27. if($res['count']>0)
  28. {
  29. $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get();
  30. }
  31. else
  32. {
  33. return false;
  34. }
  35. return $res;
  36. }
  37. public static function getOne($where)
  38. {
  39. return self::where($where)->first();
  40. }
  41. public static function add(array $data)
  42. {
  43. if ($id = self::insertGetId($data))
  44. {
  45. return $id;
  46. }
  47. return false;
  48. }
  49. public static function modify($where, array $data)
  50. {
  51. if (self::where($where)->update($data))
  52. {
  53. return true;
  54. }
  55. return false;
  56. }
  57. //删除一条记录
  58. public static function remove($id)
  59. {
  60. if (!self::whereIn('id', explode(',', $id))->delete())
  61. {
  62. return false;
  63. }
  64. return true;
  65. }
  66. }