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.

186 lines
5.3 KiB

8 years ago
4 years ago
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
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
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
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
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
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
7 years ago
7 years ago
6 years ago
8 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. use Illuminate\Support\Facades\DB;
  4. use Illuminate\Support\Facades\Log;
  5. class Slide extends BaseModel
  6. {
  7. //轮播图
  8. protected $table = 'slide';
  9. public $timestamps = false;
  10. protected $hidden = array();
  11. protected $guarded = array(); //$guarded包含你不想被赋值的字段数组。
  12. const UN_SHOW = 1; // 不显示
  13. const IS_SHOW = 0; // 显示
  14. public function getDb()
  15. {
  16. return DB::table($this->table);
  17. }
  18. /**
  19. * 列表
  20. * @param array $where 查询条件
  21. * @param string $order 排序
  22. * @param string $field 字段
  23. * @param int $offset 偏移量
  24. * @param int $limit 取多少条
  25. * @return array
  26. */
  27. public function getList($where = array(), $order = '', $field = '*', $offset = 0, $limit = 15)
  28. {
  29. $model = $this->getDb();
  30. if($where){$model = $model->where($where);}
  31. $res['count'] = $model->count();
  32. $res['list'] = array();
  33. if($res['count'] > 0)
  34. {
  35. if($field){if(is_array($field)){$model = $model->select($field);}else{$model = $model->select(\DB::raw($field));}}
  36. if($order){$model = parent::getOrderByData($model, $order);}
  37. if($offset){}else{$offset = 0;}
  38. if($limit){}else{$limit = 15;}
  39. $res['list'] = $model->skip($offset)->take($limit)->get();
  40. }
  41. return $res;
  42. }
  43. /**
  44. * 分页,用于前端html输出
  45. * @param array $where 查询条件
  46. * @param string $order 排序
  47. * @param string $field 字段
  48. * @param int $limit 每页几条
  49. * @param int $page 当前第几页
  50. * @return array
  51. */
  52. public function getPaginate($where = array(), $order = '', $field = '*', $limit = 15)
  53. {
  54. $res = $this->getDb();
  55. if($where){$res = $res->where($where);}
  56. if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
  57. if($order){$res = parent::getOrderByData($res, $order);}
  58. if($limit){}else{$limit = 15;}
  59. return $res->paginate($limit);
  60. }
  61. /**
  62. * 查询全部
  63. * @param array $where 查询条件
  64. * @param string $order 排序
  65. * @param string $field 字段
  66. * @param int $limit 取多少条
  67. * @return array
  68. */
  69. public function getAll($where = array(), $order = '', $field = '*', $limit = '', $offset = '')
  70. {
  71. $res = $this->getDb();
  72. if($where){$res = $res->where($where);}
  73. if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
  74. if($order){$res = parent::getOrderByData($res, $order);}
  75. if($offset){$res = $res->skip($offset);}
  76. if($limit){$res = $res->take($limit);}
  77. $res = $res->get();
  78. return $res;
  79. }
  80. /**
  81. * 获取一条
  82. * @param array $where 条件
  83. * @param string $field 字段
  84. * @return array
  85. */
  86. public function getOne($where, $field = '*')
  87. {
  88. $res = $this->getDb();
  89. if($where){$res = $res->where($where);}
  90. if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}}
  91. $res = $res->first();
  92. return $res;
  93. }
  94. /**
  95. * 添加
  96. * @param array $data 数据
  97. * @return int
  98. */
  99. public function add(array $data,$type = 0)
  100. {
  101. if($type==0)
  102. {
  103. // 新增单条数据并返回主键值
  104. return self::insertGetId(parent::filterTableColumn($data,$this->table));
  105. }
  106. elseif($type==1)
  107. {
  108. /**
  109. * 添加单条数据
  110. * $data = ['foo' => 'bar', 'bar' => 'foo'];
  111. * 添加多条数据
  112. * $data = [
  113. * ['foo' => 'bar', 'bar' => 'foo'],
  114. * ['foo' => 'bar1', 'bar' => 'foo1'],
  115. * ['foo' => 'bar2', 'bar' => 'foo2']
  116. * ];
  117. */
  118. return self::insert($data);
  119. }
  120. }
  121. /**
  122. * 修改
  123. * @param array $data 数据
  124. * @param array $where 条件
  125. * @return int
  126. */
  127. public function edit($data, $where = array())
  128. {
  129. $res = $this->getDb();
  130. return $res->where($where)->update(parent::filterTableColumn($data, $this->table));
  131. }
  132. /**
  133. * 删除
  134. * @param array $where 条件
  135. * @return bool
  136. */
  137. public function del($where)
  138. {
  139. $res = $this->getDb();
  140. $res = $res->where($where)->delete();
  141. return $res;
  142. }
  143. //获取显示平台文字:0pc,1weixin,2app,3wap
  144. public function getTypeAttr($data)
  145. {
  146. $arr = array(0 => 'pc', 1 => 'weixin', 2 => 'app', 3 => 'wap');
  147. return $arr[$data->type];
  148. }
  149. //是否显示,默认0显示
  150. public function getIsShowAttr($data)
  151. {
  152. $arr = array(0 => '显示', 1 => '隐藏');
  153. return $arr[$data->is_show];
  154. }
  155. //跳转方式,0_blank,1_self,2_parent,3_top,4framename
  156. public function getTargetAttr($data)
  157. {
  158. $arr = array(0 => '_blank', 1 => '_self', 2 => '_parent', 3 => '_top', 4 => 'framename');
  159. return $arr[$data->target];
  160. }
  161. }