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.

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