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.

80 lines
1.6 KiB

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