Browse Source

生态节点

afa 6 months ago
parent
commit
2ca32ea92d

+ 5 - 1
application/api/controller/Order.php

@@ -14,6 +14,7 @@ use app\common\model\LedgerTokenChangeModel;
 use app\common\model\OfflineRechargeRecordModel;
 use app\api\logic\OrderLogic;
 use app\api\logic\MarketLogic;
+use app\api\logic\WelfareLoginc;
 use Exception;
 use fast\Asset;
 use think\Db;
@@ -62,7 +63,10 @@ class Order extends Api
                 $pvs = bcmul(($order_info['pv'] * $areaNum), config('community_ratio'), 2);
                 if($pvs > 0)$userModel::setCommunityRewards($this->auth->id, $pvs, Asset::TOKEN);
             }
-      
+            
+            //生态节点标识
+            WelfareLoginc::setUserEcologyAirdrop($this->auth->id, $params['product_id']);
+
             //更新Rwa持有数量
             if($order_info->price > config('min_rwa_price')) $userModel::updateForRwaNum($this->auth->id, $this->auth->parent_id, $areaNum, '+');
             //扣除库存

+ 2 - 1
application/api/controller/Teac.php

@@ -34,7 +34,6 @@ class Teac extends Api
         $this->success('ok', $list);
     }
 
-
     /*
      * 发布求购
      */
@@ -222,5 +221,7 @@ class Teac extends Api
     {
         $this->success('ok', config('teac_trade'));
     }
+
+
    
 }

+ 1 - 0
application/api/controller/User.php

@@ -61,6 +61,7 @@ class User extends Api
             'parent_id'       => $user['parent_id'], // 上级ID
             'is_super'        => $user['address_level'], // 新人福利标识
             'direct_super'    => ['one'=>3, 'two'=>10,'direct_super'=>$user['direct_super']], // 推广新人福等级标识
+            'is_ecology'      => $user['is_ecology'], // 生态标识  
             'avatar'          => !empty($user['avatar'])? $user['avatar']:$this->request->domain().'/assets/img/logo.png', // 头像
             'parent_address'  => '', // 上级的地址
             'invite_link'     => config('rental.invite_domain') . '/?inviteCode=' . $user['address'],

+ 35 - 5
application/api/logic/WelfareLoginc.php

@@ -2,15 +2,15 @@
 
 namespace app\api\logic;
 
-use app\api\controller\Product;
+
 use app\common\model\ProductArea;
-use app\common\controller\Api;
-use app\common\model\UserWelfare;
+use fast\Asset;
+use app\common\model\LedgerFrozenChangeModel;
 use app\common\model\ProductLists;
 use app\common\model\ProductOrder;
 use app\common\model\UserModel;
 use think\Loader;
-use think\Db;
+use app\common\model\UserAirdrop;
 use think\Log;
 use Exception;
 /**
@@ -29,7 +29,6 @@ class WelfareLoginc
     public static function setUserWelfareLos($uid, int $productId, $num, $tim, $lan, $typeId)
     {   
         $result = ProductLists::where('id', $productId)->field('id,'.$lan.'_name as name')->find();
-        //if(!$result || $num > ($result->stock-$result->init_num - $result->num)) throw new Exception(__('库存不足'));
       
         //添加产品
         self::setUserProductOrder($num, 0, 0, 0, $productId, $uid, $typeId);
@@ -149,4 +148,35 @@ class WelfareLoginc
         // 返回订单设置结果
         return $result;
     }
+
+    //推广空投产品
+    public static function setUserEcologyAirdrop(int $uid, int $productId): bool
+    {
+        $ecology = config('ecology');
+        if($ecology['product_id'] != $productId){
+            return true;
+        }
+        $user = UserModel::getById($uid);
+        if($user->is_ecology) return true;
+        //空投产品
+        if($ecology['airdrop']){
+            $userAirdrop = Loader::model('UserAirdrop');
+            foreach ($ecology['airdrop'] as $item) {
+                $userAirdrop::create([
+                    'user_id'       =>  $uid,
+                    'type_id'       =>  UserAirdrop::TypeUser,
+                    'product_id'    =>  $item->product_id,
+                    'num'           =>  $item->num,
+                    'remark'        =>  '超级福利空投',
+                    'status'        =>UserAirdrop::Normal,//为0 待发放层级奖励
+                ]);
+            }
+        }
+        //发放标记茶宝
+        Loader::model('LedgerWalletModel')->changeWalletAccount($uid, Asset::FROZEN, $ecology['frozen'], LedgerFrozenChangeModel::Ecology, 0);
+
+        //修改生态节点标识
+        $user->is_ecology  = 1;
+        return $user->save();
+    }
 }

+ 2 - 1
application/common/logic/AirdropLogic.php

@@ -52,7 +52,8 @@ class AirdropLogic
         // 更新用户福利信息
         WelfareLoginc::setUserExRwaNum(
             $info_list['rwa_num'],
-            $info_list['product_id'],  $info_list['rwa_product_id'],
+            $info_list['product_id'],  
+            $info_list['rwa_product_id'],
             0,  $info_list->id , 0, 
             $info_list['rwa_mod'],
             $info_list['num']

+ 3 - 2
application/common/model/LedgerFrozenChangeModel.php

@@ -18,7 +18,7 @@ class LedgerFrozenChangeModel extends Model
     const Receive           = 4; //资产转让收款
     const System            = 5; //系统调整
     const RwaExchangeRecord = 6;
- 
+    const Ecology           = 7; //生态节点
 
     public static function getStatusList()
     {
@@ -30,7 +30,8 @@ class LedgerFrozenChangeModel extends Model
             self::Payment  => __('转账支付'),
             self::Receive => __('转账收款'),
             self::System => __('系统调整'),
-            self::RwaExchangeRecord=> __('兑换Rwa赠送')
+            self::RwaExchangeRecord=> __('兑换Rwa赠送'),
+            self::Ecology => __('生态节点'),
         ];
     }
 

+ 2 - 3
application/common/model/LedgerWalletModel.php

@@ -81,7 +81,6 @@ class LedgerWalletModel extends Model
     {
         $available = $this->getWallet($uid);
         if (empty($available)) (new LedgerWalletModel())->insertGetId(['user_id' => $uid]);  // 创建钱包
-        $frozen = ''; //冻结金额
         // 账变资产模型
         switch ($asset) {
             case Asset::TOKEN:
@@ -150,7 +149,7 @@ class LedgerWalletModel extends Model
     /**
      * 冻结茶宝
      * @param int $uid 用户ID
-     * @param string $amount 报单金额
+     * @param string $amount 报单金额 
      * @return void
      * @throws Exception
      */
@@ -158,7 +157,7 @@ class LedgerWalletModel extends Model
     {
         $available = $this->getWallet($uid);
         $ledgerWalletModel  = new LedgerWalletModel();
-        if (empty($available)) $ledgerWalletModel->insertGetId(['user_id' => $uid]);  // 创建钱包
+        if (empty($available)) throw new Exception('用户资产信息不存在');
         $walletUpdate = [];
         $result = false;
         //运费/手续费:扣除

+ 13 - 1
application/config.php

@@ -376,6 +376,18 @@ return [
             'RAC' => '0x024a9ad0ecfaa8b3566d3310affb358379a55e7a',
             'USDT' => '0x55d398326f99059ff775485246999027b3197955',
         ],
+    ],
+    //生态节点推广
+    'ecology' => [
+        'product_id'    => 17,//购买指定产品
+        //空投产品与数量
+        'airdrop' => [
+            0 => ['product_id'=>27, 'num'=>1], //1.茶世通宝1套(ID 27)
+            1 => ['product_id'=>12, 'num'=>200],//2.茶世通宝·金 200套(ID 12)
+            2 => ['product_id'=>25, 'num'=>100],// 3.茶世通宝·橘 100套(ID 25)
+            3 => ['product_id'=>40, 'num'=>8] // 4.RWACHA·破茧化蝶 8套(id 40)
+        ],
+        'frozen' => '999', //发放标记茶宝 999个   
 
-    ]
+    ] ,
 ];