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.

109 lines
2.7 KiB

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())
  53. {
  54. $data['add_time'] = time();
  55. return self::insertGetId($data);
  56. }
  57. return false;
  58. }
  59. public static function modify($where, array $data)
  60. {
  61. if (self::where($where)->update($data) !== false)
  62. {
  63. return true;
  64. }
  65. return false;
  66. }
  67. //删除一条记录
  68. public static function remove($id,$user_id)
  69. {
  70. if (self::whereIn('id', explode(',', $id))->where('user_id',$user_id)->delete() === false)
  71. {
  72. return false;
  73. }
  74. return true;
  75. }
  76. //清空我的足迹
  77. public static function clear($user_id)
  78. {
  79. if (self::where('user_id',$user_id)->delete() === false)
  80. {
  81. return false;
  82. }
  83. return true;
  84. }
  85. }