浏览代码

茶宝Api

afa 4 月之前
父节点
当前提交
8b2a875f12

+ 8 - 21
application/api/controller/Chabao.php

@@ -112,28 +112,15 @@ class Chabao extends Api
 
 
 
-    //取消交易
-    public function cancelTrade(ProductTeac $productTeac, TeacLogin $teacLogin)
+    //转让茶宝
+    public function chalink(UserModel $userModel, LedgerWalletModel $ledgerWalletModel)
     {
-        $id = $this->request->post('teac_id/d', 0);
-        $row = $productTeac::where(['id' => $id, 'user_id' => $this->auth->id])->find();
-        if(empty($row)) $this->error('订单不存在');
-        if($row['status'] != ProductTeac::Normal) $this->error('订单已完成');
-        Db::startTrans();
-        try {
-
-            //返回相应茶宝Teac
-            $teacLogin::setUserReturnOrder($this->auth->id, $row['type_id'], $row['frozen']);
-            $row->frozen = 0;
-            $row->status = ProductTeac::Closure;
-            $row->save();
-            // 提交事务
-            Db::commit();
-        } catch (Exception $e) {
-            // 回滚事务
-           Db::rollback();
-            return $e->getMessage();
-        }
+        $user = $userModel->getByPhone($this->params['mobile']);
+        
+        if(!$user) $this->error('钱包地址不存在');
+      
+        //添加茶宝
+        $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TOKEN, $this->params['chalink'], LedgerTokenChangeModel::ChaLink);
         $this->success('ok');
     }
 

+ 7 - 11
application/api/logic/WelfareLoginc.php

@@ -166,22 +166,18 @@ class WelfareLoginc
                     'num'           =>  $item['num'],
                     'total_num'     =>  $item['num'],
                     'remark'        =>  '生态节点空投',
-                    'status'        =>UserAirdrop::Normal,//为0 待发放层级奖励
+                    'status'        =>  UserAirdrop::Normal,//为0 待发放层级奖励
                 ]);
             }
         }
 
         //发放上级推广奖励
-        $ecologyCount = UserModel::where('parent_id', $parentId)->where('is_ecology', 1)->count() + 1;
-        $mod = bcmod($ecologyCount, 3);
-        $parent_chabao = $ecology['parent_chabao'][$mod];
-        if($mod == 0) Loader::model('ProductOrder')::setCreateOrder(0, ['product_id'=> $ecology['parent_product_id'], 'area_id'=>0, 'price'=>0], ProductOrder::Airdrop, $parentId, 0, 0, 0, 0);
-        //发放上级茶宝奖励
-        Loader::model('LedgerWalletModel')->changeWalletAccount($parentId, Asset::TOKEN, $parent_chabao, LedgerTokenChangeModel::Ecology, 0);
-        
-
-        //发放自己标记茶宝
-        //Loader::model('LedgerWalletModel')->changeWalletAccount($uid, Asset::FROZEN, $ecology['frozen'], LedgerFrozenChangeModel::Ecology, 0);
+        $ecologyCount = Loader::model('ProductOrder')->isBuyHoldProduct($ecology['parent_hold_product_id'], $parentId);
+        if($ecologyCount > 0){
+            //发放上级茶宝奖励
+            Loader::model('LedgerWalletModel')->changeWalletAccount($parentId, Asset::TOKEN, $ecology['parent_chabao'], LedgerTokenChangeModel::Ecology, 0);
+        }
+
         //修改生态节点标识
         $user->is_ecology  = 1;
         return $user->save();

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

@@ -33,7 +33,7 @@ class LedgerTokenChangeModel extends Model
      const Ecology           = 19; //生态节点奖励
      const Pledge            = 20; //存储服务费
      const TeamLevel         = 21; //等级分佣
-
+     const ChaLink           = 22; //茶付宝转入
      /*
       * 支付状态
       * 0未支付 100支付中 200支付成功 400支付失败
@@ -57,6 +57,7 @@ class LedgerTokenChangeModel extends Model
          self::Ecology           => '生态节点奖励',
          self::Pledge            => '存储服务费',
          self::TeamLevel         => '社区服务奖励',
+         self::ChaLink           => '茶付宝转入',
      ];
 
            
@@ -85,6 +86,7 @@ class LedgerTokenChangeModel extends Model
             self::Ecology => __('生态节点奖励'),
             self::Pledge => __('存储服务费'),
             self::TeamLevel => __('社区服务奖励'),
+            self::ChaLink => __('茶付宝转入'),
            ];
     }
    

+ 20 - 19
application/common/model/ProductOrder.php

@@ -87,7 +87,6 @@ class ProductOrder extends Model
         return $result;
     }
 
-  
 
     /**
      * @param int   $orderId   订单id
@@ -116,6 +115,12 @@ class ProductOrder extends Model
         ]);
     }
 
+    //判断是否购买持有产品
+    public function isBuyHoldProduct(array $productId, int $uid){
+        
+        return self::where('user_id', $uid)->whereIn('product_id', $productId)->whereIn('a.status', [self::Paid, self::Transferred, self::Freeze])->count();
+    }
+
     //获取持有产品数量
     public static function getByOrderProductNum($productId, $num, $uid)
     {
@@ -129,16 +134,16 @@ class ProductOrder extends Model
         return $productId;
     }
 
-    //空投产品向达到一定持有量的用户 total_num
+    //空投产品向达到一定持有量的用户
     public static function getUserOrderByProductId(int $rwaProductId, int $rwaNum){
         return ProductOrder::alias('a')
-        ->join('product_list b', 'a.product_id = b.id', 'left')
-        ->where('b.is_show', ProductLists::Normal)
-        ->whereIn('a.status', [self::Paid, self::Transferred, self::Freeze])
-        ->where('a.product_id', $rwaProductId)
-        ->group('a.user_id')->having('total_num>='.$rwaNum)
-        ->field('a.id,a.user_id,count(a.num) as total_num')
-        ->select();
+                ->join('product_list b', 'a.product_id = b.id', 'left')
+                ->where('b.is_show', ProductLists::Normal)
+                ->whereIn('a.status', [self::Paid, self::Transferred, self::Freeze])
+                ->where('a.product_id', $rwaProductId)
+                ->group('a.user_id')->having('total_num>='.$rwaNum)
+                ->field('a.id,a.user_id,count(a.num) as total_num')
+                ->select();
     }
 
     //获取持有产品数量订单
@@ -160,7 +165,8 @@ class ProductOrder extends Model
     }
 
     // 获取订单状态
-    public static function getProductOrder($orderId, $status, string $field){
+    public static function getProductOrder($orderId, $status, string $field)
+    {
         return self::alias('a')->where('a.id', $orderId)
                 ->join("product_list b", "a.product_id = b.id", "left")
                 ->field('a.*,'.$field)
@@ -169,20 +175,15 @@ class ProductOrder extends Model
     }
 
     // 获取新人福利领取订单记录
-    public static function getUserWelfare($uid, $typeId){
-        return self::where('user_id', $uid)
-                ->where('type_id', $typeId)
-                ->order('create_time desc')
-                ->find();
+    public static function getUserWelfare($uid, $typeId)
+    {
+        return self::where('user_id', $uid)->where('type_id', $typeId)->order('create_time desc')->find();
     }
 
 
-
-    
     public static function getStatusList()
     {
-        return [self::Paid  => __('已付款'), self::Transferred => __('已转让'), 
-        self::Shipped => __('提货'), self::Cancelled  => __('已取消'), self::Closure => __('关闭'), self::Freeze => __('质押')];
+        return [self::Paid  => __('已付款'), self::Transferred => __('已转让'), self::Shipped => __('提货'), self::Cancelled  => __('已取消'), self::Closure => __('关闭'), self::Freeze => __('质押')];
     }
 
     //全部类型: 

+ 3 - 3
application/config.php

@@ -375,9 +375,9 @@ return [
             3 => ['product_id'=>40, 'num'=>8],   //4.RWACHA·破茧化蝶 8套(id 40)
             4 => ['product_id'=>101, 'num'=>1]   //4.TeaC·生态发展,空投卡 1 张(id 52)
         ],
-        'frozen'            => '999', //发放标记茶宝 999个
-        'parent_product_id' => 26,    //上级空投指定产品
-        'parent_chabao'     => [0=>749.5, 1=>299.8, 2=>499.7], //上级奖励茶宝: 顺序:1=1, 2=2, 3=0
+        'parent_hold_product_id' => [16, 17, 35], //上级持有产品
+        'parent_product_id'      => 26,    //上级空投指定产品
+        'parent_chabao'          => 450,   //上级奖励茶宝: 顺序:1=1, 2=2, 3=0
     ],
     //超级福利奖励
     'super_welfare' => [