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.

86 lines
1.9 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 Bonus extends BaseModel
  4. {
  5. //优惠券
  6. protected $table = 'bonus';
  7. public $timestamps = false;
  8. /**
  9. * 不能被批量赋值的属性
  10. *
  11. * @var array
  12. */
  13. protected $guarded = [];
  14. const STATUS = 0; // 优惠券可以
  15. //获取列表
  16. public static function getList(array $param)
  17. {
  18. extract($param); //参数:limit,offset
  19. $limit = isset($limit) ? $limit : 10;
  20. $offset = isset($offset) ? $offset : 0;
  21. $where['status'] = self::STATUS;
  22. $model = new Bonus;
  23. $model = $model->where($where);
  24. $model = $model->where(function ($query) {
  25. $query->where('num', '=', -1)->orWhere('num', '>', 0);
  26. });
  27. $model = $model->where(function ($query) {
  28. $query->where('start_time', '<', date('Y-m-d H:i:s'))->where('end_time', '>', date('Y-m-d H:i:s'));
  29. });
  30. $res['count'] = $model->count();
  31. $res['list'] = array();
  32. if($res['count']>0)
  33. {
  34. $res['list'] = $model->skip($offset)->take($limit)->orderBy('money','desc')->get();
  35. }
  36. return $res;
  37. }
  38. public static function getOne($id)
  39. {
  40. return self::where('id', $id)->first();
  41. }
  42. public static function add(array $data)
  43. {
  44. if ($id = self::insertGetId($data))
  45. {
  46. return true;
  47. }
  48. return false;
  49. }
  50. public static function modify($where, array $data)
  51. {
  52. if (self::where($where)->update($data)!==false)
  53. {
  54. return true;
  55. }
  56. return false;
  57. }
  58. //删除一条记录
  59. public static function remove($id)
  60. {
  61. if (!self::whereIn('id', explode(',', $id))->delete())
  62. {
  63. return false;
  64. }
  65. return true;
  66. }
  67. }