Explorar o código

feat(lakala): 添加随机立减功能支持

- 在配置类中新增 random_discount_max 属性用于设置随机立减上限
- 在支付流程中实现随机立减金额计算逻辑
- 更新配置文件,增加随机立减金额上限的表单字段定义
- 设置默认值为0,并支持用户自定义设置立减区间
runphp hai 4 meses
pai
achega
bf87d170a3
Modificáronse 3 ficheiros con 20 adicións e 0 borrados
  1. 17 0
      config.php
  2. 1 0
      src/Config.php
  3. 2 0
      src/PaymentProvider.php

+ 17 - 0
config.php

@@ -303,6 +303,23 @@ return json_decode(<<<'JSON'
     "name": "ref_Fqcvmh2zkilk152c",
     "display": true,
     "hidden": false
+  },
+  {
+    "type": "input",
+    "title": "随机立减金额上限",
+    "field": "random_discount_max",
+    "value": "0",
+    "props": {
+      "placeholder": "请输入随机立减金额上限,如:0.5(表示0到0.5之间的随机减免)",
+      "type": "number",
+      "min": 1,
+      "step": 0.01
+    },
+    "_fc_id": "id_FrandomDiscount",
+    "name": "ref_FrandomDiscount",
+    "_fc_drag_tag": "input",
+    "display": true,
+    "hidden": false
   }
 ]
 JSON, true);

+ 1 - 0
src/Config.php

@@ -16,6 +16,7 @@ use SixShop\System\Trait\ConfigTrait;
  * @property string $org_code 机构代码
  * @property string $sub_appid 子商户公众账号ID
  * @property string $receiver_agreement_file 默认合作协议文件
+ * @property string $random_discount_max 随机立减金额上限
  */
 class Config
 {

+ 2 - 0
src/PaymentProvider.php

@@ -49,6 +49,8 @@ class PaymentProvider implements PaymentProviderInterface
             throw new  \RuntimeException('开发测试中,请稍后再试');
         }
         $payment->transaction(function () use ($bizType, $order, $payment) {
+            $randomDiscount = mt_rand(1, intval($this->config->random_discount_max * 100)) / 100;
+            $order['pay_amount'] = $order['pay_amount'] - $randomDiscount;
             $payment->save([
                 'user_id' => $order['user_id'],
                 'order_id' => $order['id'],