作者 SHW\戥岁。。

金额格式化

@@ -414,8 +414,8 @@ class Classification extends Api @@ -414,8 +414,8 @@ class Classification extends Api
414 $goods_spec = Db::name('litestore_goods_spec') 414 $goods_spec = Db::name('litestore_goods_spec')
415 ->where('goods_id', $item['goods_id']) 415 ->where('goods_id', $item['goods_id'])
416 ->find(); 416 ->find();
417 - $item['price'] = $goods_spec['goods_price'];  
418 - $item['line_price'] = $goods_spec['line_price']; 417 + $item['price'] = round($goods_spec['goods_price'], 2);
  418 + $item['line_price'] = round($goods_spec['line_price'], 2);
419 //判断是否打折 419 //判断是否打折
420 $item['is_discount'] = 'is'; 420 $item['is_discount'] = 'is';
421 if ($goods_spec['goods_price'] == $goods_spec['line_price']) { 421 if ($goods_spec['goods_price'] == $goods_spec['line_price']) {
@@ -452,9 +452,11 @@ class Classification extends Api @@ -452,9 +452,11 @@ class Classification extends Api
452 $goods_spec = GoodsSpec::all(['goods_id' => $item['goods_id']]); 452 $goods_spec = GoodsSpec::all(['goods_id' => $item['goods_id']]);
453 foreach ($goods_spec as &$spec_value) { 453 foreach ($goods_spec as &$spec_value) {
454 //规格下的购物车数量 454 //规格下的购物车数量
455 - $spec_value['cart_number'] = Db::name('cart') 455 + $number = Db::name('cart')
456 ->where(['goods_id' => $spec_value['goods_id'], 'sku_id' => $spec_value['goods_spec_id'], 'user_id' => $this->auth->id]) 456 ->where(['goods_id' => $spec_value['goods_id'], 'sku_id' => $spec_value['goods_spec_id'], 'user_id' => $this->auth->id])
457 ->value('number'); 457 ->value('number');
  458 +
  459 + $spec_value['cart_number'] = $number ?? 0;
458 //判断是否打折 460 //判断是否打折
459 $spec_value['is_discount'] = 'is'; 461 $spec_value['is_discount'] = 'is';
460 if ($spec_value['goods_price'] == $spec_value['line_price']) { 462 if ($spec_value['goods_price'] == $spec_value['line_price']) {
@@ -482,8 +484,8 @@ class Classification extends Api @@ -482,8 +484,8 @@ class Classification extends Api
482 $goods_spec = Db::name('litestore_goods_spec') 484 $goods_spec = Db::name('litestore_goods_spec')
483 ->where('goods_id', $item['goods_id']) 485 ->where('goods_id', $item['goods_id'])
484 ->find(); 486 ->find();
485 - $item['price'] = $goods_spec['goods_price'];  
486 - $item['line_price'] = $goods_spec['line_price']; 487 + $item['price'] = round($goods_spec['goods_price'], 2);
  488 + $item['line_price'] = round($goods_spec['line_price'], 2);
487 //判断是否打折 489 //判断是否打折
488 $item['is_discount'] = 'is'; 490 $item['is_discount'] = 'is';
489 if ($goods_spec['goods_price'] == $goods_spec['line_price']) { 491 if ($goods_spec['goods_price'] == $goods_spec['line_price']) {
@@ -521,9 +523,11 @@ class Classification extends Api @@ -521,9 +523,11 @@ class Classification extends Api
521 foreach ($goods_spec as &$spec_value) { 523 foreach ($goods_spec as &$spec_value) {
522 524
523 //规格下的购物车数量 525 //规格下的购物车数量
524 - $spec_value['cart_number'] = Db::name('cart') 526 + $number = Db::name('cart')
525 ->where(['goods_id' => $spec_value['goods_id'], 'sku_id' => $spec_value['goods_spec_id'], 'user_id' => $this->auth->id]) 527 ->where(['goods_id' => $spec_value['goods_id'], 'sku_id' => $spec_value['goods_spec_id'], 'user_id' => $this->auth->id])
526 ->value('number'); 528 ->value('number');
  529 +
  530 + $spec_value['cart_number'] = $number ?? 0;
527 //判断是否打折 531 //判断是否打折
528 $spec_value['is_discount'] = 'is'; 532 $spec_value['is_discount'] = 'is';
529 if ($spec_value['goods_price'] == $spec_value['line_price']) { 533 if ($spec_value['goods_price'] == $spec_value['line_price']) {
@@ -58,8 +58,8 @@ class Goods extends Api @@ -58,8 +58,8 @@ class Goods extends Api
58 } 58 }
59 $goods = $goodsmodel::get($goods_id); 59 $goods = $goodsmodel::get($goods_id);
60 $goods_spec = Db::name('litestore_goods_spec')->where('goods_id', $goods['goods_id'])->find(); 60 $goods_spec = Db::name('litestore_goods_spec')->where('goods_id', $goods['goods_id'])->find();
61 - $goods['price'] = $goods_spec['goods_price'];  
62 - $goods['line_price'] = $goods_spec['line_price']; 61 + $goods['price'] = round($goods_spec['goods_price'], 2);
  62 + $goods['line_price'] = round($goods_spec['line_price'], 2);
63 //判断是否打折 63 //判断是否打折
64 $goods['is_discount'] = 'is'; 64 $goods['is_discount'] = 'is';
65 if ($goods_spec['goods_price'] == $goods_spec['line_price']) { 65 if ($goods_spec['goods_price'] == $goods_spec['line_price']) {
@@ -150,6 +150,8 @@ class Goods extends Api @@ -150,6 +150,8 @@ class Goods extends Api
150 } 150 }
151 $goods_spec = GoodsSpec::all(['goods_id' => $goods_id]); 151 $goods_spec = GoodsSpec::all(['goods_id' => $goods_id]);
152 foreach ($goods_spec as &$value) { 152 foreach ($goods_spec as &$value) {
  153 + $value['goods_price'] = round($value['goods_price'], 2);
  154 + $value['line_price'] = round($value['line_price'], 2);
153 //判断是否打折 155 //判断是否打折
154 $value['is_discount'] = 'is'; 156 $value['is_discount'] = 'is';
155 if ($value['goods_price'] == $value['line_price']) { 157 if ($value['goods_price'] == $value['line_price']) {