本帖最后由 Kvm 于 2024-12-1 16:41 编辑
给你看三哥的代码
功能倒是很多, 就是一堆bug, 连修复的欲望都没有
- if( $hostingdetail->billingcycle == "Monthly" )
- {
- $durationVal = "P1M";
- $pricingModeVal = "default";
- }
- else
- {
- if( $hostingdetail->billingcycle == "Quarterly" )
- {
- $durationVal = "P3M";
- $pricingModeVal = "default";
- }
- else
- {
- if( $hostingdetail->billingcycle == "Semi-Annually" )
- {
- $durationVal = "P6M";
- $pricingModeVal = "default";
- }
- else
- {
- if( $hostingdetail->billingcycle == "Annually" )
- {
- $durationVal = "P1Y";
- $pricingModeVal = "degressivity12";
- }
- else
- {
- if( $hostingdetail->billingcycle == "Biennially" )
- {
- $durationVal = "P2Y";
- $pricingModeVal = "degressivity24";
- }
- else
- {
- $durationVal = "P1M";
- $pricingModeVal = "default";
- }
- }
- }
- }
- }
复制代码
简单更改逻辑后的代码
- public static function billingcycle($billing)
- {
- // 订阅合约时长 P1M=1 P24M=2年月付 P1Y=1年付
- // upfront12 = 1年付
- // degressivity24 = 2年每月付
- $cycles = [
- 'Monthly' => ['duration' => 'P1M', 'pricingMode' => 'default'],
- 'Quarterly' => ['duration' => 'P3M', 'pricingMode' => 'default'],
- 'Semi-Annually' => ['duration' => 'P6M', 'pricingMode' => 'default'],
- 'Annually' => ['duration' => 'P1Y', 'pricingMode' => 'upfront12'],
- 'Biennially' => ['duration' => 'P2Y', 'pricingMode' => 'upfront24'],
- ];
- return $cycles[$billing] ?? $cycles['Monthly'] ;
- }
复制代码 |