Authored by Rock Zhang

排除浏览记录中下架的商品

Code Review By Rock Zhang
... ... @@ -301,31 +301,49 @@ class UserModel
$records = UserData::browseRecord($uid, $udid, $page, $limit);
if (!$records) {
$result['walkwayUrl'] = Helpers::url('/product/new');
$result['noRecord'] = true;
return $result;
}
// 处理数据
if (isset($records['data']['product_list'])) {
do {
if (!$records) {
$result['walkwayUrl'] = Helpers::url('/product/new');
$result['noRecord'] = true;
break;
}
if (!isset($records['data']['product_list'])) {
break;
}
// 不能再查到结果了
if ($page == 1 && $records['data']['total'] === 0) {
$result['walkwayUrl'] = Helpers::url('/product/new');
$result['noRecord'] = true;
} else {
$data = $records['data']['product_list'];
foreach ($data as &$val) {
$val['link'] = Helpers::url('/product/show_' . $val['product_skn'] . '.html');
$val['image'] = !empty($val['image']) ? Helpers::getImageUrl($val['image'], 447, 596) : '';
$val['sales_price'] = Helpers::transPrice($val['sales_price']);
$val['market_price'] = ($val['market_price'] - $val['sales_price'] > 0) ? Helpers::transPrice($val['market_price']) : false;
break;
}
$data = $records['data']['product_list'];
$allRecords = array();
$record = array();
foreach ($data as &$val) {
// 排除下架的商品
if ($val['status'] == 0) {
continue;
}
!empty($data) && $result['browseRecord'] = $data;
$record = array();
$record['product_name'] = $val['product_name'];
$record['product_id'] = $val['product_id'];
$record['link'] = Helpers::url('/product/show_' . $val['product_skn'] . '.html');
$record['image'] = !empty($val['image']) ? Helpers::getImageUrl($val['image'], 447, 596) : '';
$record['sales_price'] = Helpers::transPrice($val['sales_price']);
$record['market_price'] = ($val['market_price'] - $val['sales_price'] > 0) ? Helpers::transPrice($val['market_price']) : false;
$record['storage'] = $val['storage'];
$allRecords[] = $record;
}
}
if (!empty($allRecords)) {
$result['browseRecord'] = $allRecords;
}
} while(false);
return $result;
}
... ...