feat/task1-c-wallet
gongfuxiang 2018-09-08 15:35:18 +08:00
parent 60d76d07a5
commit 6b4c67eaf6
5 changed files with 44 additions and 18 deletions

View File

@ -85,8 +85,15 @@ class SearchController extends CommonController
public function GoodsList()
{
$data = SearchService::GoodsList($this->params);
$msg = empty($data['data']) ? L('common_not_data_tips') : L('common_operation_success');
$this->ajaxReturn($msg, 0, $data);
if(empty($data['data']))
{
$msg = L('common_not_data_tips');
$code = -100;
} else {
$msg = L('common_operation_success');
$code = 0;
}
$this->ajaxReturn($msg, $code, $data);
}
}
?>

View File

@ -105,7 +105,10 @@
<ul class="am-avg-sm-2 am-avg-md-3 am-avg-lg-5 data-list"></ul>
</div>
<!--分页 -->
<!-- 没有数据 -->
<div class="table-no" style="display:none;"><i class="am-icon-warning"></i> {{:L('common_not_data_tips')}}</div>
<!-- 分页 -->
<button type="button" class="am-btn am-btn-default am-btn-block search-pages-submit" data-url="{{:U('Home/Search/GoodsList')}}">加载更多 <i class="am-icon-angle-double-down"></i></button>
</div>
</div>

View File

@ -14,7 +14,7 @@ use Service\GoodsService;
class SearchService
{
/**
* 根据分类id获取级列表
* 根据分类id获取级列表
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
@ -24,9 +24,6 @@ class SearchService
*/
public static function GoodsCategoryList($params = [])
{
// 根据分类id获取同级列表
// $category = GoodsService::GoodsCategoryRow(['id'=>$params['category_id']]);
// $pid = empty($category['pid']) ? 0 : $category['pid'];
return GoodsService::GoodsCategoryList(['pid'=>$params['category_id']]);
}
@ -61,15 +58,21 @@ class SearchService
'total' => 450,
'data' => [],
];
$goods_where = [
$where = [
'g.is_delete_time' => 0,
'g.is_shelves' => 1,
];
// 关键字
if(!empty($params['keywords']))
{
$where['g.title'] = ['like', '%'.$params['keywords'].'%'];
}
// 品牌
if(!empty($params['brand_id']))
{
$goods_where['g.brand_id'] = intval($params['brand_id']);
$where['g.brand_id'] = intval($params['brand_id']);
}
// 分类id
@ -77,7 +80,7 @@ class SearchService
{
$category_ids = GoodsService::GoodsCategoryItemsIds(['category_id'=>$params['category_id']]);
$category_ids[] = $params['category_id'];
$goods_where['gci.id'] = ['in', $category_ids];
$where['gci.id'] = ['in', $category_ids];
}
// 筛选价格
@ -86,21 +89,21 @@ class SearchService
$price = M('ScreeningPrice')->field('min_price,max_price')->where(['is_enable'=>1, 'id'=>intval($params['screening_price_id'])])->find();
if(!empty($price['min_price']) && !empty($price['max_price']))
{
$goods_where['g.price'] = [
$where['g.price'] = [
['EGT', $price['min_price']],
['LT', $price['max_price']],
];
} else if(!empty($price['min_price']))
{
$goods_where['g.price'] = ['EGT', $price['min_price']];
$where['g.price'] = ['EGT', $price['min_price']];
} else if(!empty($price['max_price']))
{
$goods_where['g.price'] = ['LT', $price['max_price']];
$where['g.price'] = ['LT', $price['max_price']];
}
}
// 获取商品总数
$result['total'] = GoodsService::GoodsTotal(['where'=>$goods_where]);
$result['total'] = GoodsService::GoodsTotal(['where'=>$where]);
// 获取商品列表
if($result['total'] > 0)
@ -108,8 +111,7 @@ class SearchService
$page = intval(I('page', 1));
$n = 10;
$m = intval(($page-1)*$n);
$result['data'] = GoodsService::GoodsList(['where'=>$goods_where, 'm'=>$m, 'n'=>$n]);
$result['data'] = GoodsService::GoodsList(['where'=>$where, 'm'=>$m, 'n'=>$n]);
$result['page_total'] = ceil($result['total']/$n);
}
return $result;

View File

@ -1,5 +1,5 @@
/* 没数据 */
.table-no {text-align:center;padding-top:30px !important;background:#FFF !important;}
.table-no {text-align:center;padding-top:30px !important;background:#FFF !important; color: #888; }
/* 公共dl样式 */
.dl-content dt { float: left; padding-left: 5px; overflow: hidden; clear: left;

View File

@ -143,7 +143,7 @@ $(function()
data:data,
success:function(result)
{
if(result.code == 0 && result.data.data.length > 0)
if(result.code == 0)
{
for(var i in result.data.data)
{
@ -161,6 +161,20 @@ $(function()
$('.data-list').append(html);
}
$('.search-pages-submit').attr('data-page', data.page+1);
$('.search-pages-submit').attr('disabled', (result.data.page_total <= 1));
$('.search-pages-submit').show();
$('.table-no').hide();
} else if(result.code == -100) {
if($('.data-list li').length == 0)
{
$('.table-no').show();
$('.search-pages-submit').hide();
} else {
$('.table-no').hide();
$('.search-pages-submit').show();
$('.search-pages-submit').attr('disabled', true);
}
Prompt(result.msg);
} else {
Prompt(result.msg);
}