|
|
@ -1,87 +1,176 @@ |
|
|
|
<?php |
|
|
|
namespace App\Http\Model; |
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
use DB; |
|
|
|
|
|
|
|
class Slide extends Model |
|
|
|
class Slide extends BaseModel |
|
|
|
{ |
|
|
|
//轮播图
|
|
|
|
|
|
|
|
protected $table = 'slide'; |
|
|
|
const TABLE_NAME = 'slide'; |
|
|
|
|
|
|
|
public $timestamps = false; |
|
|
|
protected $guarded = []; //$guarded包含你不想被赋值的字段数组。
|
|
|
|
|
|
|
|
const UN_SHOW = 1; // 不显示
|
|
|
|
const IS_SHOW = 0; // 显示
|
|
|
|
|
|
|
|
public static function getList(array $param) |
|
|
|
|
|
|
|
public static function getDb() |
|
|
|
{ |
|
|
|
extract($param); //参数:group_id,limit,offset
|
|
|
|
|
|
|
|
$limit = isset($limit) ? $limit : 10; |
|
|
|
$offset = isset($offset) ? $offset : 0; |
|
|
|
|
|
|
|
$where['is_show'] = self::IS_SHOW; |
|
|
|
$model = new Slide; |
|
|
|
|
|
|
|
if(isset($group_id)){$where['group_id'] = $group_id;} |
|
|
|
if(isset($type)){$where['type'] = $type;} |
|
|
|
|
|
|
|
return DB::table(self::TABLE_NAME); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 列表 |
|
|
|
* @param array $where 查询条件 |
|
|
|
* @param string $order 排序 |
|
|
|
* @param string $field 字段 |
|
|
|
* @param int $offset 偏移量 |
|
|
|
* @param int $limit 取多少条 |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public static function getList($where = array(), $order = '', $field = '*', $offset = 0, $limit = 10) |
|
|
|
{ |
|
|
|
$model = self::getDb(); |
|
|
|
if($where){$model = $model->where($where);} |
|
|
|
|
|
|
|
|
|
|
|
$res['count'] = $model->count(); |
|
|
|
$res['list'] = array(); |
|
|
|
|
|
|
|
if($res['count']>0) |
|
|
|
{ |
|
|
|
$res['list'] = $model->orderBy('id', 'desc')->skip($offset)->take($limit)->get()->toArray(); |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
if($res['count'] > 0) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
if($field){if(is_array($field)){$model = $model->select($field);}else{$model = $model->select(\DB::raw($field));}} |
|
|
|
if($order){$model = parent::getOrderByData($model, $order);} |
|
|
|
if($offset){}else{$offset = 0;} |
|
|
|
if($limit){}else{$limit = 10;} |
|
|
|
|
|
|
|
$res['list'] = $model->skip($offset)->take($limit)->get(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $res; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 分页,用于前端html输出 |
|
|
|
* @param array $where 查询条件 |
|
|
|
* @param string $order 排序 |
|
|
|
* @param string $field 字段 |
|
|
|
* @param int $limit 每页几条 |
|
|
|
* @param int $page 当前第几页 |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public static function getPaginate($where = array(), $order = '', $field = '*', $limit = '') |
|
|
|
{ |
|
|
|
$res = self::getDb(); |
|
|
|
|
|
|
|
if($where){$res = $res->where($where);} |
|
|
|
if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} |
|
|
|
if($order){$res = parent::getOrderByData($res, $order);} |
|
|
|
if($limit){}else{$limit = 10;} |
|
|
|
|
|
|
|
return $res->paginate($limit); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询全部 |
|
|
|
* @param array $where 查询条件 |
|
|
|
* @param string $order 排序 |
|
|
|
* @param string $field 字段 |
|
|
|
* @param int $limit 取多少条 |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public static function getAll($where = array(), $order = '', $field = '*', $limit = 10, $offset = 0) |
|
|
|
{ |
|
|
|
$res = self::getDb(); |
|
|
|
|
|
|
|
if($where){$res = $res->where($where);} |
|
|
|
if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} |
|
|
|
if($order){$res = parent::getOrderByData($res, $order);} |
|
|
|
if($offset){}else{$offset = 0;} |
|
|
|
if($limit){}else{$limit = 10;} |
|
|
|
|
|
|
|
$res = $res->skip($offset)->take($limit)->get(); |
|
|
|
|
|
|
|
return $res; |
|
|
|
} |
|
|
|
|
|
|
|
public static function getOne($id) |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取一条 |
|
|
|
* @param array $where 条件 |
|
|
|
* @param string $field 字段 |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public static function getOne($where, $field = '*') |
|
|
|
{ |
|
|
|
return self::where('id', $id)->first()->toArray(); |
|
|
|
$res = self::getDb(); |
|
|
|
|
|
|
|
if($where){$res = $res->where($where);} |
|
|
|
if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} |
|
|
|
|
|
|
|
$res = $res->first(); |
|
|
|
|
|
|
|
return $res; |
|
|
|
} |
|
|
|
|
|
|
|
public static function add(array $data) |
|
|
|
|
|
|
|
/** |
|
|
|
* 添加 |
|
|
|
* @param array $data 数据 |
|
|
|
* @return int |
|
|
|
*/ |
|
|
|
public static function add(array $data,$type = 0) |
|
|
|
{ |
|
|
|
if ($id = DB::table(self::$table)->insertGetId($data)) |
|
|
|
if($type==0) |
|
|
|
{ |
|
|
|
return $id; |
|
|
|
// 新增单条数据并返回主键值
|
|
|
|
return self::insertGetId(parent::filterTableColumn($data,self::TABLE_NAME)); |
|
|
|
} |
|
|
|
elseif($type==1) |
|
|
|
{ |
|
|
|
/** |
|
|
|
* 添加单条数据 |
|
|
|
* $data = ['foo' => 'bar', 'bar' => 'foo']; |
|
|
|
* 添加多条数据 |
|
|
|
* $data = [ |
|
|
|
* ['foo' => 'bar', 'bar' => 'foo'], |
|
|
|
* ['foo' => 'bar1', 'bar' => 'foo1'], |
|
|
|
* ['foo' => 'bar2', 'bar' => 'foo2'] |
|
|
|
* ]; |
|
|
|
*/ |
|
|
|
return self::insert($data); |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public static function modify($where, array $data) |
|
|
|
|
|
|
|
/** |
|
|
|
* 修改 |
|
|
|
* @param array $data 数据 |
|
|
|
* @param array $where 条件 |
|
|
|
* @return bool |
|
|
|
*/ |
|
|
|
public static function edit($data, $where = array()) |
|
|
|
{ |
|
|
|
$slide = DB::table(self::$table); |
|
|
|
if ($slide->where($where)->update($data)) |
|
|
|
if (self::where($where)->update(parent::filterTableColumn($data, self::TABLE_NAME)) !== false) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 删除 |
|
|
|
* @param array $where 条件 |
|
|
|
* @return bool |
|
|
|
*/ |
|
|
|
public static function del($where) |
|
|
|
{ |
|
|
|
return self::where($where)->delete(); |
|
|
|
} |
|
|
|
|
|
|
|
//删除一条记录
|
|
|
|
public static function remove($id) |
|
|
|
{ |
|
|
|
if (!self::whereIn('id', explode(',', $id))->delete()) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
return self::whereIn('id', explode(',', $id))->delete(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//获取显示平台文字:0pc,1weixin,2app,3wap
|
|
|
|
public static function getTypeText($where) |
|
|
|
{ |
|
|
|