提出价格处理函数;修改获取优惠券接口,能单独返回总数
Showing
2 changed files
with
21 additions
and
4 deletions
@@ -155,8 +155,6 @@ class Helpers | @@ -155,8 +155,6 @@ class Helpers | ||
155 | */ | 155 | */ |
156 | public static function transOrder($order, $type) | 156 | public static function transOrder($order, $type) |
157 | { | 157 | { |
158 | - $result = ''; | ||
159 | - | ||
160 | switch ($type) { | 158 | switch ($type) { |
161 | case 'price': | 159 | case 'price': |
162 | $result = ($order == 0) ? 's_p_desc' : 's_p_asc'; | 160 | $result = ($order == 0) ? 's_p_desc' : 's_p_asc'; |
@@ -173,6 +171,17 @@ class Helpers | @@ -173,6 +171,17 @@ class Helpers | ||
173 | return $result; | 171 | return $result; |
174 | } | 172 | } |
175 | 173 | ||
174 | + /** | ||
175 | + * 转换价格 | ||
176 | + * | ||
177 | + * @param float|string $price 价格 | ||
178 | + * @return float|string 转换之后的价格 | ||
179 | + */ | ||
180 | + public static function transPrice($price) | ||
181 | + { | ||
182 | + return (!empty($price) && !is_float($price)) ? $price . '.00' : $price; | ||
183 | + } | ||
184 | + | ||
176 | /** | 185 | /** |
177 | * 格式化商品信息 | 186 | * 格式化商品信息 |
178 | * | 187 | * |
@@ -322,7 +322,7 @@ class UserModel | @@ -322,7 +322,7 @@ class UserModel | ||
322 | foreach ($data as &$val) { | 322 | foreach ($data as &$val) { |
323 | $val['link'] = isset($val['goodsId']) ? Helpers::url('/product/pro_' . $val['product_skn'] . '_' . $val['goodsId'] . '/' . $val['cnAlphabet'] . '.html') : ''; | 323 | $val['link'] = isset($val['goodsId']) ? Helpers::url('/product/pro_' . $val['product_skn'] . '_' . $val['goodsId'] . '/' . $val['cnAlphabet'] . '.html') : ''; |
324 | $val['image'] = !empty($val['image']) ? Helpers::getImageUrl($val['image'], 447, 596) : ''; | 324 | $val['image'] = !empty($val['image']) ? Helpers::getImageUrl($val['image'], 447, 596) : ''; |
325 | - $val['sales_price'] = (!empty($val['sales_price']) && !is_float($val['sales_price'])) ? $val['sales_price'] . '.00' : $val['sales_price']; | 325 | + $val['sales_price'] = Helpers::transPrice($val['sales_price']); |
326 | $val['market_price'] = ($val['market_price'] - $val['sales_price'] > 0) ? $val['market_price'] . '.00' : false; | 326 | $val['market_price'] = ($val['market_price'] - $val['sales_price'] > 0) ? $val['market_price'] . '.00' : false; |
327 | } | 327 | } |
328 | !empty($data) && $result['browseRecord'] = $data; | 328 | !empty($data) && $result['browseRecord'] = $data; |
@@ -381,9 +381,10 @@ class UserModel | @@ -381,9 +381,10 @@ class UserModel | ||
381 | * @param int $uid 用户ID | 381 | * @param int $uid 用户ID |
382 | * @param int $status 优惠券状态,0表示未使用,1表示已使用 | 382 | * @param int $status 优惠券状态,0表示未使用,1表示已使用 |
383 | * @param int $page 第几页 | 383 | * @param int $page 第几页 |
384 | + * @param boolean $onlyTotal 只返回总数 | ||
384 | * @return array|mixed 处理之后的优惠券数据 | 385 | * @return array|mixed 处理之后的优惠券数据 |
385 | */ | 386 | */ |
386 | - public static function getCouponData($uid, $status, $page) | 387 | + public static function getCouponData($uid, $status, $page, $onlyTotal = false) |
387 | { | 388 | { |
388 | $result = array(); | 389 | $result = array(); |
389 | 390 | ||
@@ -400,6 +401,13 @@ class UserModel | @@ -400,6 +401,13 @@ class UserModel | ||
400 | 401 | ||
401 | // 处理优惠券数据 | 402 | // 处理优惠券数据 |
402 | if (isset($coupons['data'])) { | 403 | if (isset($coupons['data'])) { |
404 | + | ||
405 | + if ($onlyTotal) { | ||
406 | + $result['count'] = $coupons['data']['total']; | ||
407 | + | ||
408 | + return $result; | ||
409 | + } | ||
410 | + | ||
403 | // 不能再查到结果了 | 411 | // 不能再查到结果了 |
404 | if ($page == 1 && $coupons['data']['total'] === 0) { | 412 | if ($page == 1 && $coupons['data']['total'] === 0) { |
405 | $result['walkwayUrl'] = '/product/new'; | 413 | $result['walkwayUrl'] = '/product/new'; |
-
Please register or login to post a comment