remp/crm-upgrades-module 问题修复 & 功能扩展

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

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

remp/crm-upgrades-module

Composer 安装命令:

composer require remp/crm-upgrades-module

包简介

CRM Upgrades Module

README 文档

README

Module provides a way to upgrade user's subscriptions. It utilizes current subscription price, target subscription price, and number of remaining days of user's subscription to calculate "credit" which is used to provide different ways of upgrade.

Installation

We recommend using Composer for installation and update management. To add CRM Upgrades extension to your REMP CRM application use following command:

composer require remp/crm-upgrades-module

Enable installed extension in your app/config/config.neon file:

extensions:
	# ...
	- Crm\UpgradesModule\DI\UpgradesModuleExtension

Configuration

Prerequisites

Upgrades expect you to configure default subscription type for each combination of content access and subscription length. This way the module knows, that if you want to upgrade to subscription type with content access content_access_AA, it's the default one.

The setting is not available in the UI, so you need to seed it manually. You can use following snippet to make sure, there's only one default subscription type for each content access / length combination.

Validation snippet
private function validateDefaultSubscriptionTypes()
{
    $defaultSubscriptionTypes = $this->subscriptionTypesRepository->getTable()
        ->where(['default' => true])
        ->fetchAll();

    $contentAccessCheck = [];
    foreach ($defaultSubscriptionTypes as $subscriptionType) {
        $contentAccess = [];
        foreach ($subscriptionType->related('subscription_type_content_access') as $stca) {
            $contentAccess[$stca->content_access->name] = $stca->content_access->name;
        }
        sort($contentAccess);
        $hash = md5(implode('', $contentAccess) . $subscriptionType->length);
        $contentAccessCheck[$hash][] = $subscriptionType->code;
    }

    $duplicates = [];
    foreach ($contentAccessCheck as $hash => $subscriptionTypes) {
        if (count($subscriptionTypes) > 1) {
            $duplicates[] = $subscriptionTypes;
        }
    }
    return $duplicates;
}

Alternatively you could set the target subscription type explicitly at the upgrade_options.subscription_type column, however this would cause a lot of duplication and is not generally recommended.

Upgraders

Module currently provides 4 default upgraders to use:

  • paid_recurrent. Calculates the amount of money that user needs to pay to upgrade to better subscription without changing the billing cycle. Charge is made directly.
  • free_recurrent. Changes the subscription type configured on the recurring payment. Upgrade is made free of charge at the moment of upgrade, higher amount will be charged at the next billing cycle.
  • paid_extend. Calculates the discount for fully new subscription. End time of original subscription is ignored, original subscription is stopped and remaining days are used as a credit to discount the upgraded subscription price.
  • short. Calculates the credit user has available and uses it to calculate number of days of higher-tier subscription user could have. Upgrade "shortens" the original subscription and upgrades it.

You can implement your own upgrader by following Crm\UpgradesModule\Upgrade\UpgraderInterface and then registering it in applicatino configuration:

services:
	upgraderFactory:
		setup:
			- registerUpgrader(\Crm\FooModule\Models\Upgrades\FooUpgrade())

Subsequent upgrades

CRM provides support to upgrade subscriptions following currently upgraded subscription. Subsequent upgrades allow upgrade of subscriptions:

  • Having the same subscription type as the original subscription before upgrade.
  • Having the same subscription type as the subscription after the upgrade.

Subsequent upgrades currently don't support cross-subscription-type upgrade. That means, that if user has monthly subscription followed by yearly subscription, the yearly still wouldn't be upgraded.

This feature is still experimental and disabled by default. To enable it, add this to your configuration:

services:
	upgraderFactory:
		setup:
			- setSubsequentUpgrader(\Crm\UpgradesModule\Upgrade\ShortUpgrade())

This config says, that to execute subsequent upgrades, CRM should use short upgrader. Even if user used paid_recurrent upgrade to do the actual upgrade, all of the following subscriptions will be shortened. This is to simplify the process and provide universal way of subsequent upgrades.

Upgrade scenarios

At this moment there's no UI to configure the upgrades within CRM admin. You need to seed your configuration from within your internal modules.

Upgrade options

Options define which upgrader can be used for which kind of content-access-based upgrade. The two important columns are:

  • type. This is referencing UpgraderInterface::getType() return value.
  • config. Object defining the conditions of upgrade (described below).
    {
      /*
       * Required. Array of strings. Content access you want to upgrade to. UpgradesModule will search for the default
       * subscription type with the same length, and content access of:
       *
       *   - currently active subscription type, and
       *   - content_access_CC (or whatever is set within "require_content" property
       * 
       * When module finds all available options, it calculates profitability of upgrade to each one of them. The most
       * profitable is offered to user as an option to upgrade.
       */
      "require_content": ["content_access_CC"],
    
      /*
       * Optional. Array of strings. Content access you don't want to upgrade to. UpgradesModule will find the default
       * subscription type with the same length, and content access defined by the "require_content" property, but
       * without ones defined within this property ("content_access_BB").
       * 
       * Since upgrades module always tries to find subscription types with the same content access (plus the ones required)
       * as the current subscription, you can use this property to achieve following:
       *
       *   - Current subscription content access: ["content_access_AA, "content_access_BB"]
       *   - Content access we want to upgrade to: ["content_access_AA", "content_access_CC"]
       */
      "omit_content": ["content_access_BB"],
    
      /*
       * Optional. Number. Defines fixed amount of monthly price raise. By default the module uses price of the target
       * subscription type as a variable for calculations. You can override that and set a monthly fixed raise of price
       * instead. If user is paying 10eur/month and want's to upgrade to 20eur/month subscription, this setting would
       * force all calculations to "see" that the price of upgraded subscription type is 15eur/month (10+5), not 20eur.
       */  
      "monthly_fix": 5,
    
      /*
       * Optional. Some upgrade options (like the one with "monthly_fix") probably shouldn't be available for everyone.
       * You may enforce the limitation by requiring special tags at the landing page for this special offer.
       * The upgrade option will only be available if you request the list of available upgraders with this special tag:
       *
       *   $this->availableUpgraders->all($this->getUser()->id, $contentAccess, ["foo"]);
       */
      "require_tags": ["foo"]
    }

Upgrade schemas

Schemas have only one purpose: to bundle multiple upgrade options logically together.

Module needs to link each subscription type with upgrade options that it can use. To prevent linking each subscription type with N upgrade options, options are grouped within a schema and subscription type is linked to this single schema.

The link is made in subscription_type_upgrade_schemas table and it needs to be defined explicitly for each subscription type you want to be upgradeable.

Example

If you want to allow upgrade to content access foo by shortening the subscription, you would:

  • Insert new upgrade_option record with values:
    • type: short
    • config: {"require_content": ["foo"]}
  • Link it to some upgrade_schema record.
  • Link all the subscription types you want to allow the upgrade from to this upgrade_schema record.
  • Make sure there's a single subscription type with content access foo for each standard length of your subscription types.

Using module

Module has a default presentation layer displaying all the default available upgrade scenarios for currently logged user at :Upgrades:Upgrade:default route.

It's recommended to make a custom implementation of the presenter for special offer upgrades due to the use of require_tags configuration option.

remp/crm-upgrades-module 适用场景与选型建议

remp/crm-upgrades-module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41.79k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 remp/crm-upgrades-module 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-16