padam87/money-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

padam87/money-bundle

Composer 安装命令:

composer require padam87/money-bundle

包简介

Symfony bundle for https://github.com/moneyphp/money

README 文档

README

Symfony bundle for https://github.com/brick/money

As an opinionated bundle, this money bundle uses the following principles as it's main guide:

  • Storage is just as important as calculation.
  • Financial data should be held in SQL, so Doctrine ORM only implementation.
  • Money objects are Embeddables.
  • Amount should be stored in a human readable way in the database.
  • ISO money scale (eg smallest amount is 1 cent for EUR) is not viable for complex applications.

To achieve these, the following restrictions apply:

  • precision and scale are mandatory (but have default values)
  • amounts are mapped as DECIMAL (changable, but not recommended to change)
  • ext-bcmath is mandatory.

Installation

composer require padam87/money-bundle

Configuration (optional)

padam87_money:
    precision:            18
    scale:                2
    currencies:

        # Default:
        - EUR

Usage

Doctrine

A) Using the embedded money type

    #[ORM\Embedded(class: EmbeddedMoney::class)]
    protected EmbeddedMoney $netPrice;

    public function getNetPrice(): ?Money
    {
        return ($this->netPrice)();
    }

    public function setNetPrice(?Money $netPrice): self
    {
        $this->netPrice = new EmbeddedMoney($netPrice);

        return $this;
    }

B) Using separate fields for amount and currency

This is recommended when multiple amounts share the same currency

    use MoneyFromDecimalTrait;

    #[ORM\Column(type: 'currency')]
    private ?Currency $currency = null;

    #[ORM\Column(type: 'decimal_object')]
    private ?BigDecimal $netPrice = null;
    
    #[ORM\Column(type: 'decimal_object')]
    private ?BigDecimal $grossPrice = null;
    

    public function getCurrency(): ?Currency
    {
        return $this->currency;
    }
    
    
    public function getNetPrice(): Money
    {
        return $this->getMoney($this->netPrice);
    }

    protected function setNetPrice(Money $netPrice): self
    {
        $this->setMoney($this->netPrice, $netPrice);

        return $this;
    }
    
    
    public function getGrossPrice(): Money
    {
        return $this->getMoney($this->grossPrice);
    }

    protected function setGrossPrice(Money $grossPrice): self
    {
        $this->setMoney($this->grossPrice, $grossPrice);

        return $this;
    }

Formatting

Twig

{{ netPrice|money }} -> €100

{{ netPrice|money_amount }} -> 100

{{ netPrice|money_currency }} -> €

padam87/money-bundle 适用场景与选型建议

padam87/money-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.39k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2018 年 07 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 padam87/money-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 padam87/money-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 padam87/money-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-24