afa 4 сар өмнө
parent
commit
63d0554eb9

+ 29 - 0
application/admin/view/product/welfarerede/add.html

@@ -101,6 +101,35 @@
         </div>
     </div>
 
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('是否开启推广')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input type="radio" name="row[is_promotion]" value="0" checked />不开启
+            <input type="radio" name="row[is_promotion]" value="1" /> 开启
+            <p style="color: cornflowerblue;">上级推荐奖励请输入%比</p>
+        </div>
+    </div>
+    <div class="form-group" data-favisible="is_promotion=1">
+        <label class="control-label col-xs-12 col-sm-2">{:__('推广持有产品数量')}:</label>
+        <div class="col-xs-12 col-sm-3">
+            <input id="c-promotion_product" class="form-control" name="row[promotion_product]" type="text" value="1">
+        </div>
+        <label class="control-label col-xs-12 col-sm-2">{:__('一级奖励')}:</label>
+         <div class="col-xs-12 col-sm-3">
+            <input id="c-promotion_one" class="form-control" placeholder="请输入%比" name="row[promotion_one]" type="text" value="25">
+        </div>
+    </div>
+    <div class="form-group" data-favisible="is_promotion=1">
+        <label class="control-label col-xs-12 col-sm-2">{:__('二级奖励')}</label>
+        <div class="col-xs-12 col-sm-3">
+            <input id="c-promotion_two" class="form-control" placeholder="请输入%比"  name="row[promotion_two]" type="text" value="5">
+        </div>
+        <label class="control-label col-xs-12 col-sm-2">{:__('三级奖励')}</label>
+        <div class="col-xs-12 col-sm-3">
+            <input id="c-promotion_thre" class="form-control" placeholder="请输入%比"  name="row[promotion_thre]" type="text" value="0">
+        </div>
+    </div>
+    
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Describe')}:</label>
         <div class="col-xs-12 col-sm-8">

+ 28 - 0
application/admin/view/product/welfarerede/edit.html

@@ -97,6 +97,34 @@
         <div class="col-xs-12 col-sm-3">
             <input id="c-chabao_num" class="form-control" name="row[chabao_num]" type="text" value="{$row.chabao_num|htmlentities}">
         </div>
+    </div>
+     <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('是否开启推广')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input type="radio" name="row[is_promotion]" value="0" {if $row.is_promotion==0} checked {/if} />不开启
+            <input type="radio" name="row[is_promotion]" value="1" {if $row.is_promotion==1} checked {/if}/> 开启
+            <p style="color: cornflowerblue;">上级推荐奖励请输入%比</p>
+        </div>
+    </div>
+    <div class="form-group" data-favisible="is_promotion=1">
+        <label class="control-label col-xs-12 col-sm-2">{:__('推广持有产品数量')}:</label>
+        <div class="col-xs-12 col-sm-3">
+            <input id="c-promotion_product" class="form-control" name="row[promotion_product]" type="text" value="{$row.promotion_product|htmlentities}">
+        </div>
+        <label class="control-label col-xs-12 col-sm-2">{:__('一级奖励')}:</label>
+         <div class="col-xs-12 col-sm-3">
+            <input id="c-promotion_one" class="form-control" placeholder="请输入%比" name="row[promotion_one]" type="text" value="{$row.promotion_one|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group" data-favisible="is_promotion=1">
+        <label class="control-label col-xs-12 col-sm-2">{:__('二级奖励')}</label>
+        <div class="col-xs-12 col-sm-3">
+            <input id="c-promotion_two" class="form-control" placeholder="请输入%比"  name="row[promotion_two]" type="text" value="{$row.promotion_two|htmlentities}">
+        </div>
+        <label class="control-label col-xs-12 col-sm-2">{:__('三级奖励')}</label>
+        <div class="col-xs-12 col-sm-3">
+            <input id="c-promotion_thre" class="form-control" placeholder="请输入%比"  name="row[promotion_thre]" type="text" value="{$row.promotion_thre|htmlentities}">
+        </div>
     </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Describe')}:</label>

+ 8 - 1
application/api/controller/Exchange.php

@@ -94,6 +94,7 @@ class Exchange extends Api
               if($check_user >= $welfare_config['limit_num']) $this->error('每人限制兑换' .$welfare_config['limit_num'].'套,您已达上限');
           }
           $token = 0; 
+          $bonus = 0; //推广u或茶宝数量
           $order_no = date('YmdHis') . rand(1000, 9999);
           $inster_data = [
               'order_no' => $order_no,
@@ -165,6 +166,7 @@ class Exchange extends Api
                 foreach ($result_usdt['data'] as $value) {
                     if ($value['amount'] == $welfare_config->usdt_num) {
                         $usdt_list[] = $value;
+                        $bonus += $value['amount'];
                     }
                 }
                 if (empty($usdt_list)) {
@@ -191,7 +193,8 @@ class Exchange extends Api
             }
             
             if($type_id == 1){
-                $inster_data['amount_chabao'] =$token= $welfare_config->chabao_num;
+                $inster_data['amount_chabao'] =$token= $bonus= $welfare_config->chabao_num;
+
             }
           try {
               Db::startTrans();
@@ -208,6 +211,10 @@ class Exchange extends Api
               if($token > 0){
                   $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$token, LedgerTokenChangeModel::RwaExchangeRecord, 0);
               }
+              //推广奖励
+              if($bonus > 0 && !empty($welfare_config->is_promotion) && $welfare_config->promotion_product > 0){
+                  ProductWelfareRede::sendPromotionReward($this->auth->id, explode(',', $welfare_config->product_id), $welfare_config->promotion_product, $bonus, $welfare_config->promotion_one,$welfare_config->promotion_two, $welfare_config->promotion_thre);
+              }
               //发放产品奖励
               $rs =WelfareLoginc::setUserWelfareProduct($this->auth->id, $welfare_config['product_id'], ProductOrder::RwaExchange);
               Log::info($rs, '发放产品奖励状态');

+ 0 - 2
application/api/controller/Product.php

@@ -14,8 +14,6 @@ use app\api\logic\OrderLogic;
 class Product extends Api
 {
     protected array $noNeedLogin = ['getPopularList'];
-
-
     protected string $lan = '';
 
     public function _initialize()

+ 3 - 0
application/common/model/LedgerTokenChangeModel.php

@@ -35,6 +35,7 @@ class LedgerTokenChangeModel extends Model
      const TeamLevel         = 21; //等级分佣
      const ChaLink           = 22; //茶付宝转入
      const RwaExchangeRecord = 23; //兑换Rwa
+     const Promotion         = 24; //推广奖励
      /*
       * 支付状态
       * 0未支付 100支付中 200支付成功 400支付失败
@@ -60,6 +61,7 @@ class LedgerTokenChangeModel extends Model
          self::TeamLevel         => '社区服务奖励',
          self::ChaLink           => '茶付宝划转',
          self::RwaExchangeRecord => '兑换Rwa',
+         self::Promotion         => '推广奖励',
      ];
 
            
@@ -90,6 +92,7 @@ class LedgerTokenChangeModel extends Model
             self::TeamLevel => __('社区服务奖励'),
             self::ChaLink => __('茶付宝转入'),
             self::RwaExchangeRecord => __('兑换Rwa'),
+            self::Promotion => __('推广奖励'),
            ];
     }
    

+ 34 - 1
application/common/model/ProductWelfareRede.php

@@ -6,7 +6,7 @@ use Exception;
 use fast\Action;
 use fast\Asset;
 use fast\RechargeOrderType;
-use fast\RechargeStatus;
+use think\Loader;
 use think\Db;
 use think\Model;
 
@@ -41,6 +41,39 @@ class ProductWelfareRede extends Model
         self::Normal            => '正常'
     ];
 
+
+    //发放推广奖励
+    public static function sendPromotionReward(int $user_id, array $product_ids,  int $product_num, $bonus,  int $promotion_one, int $promotion_two, int $promotion_thre){
+
+        $pathId  = UserPathModel::where('user_id', $user_id)->order('distance', 'asc')->limit(3)->column('parent_id');
+        $ledgerWalletModel = new LedgerWalletModel();
+        $productOrder = new ProductOrder();
+        $ratio = 0;
+        foreach ($pathId as $key=> $pid) {
+            switch ($key) {
+                case 1:
+                    $ratio = $promotion_two;
+                    break;
+                case 2:
+                    $ratio = $promotion_thre;
+                    break;
+                default:
+                    $ratio = $promotion_one;
+                    break;
+            }
+            //如果比例大于0
+            if($ratio > 0){
+                //查询上级持有量
+                $num = $productOrder->isBuyHoldProduct($product_ids, $pid);
+                if($num >= $product_num){
+                    //发放奖励
+                    $amount = $bonus* bcdiv($ratio, 100, 3);
+                    if( $amount > 0) $ledgerWalletModel->changeWalletAccount($pid, Asset::TOKEN, $amount, LedgerTOKENChangeModel::Promotion, 0);
+                }
+            }
+        }
+    }
+
   
     public function getCreateTimeTextAttr($value, $data)
     {

+ 2 - 0
public/assets/js/backend/ledger/ledger_token_change.js

@@ -56,6 +56,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                 20: '存储服务费',
                                 21: '社区服务奖励',
                                 22: '茶付宝划转',
+                                23: '兑换Rwa',
+                                24: '推广奖励',
                             }, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label
                         },
                     ]