Commit 9bb78f52 authored by zhuwei's avatar zhuwei

获取随机图片

parent 8273e915
......@@ -177,49 +177,29 @@ class ImageDepot extends Basic
* 获取随机图片
* @return \think\Response
*/
public function getImageWidthRand($img_type,$label)
public function getImageWidthRand($img_type=0,$label='商场美食')
{
if($img_type == 0)
{
}elseif($img_type == 1)
{
}else{
$params_['img_status'] = 0;
if (!empty($img_type)) {
$params_['img_type'] = $img_type;
}
//todo 根据条件 查询所有符合要求的记录的ID
if (!empty($params['label'])) {
$params_['label'] = [ 'LIKE', '%' . $params['label'] . '%' ];
if($img_type == 0 or $img_type == 1)
{
if (!empty($label)) {
$params_['label'] = [ 'LIKE', '%' . $label . '%' ];
}
if (!empty($this->params['img_type'])) {
$params_['img_type'] = $params['img_type'];
}
/*$params = array(
"agents_id" => 5740
);*/
/**
`id`
`img_type` '图片类型:0室外图 ,1室内图 ,2人群图',
`label_type` '业态标签:0商场美食、1沿街餐饮、2百货零售、3服饰鞋包、4休闲娱乐、5亲子教育、6百货超市、7办公',
`img_name` '图片名称',
`img_status` '删除状态 0正常 1删除',
`update_time` '更新时间',
`create_time` '创建时间',
*/
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
$field = 'id,img_type,label,img_name,create_time';
$params_['img_status'] = 0;
$result = $this->imageDepot->getImageDepotIDList($params_);
if(!$result){
//TODO 返回一个默认图片
return $result;
}
$random_keys=array_rand($result,1);
$res = $this->imageDepot->getImageDepotList($field,$params_,$pageNo,$pageSize);
$img_file_path= CURRENT_URL . 'static/shop_image_depot/' . $result[$random_keys]['img_name'];
//
return $img_file_path;
}
......
......@@ -49,6 +49,28 @@ class GImageDepot extends Model
return $result;
}
/**
* 查询id集合
*/
public function getImageDepotIDList($params)
{
$field = "id,img_name";
$result = Db::table($this->table)
->field($field)
->where($params)
->select();
if(!$result){
return $result;
}
foreach ($result as $k => $v) {
$result_['id'] = $v['id'];
$result_['img_name'] = $v['img_name'];
$result__[]=$result_;
}
//dump($this->getLastSql());
return $result__;
}
/**
* 查询统计数据
*/
......
......@@ -384,6 +384,7 @@ Route::group('api', [
'getImageDepotList' => [ 'api/ImageDepot/getImageDepotList', [ 'method' => 'get | post' ] ],//获取图片列表
'getImageDepotById' => [ 'api/ImageDepot/getImageDepotById', [ 'method' => 'get | post' ] ],//根据ID获取记录
'delImageDepot' => [ 'api/ImageDepot/delImageDepot', [ 'method' => 'get | post' ] ],//删除
'getImageWidthRand' => [ 'api/ImageDepot/getImageWidthRand', [ 'method' => 'get | post' ] ],//删除
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment