定制 yeknava/simple-wallet 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

yeknava/simple-wallet

Composer 安装命令:

composer require yeknava/simple-wallet

包简介

simple wallet package for laravel

README 文档

README

Laravel Simple Wallet Package. this package heavily inspired by laravel-wallet package. if you need a full feature wallet you should use laravel-wallet. i made this package because i needed a simple wallet functionality with some modifications which laravel-wallet didn't support them at that time, like cash back feature or supporting a system (core) wallet which has sum of all purchases. also you may lock wallet balance or part of it or even lock whole wallet and release it after.

Features

  • Deposit
  • Withdraw
  • Gift (user to user)
  • System Gift (system to user)
  • Purchase
  • Cashback
  • Refund
  • Lock Balance
  • Lock / Full Lock Wallet
  • Transactions history
  • Multi wallets
  • Currency exchange
  • Force transaction (negative balance)

Installation

Use the package manager composer to install simple wallet package.

composer require yeknava/simple-wallet

Usage

Run this command in your terminal:

php artisan vendor:publish

Add HasWallet trait to models that have wallets.

<?php

use Yeknava\SimpleWallet\HasWallet;

class User extends Model {
    use HasWallet;

    protected static function boot()
    {
        parent::boot();
        self::walletBoot();
    }
}
$user = User::first();
$user->balance(); // float(0.0)

$user->deposit(100);
$user->balance(); // float(100.0)

$user->withdraw(10);
$user->balance(); // float(90.0)

$system = User::where('type', 'system')->first();

$user->withdraw(10, ['desc'=>'monthly_fee'], null, null, $system->wallet());
$user->balance(); // float(80.0)
$system->balance(); // float(10.0)

$user2 = User::last();
$user2->balance(); // float(0.0)
$user->transfer(10, $user2->wallet());
$user->balance(); // float(70.0)
$user2->balance(); // float(10.0)
$user2->forceTransfer(20, $user->wallet());
$user2->balance(); // float(-10.0)
$user->balance(); // float(90.0)

$user->lockBalance(10);
$user->balance(); // float(80.0)
$user->blocked(); // float(10.0)
$user->releaseBalance(5); // float(10.0)
$user->balance(); // float(85.0)
$user->blocked(); // float(5.0)

$user->lockWallet(); // lock for pay but available for being paid 
$user->transfer(10, $user2->wallet()); // error
$user->deposit(10); // success
$user->fullLockWallet(); // lock for pay or being paid
$user->deposit(10); // error
$user->releaseWallet();
$user->transfer(10, $user2->wallet()); // success

// purchase an item with 50 price which user2 is owner of it and with 5 cashback for payer
$user->balance(); // float(85.0)
$user2->balance(); // float(0.0)
$user->purchase(50, "sample_service", $user2->wallet(), null, ['fee'=>2], 5); 
$user->balance(); // float(40.0)
$user2->balance(); // float(45.0)

$payment = $user1->transactions()->where('service_id', 'sample_service')->first();
$user1->refund($payment);
$user->balance(); // float(85.0)
$user2->balance(); // float(0.0)

$user1NewWallet = $user1->createWallet([], 'wallet2'); //new wallet with 'wallet2' slug
$user1NewWallet->balance(); // float(0.0)
$user->balance(); // float(85.0)
$user1NewWallet->makeDefault();
$user->balance(); // float(0.0)

Config

<?php

use Yeknava\SimpleWallet\Samples\UsdRateServiceSample;

return [
    'default_currency' => 'irt',

    'currencies' => [
        'irr' => 'IRR',
        'irt' => 'IRT',
        'usd' => 'USD',
    ],

    'rates' => [
        'irr' => [
            'irt' => 0.1,
            'usd' => 0.0067
        ],
        'irt' => [
            'irr' => 10,
            'usd' => 0.067
        ],
        'usd' => UsdRateServiceSample::class
    ],

    'wallet_default_slug' => 'wallet',

    // if true, wallet will be created on calling any wallet
    // specific methods in case holder has not any wallet
    'create_wallet_on_fetch' => true 
];

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

yeknava/simple-wallet 适用场景与选型建议

yeknava/simple-wallet 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 02 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「payment」 「laravel」 「wallet」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 yeknava/simple-wallet 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-26