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.

93 lines
2.1 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 UserBonus extends BaseModel
  4. {
  5. //用户优惠券
  6. protected $table = 'user_bonus';
  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. $where['user_id'] = $user_id;
  19. $limit = isset($limit) ? $limit : 10;
  20. $offset = isset($offset) ? $offset : 0;
  21. $model = new UserBonus;
  22. if(isset($status)){$where['status'] = $status;}
  23. $model = $model->where($where);
  24. $res['count'] = $model->count();
  25. $res['list'] = array();
  26. if($res['count']>0)
  27. {
  28. $bonus_list = $model->skip($offset)->take($limit)->orderBy('id','desc')->get();
  29. foreach($bonus_list as $k=>$v)
  30. {
  31. $bonus_list[$k]->bonus = Bonus::where('id',$v->bonus_id)->first();
  32. }
  33. $res['list'] = $bonus_list;
  34. }
  35. else
  36. {
  37. return false;
  38. }
  39. return $res;
  40. }
  41. public static function getOne($where)
  42. {
  43. $res = self::where($where)->first();
  44. if($res){$res->bonus = Bonus::where('id',$res->bonus_id)->first();}
  45. return $res;
  46. }
  47. public static function add(array $data)
  48. {
  49. if(self::where(['bonus_id'=>$data['bonus_id'],'user_id'=>$data['user_id']])->first()){return '亲,您已获取!';}
  50. if ($id = self::insertGetId($data))
  51. {
  52. return $id;
  53. }
  54. return false;
  55. }
  56. public static function modify($where, array $data)
  57. {
  58. if (self::where($where)->update($data))
  59. {
  60. return true;
  61. }
  62. return false;
  63. }
  64. //删除一条记录
  65. public static function remove($id)
  66. {
  67. if (!self::whereIn('id', explode(',', $id))->delete())
  68. {
  69. return false;
  70. }
  71. return true;
  72. }
  73. }