格式化价格
parent
5dfb4a165b
commit
37856defd6
|
|
@ -21,8 +21,8 @@ class ProduckSkuResource extends JsonResource
|
|||
'cover' => (string) $this->cover,
|
||||
'media' => (string) $this->media,
|
||||
'images' => $this->images,
|
||||
'sell_price' => (string) $this->sell_price,
|
||||
'vip_price' => (string) $this->vip_price,
|
||||
'sell_price' => (string) $this->sell_price_format,
|
||||
'vip_price' => (string) $this->vip_price_format,
|
||||
'sales' => $this->sales,
|
||||
'description' => (string) $this->description,
|
||||
'attrs' => $this->attrs,
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ class ProductSkuSimpleResource extends JsonResource
|
|||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'cover' => (string) $this->cover,
|
||||
'sell_price' => (string) $this->sell_price,
|
||||
'vip_price' => (string) $this->vip_price,
|
||||
'sell_price' => (string) $this->sell_price_format,
|
||||
'vip_price' => (string) $this->vip_price_format,
|
||||
'specs' => array_values((array) $this->specs),
|
||||
'stock' => (int) $this->saleable_stock,
|
||||
'is_online' => $this->isOnline(),
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ class ProductSkuTinyResource extends JsonResource
|
|||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'cover' => (string) $this->cover,
|
||||
'sell_price' => (string) $this->sell_price,
|
||||
'vip_price' => (string) $this->vip_price,
|
||||
'sell_price' => (string) $this->sell_price_format,
|
||||
'vip_price' => (string) $this->vip_price_format,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ class ShoppingCartItemResource extends JsonResource
|
|||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'cover' => (string) $this->cover,
|
||||
'sell_price' => $this->sell_price,
|
||||
'vip_price' => (string) $this->vip_price,
|
||||
'sell_price' => $this->sell_price_format,
|
||||
'vip_price' => (string) $this->vip_price_format,
|
||||
'specs' => array_values((array) $this->specs),
|
||||
'stock' => 0,
|
||||
'is_online' => false,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Helpers\Numeric;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OrderProduct extends Model
|
||||
|
|
@ -36,18 +35,23 @@ class OrderProduct extends Model
|
|||
'total_amount',
|
||||
];
|
||||
|
||||
public function packageProducts()
|
||||
{
|
||||
return $this->hasMany(OrderPackageProduct::class, 'order_product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单商品真实价格
|
||||
* 获取订单商品销售价格
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSellPriceFormatAttribute()
|
||||
{
|
||||
return Numeric::trimTrailingZero(bcdiv($this->attributes['sell_price'], 100, 2));
|
||||
return bcdiv($this->attributes['sell_price'], 100, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单商品真实价格
|
||||
* 获取订单商品会员价格
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -57,11 +61,6 @@ class OrderProduct extends Model
|
|||
return '';
|
||||
}
|
||||
|
||||
return Numeric::trimTrailingZero(bcdiv($price, 100, 2));
|
||||
}
|
||||
|
||||
public function packageProducts()
|
||||
{
|
||||
return $this->hasMany(OrderPackageProduct::class, 'order_product_id');
|
||||
return bcdiv($price, 100, 2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,4 +153,28 @@ class ProductSku extends Model
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品售价
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSellPriceFormatAttribute()
|
||||
{
|
||||
return bcdiv($this->attributes['sell_price'], 100, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品会员价
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVipPriceFormatAttribute()
|
||||
{
|
||||
if (is_null($price = $this->attributes['vip_price'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return bcdiv($price, 100, 2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,4 +35,28 @@ class ShoppingCartItem extends Model
|
|||
{
|
||||
return $this->belongsTo(ProductSku::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品售价
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSellPriceFormatAttribute()
|
||||
{
|
||||
return bcdiv($this->attributes['sell_price'], 100, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品会员价
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVipPriceFormatAttribute()
|
||||
{
|
||||
if (is_null($price = $this->attributes['vip_price'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return bcdiv($price, 100, 2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue