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.

111 lines
2.8 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
  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. if($res['list'])
  30. {
  31. foreach($res['list'] as $k=>$v)
  32. {
  33. $goods = Goods::getOne(array('id'=>$v['goods_id'],'field'=>array('id', 'typeid', 'tuijian', 'click', 'title', 'sn', 'price','litpic', 'pubdate', 'add_time', 'market_price', 'goods_number', 'sale', 'comments','promote_start_date','promote_price','promote_end_date','goods_img','spec','point')));
  34. $res['list'][$k]['goods'] = $goods;
  35. }
  36. }
  37. }
  38. else
  39. {
  40. return false;
  41. }
  42. return $res;
  43. }
  44. public static function getOne(array $param)
  45. {
  46. extract($param); //参数
  47. $where['id'] = $id;
  48. return self::where($where)->first();
  49. }
  50. public static function add(array $data)
  51. {
  52. if(self::where($data)->first()){return false;}
  53. if (!self::where($data)->first())
  54. {
  55. $data['add_time'] = time();
  56. return self::insertGetId($data);
  57. }
  58. return false;
  59. }
  60. public static function modify($where, array $data)
  61. {
  62. if (self::where($where)->update($data) !== false)
  63. {
  64. return true;
  65. }
  66. return false;
  67. }
  68. //删除一条记录
  69. public static function remove($id,$user_id)
  70. {
  71. if (self::whereIn('id', explode(',', $id))->where('user_id',$user_id)->delete() === false)
  72. {
  73. return false;
  74. }
  75. return true;
  76. }
  77. //清空我的足迹
  78. public static function clear($user_id)
  79. {
  80. if (self::where('user_id',$user_id)->delete() === false)
  81. {
  82. return false;
  83. }
  84. return true;
  85. }
  86. }