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.

99 lines
2.1 KiB

8 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. class UserGoodsHistory extends BaseModel
  4. {
  5. //用户优惠券
  6. protected $table = 'user_goods_history';
  7. public $timestamps = false;
  8. /**
  9. * 不能被批量赋值的属性
  10. *
  11. * @var array
  12. */
  13. protected $guarded = [];
  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 UserGoodsHistory;
  21. if(isset($user_id)){$where['user_id'] = $user_id;}
  22. if(isset($goods_id)){$where['goods_id'] = $goods_id;}
  23. if(isset($where)){$model = $model->where($where);}
  24. $res['count'] = $model->count();
  25. $res['list'] = array();
  26. if($res['count']>0)
  27. {
  28. $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get();
  29. }
  30. else
  31. {
  32. return false;
  33. }
  34. return $res;
  35. }
  36. public static function getOne(array $param)
  37. {
  38. extract($param); //参数
  39. $where['id'] = $id;
  40. return self::where($where)->first();
  41. }
  42. public static function add(array $data)
  43. {
  44. if (!self::where($data)->first())
  45. {
  46. $data['add_time'] = time();
  47. return self::insertGetId($data);
  48. }
  49. return false;
  50. }
  51. public static function modify($where, array $data)
  52. {
  53. if (self::where($where)->update($data) !== false)
  54. {
  55. return true;
  56. }
  57. return false;
  58. }
  59. //删除一条记录
  60. public static function remove($id)
  61. {
  62. if (self::whereIn('id', explode(',', $id))->delete() === false)
  63. {
  64. return false;
  65. }
  66. return true;
  67. }
  68. //清空我的足迹
  69. public static function clear($user_id)
  70. {
  71. if (self::where('user_id',$user_id)->delete() === false)
  72. {
  73. return false;
  74. }
  75. return true;
  76. }
  77. }