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