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.

107 lines
2.4 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
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. 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 = 1; // 不显示
  12. const IS_SHOW = 0; // 显示
  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(isset($type)){$where['type'] = $type;}
  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. //获取显示平台文字:0pc,1weixin,2app,3wap
  66. public static function getTypeText($where)
  67. {
  68. $res = '';
  69. if($where['type'] === 0)
  70. {
  71. $res = 'pc';
  72. }
  73. elseif($where['type'] === 1)
  74. {
  75. $res = 'weixin';
  76. }
  77. elseif($where['type'] === 2)
  78. {
  79. $res = 'app';
  80. }
  81. elseif($where['type'] === 3)
  82. {
  83. $res = 'wap';
  84. }
  85. return $res;
  86. }
  87. }