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.

82 lines
1.8 KiB

8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. use Illuminate\Database\Eloquent\Model;
  4. use DB;
  5. class Slide extends Model
  6. {
  7. //轮播图
  8. protected $table = 'slide';
  9. public $timestamps = false;
  10. protected $guarded = []; //$guarded包含你不想被赋值的字段数组。
  11. const UN_SHOW = 0; // 不显示
  12. const IS_SHOW = 1; // 显示
  13. public static function getList(array $param)
  14. {
  15. extract($param); //参数:group_id,limit,offset
  16. $limit = isset($limit) ? $limit : 10;
  17. $offset = isset($offset) ? $offset : 0;
  18. $where['is_show'] = self::IS_SHOW;
  19. $model = new Slide;
  20. if(isset($group_id)){$where['group_id'] = $group_id;}
  21. if($where){$model = $model->where($where);}
  22. $res['count'] = $model->count();
  23. $res['list'] = array();
  24. if($res['count']>0)
  25. {
  26. $res['list'] = $model->orderBy('id', 'desc')->skip($offset)->take($limit)->get()->toArray();
  27. }
  28. else
  29. {
  30. return false;
  31. }
  32. return $res;
  33. }
  34. public static function getOne($id)
  35. {
  36. return self::where('id', $id)->first()->toArray();
  37. }
  38. public static function add(array $data)
  39. {
  40. if ($id = DB::table(self::$table)->insertGetId($data))
  41. {
  42. return $id;
  43. }
  44. return false;
  45. }
  46. public static function modify($where, array $data)
  47. {
  48. $slide = DB::table(self::$table);
  49. if ($slide->where($where)->update($data))
  50. {
  51. return true;
  52. }
  53. return false;
  54. }
  55. //删除一条记录
  56. public static function remove($id)
  57. {
  58. if (!self::whereIn('id', explode(',', $id))->delete())
  59. {
  60. return false;
  61. }
  62. return true;
  63. }
  64. }