afa 6 сар өмнө
parent
commit
34c926b03f

+ 3 - 0
application/admin/controller/product/Pledges.php

@@ -23,6 +23,9 @@ class Pledges extends Backend
      */
     protected $model = null;
 
+    protected $multiFields = ['status','is_renew'];
+    
+
     public function _initialize()
     {
         parent::_initialize();

+ 2 - 0
application/admin/lang/zh-cn/product/pledges.php

@@ -12,6 +12,8 @@ return [
     'Detail'      => '详情',
     'Weigh'       => '权重',
     'Status'      => '状态',
+    'Token'       => '茶宝',
+    'Teac'        => 'TeaC',
     'Create_time' => '创建时间',
     'Update_time' => '更新时间'
 ];

+ 12 - 1
application/admin/view/product/pledges/add.html

@@ -52,13 +52,24 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Day_num')}:</label>
         <div class="col-xs-12 col-sm-3">
-            <input id="c-day_num" data-rule="required;range(1~)" class="form-control" name="row[day_num]" type="number" value="0">
+            <input id="c-day_num" data-rule="required;range(0.01~)" class="form-control" name="row[day_num]" type="number" value="0">
         </div>
         <label class="control-label col-xs-12 col-sm-2">{:__('Income_reta')}:</label>
         <div class="col-xs-12 col-sm-3">
             <input id="c-income_reta" data-rule="required;range(0.01~)" min="0" class="form-control" step="0.01" name="row[income_reta]" type="number" value="0.00">
         </div>
     </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Token')}:</label>
+        <div class="col-xs-12 col-sm-3">
+            <input id="c-token" data-rule="required;range(0.01~)" class="form-control" name="row[token]" type="number" value="0">
+        </div>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Teac')}:</label>
+        <div class="col-xs-12 col-sm-3">
+            <input id="c-teac" data-rule="required;range(0.01~)" min="0" class="form-control" step="0.01" name="row[teac]" type="number" value="0.00">
+        </div>
+    </div>
+    
 
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Detail')}:</label>

+ 11 - 1
application/admin/view/product/pledges/edit.html

@@ -53,13 +53,23 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Day_num')}:</label>
         <div class="col-xs-12 col-sm-3">
-            <input id="c-day_num" data-rule="required;range(1~)" class="form-control" name="row[day_num]" type="number" value="{$row.day_num|htmlentities}">
+            <input id="c-day_num" data-rule="required;range(0.01~)" class="form-control" name="row[day_num]" type="number" value="{$row.day_num|htmlentities}">
         </div>
         <label class="control-label col-xs-12 col-sm-2">{:__('Income_reta')}:</label>
         <div class="col-xs-12 col-sm-3">
             <input id="c-income_reta" data-rule="required" min="0" class="form-control" step="0.01" name="row[income_reta]" type="number" value="{$row.income_reta|htmlentities}">
         </div>
     </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Token')}:</label>
+        <div class="col-xs-12 col-sm-3">
+            <input id="c-token" data-rule="required;range(0.01~)" class="form-control" name="row[token]" type="number" value="{$row.token|htmlentities}">
+        </div>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Teac')}:</label>
+        <div class="col-xs-12 col-sm-3">
+            <input id="c-teac" data-rule="required;range(0.01~)" min="0" class="form-control" step="0.01" name="row[teac]" type="number" value="{$row.teac|htmlentities}">
+        </div>
+    </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Detail')}:</label>
         <div class="col-xs-12 col-sm-8">

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

@@ -66,7 +66,7 @@ class Order extends Api
             }
             
             //生态节点标识
-            WelfareLoginc::setUserEcologyAirdrop($this->auth->id, $params['product_id']);
+            WelfareLoginc::setUserEcologyAirdrop($this->auth->id, $params['product_id'], $this->auth->parent_id);
 
             //更新Rwa持有数量
             if($order_info->price > config('min_rwa_price')) $userModel::updateForRwaNum($this->auth->id, $this->auth->parent_id, $areaNum, '+');

+ 16 - 7
application/api/controller/Pledge.php

@@ -5,7 +5,7 @@ namespace app\api\controller;
 
 use app\common\controller\Api;
 use app\common\model\ProductLists;
-use app\common\model\ProductOrder;
+use app\common\model\LedgerWalletModel;
 use app\common\model\ProductPledges;
 use Exception;
 use app\common\model\UserModel;
@@ -18,6 +18,7 @@ class Pledge extends Api
 {
 
       protected string $lan = '';
+      protected $pay = [1=>'token', 2=>'teac'];
 
       public function _initialize()
       {
@@ -72,23 +73,30 @@ class Pledge extends Api
       /*
       * 质押存储
       */
-      public function create(ProductPledges $productPledges, PledgeLogic $pledgeLogic)
+      public function create(ProductPledges $productPledges, PledgeLogic $pledgeLogic, LedgerWalletModel $ledgerWalletModel)
       {
         $pledge_id  = $this->request->post('pledge_id', 0, 'intval');
         $order_no   = $this->request->post('order_no/a', '');
-        if(empty($pledge_id) || empty($order_no)) $this->error(__("参数有误,无可用产品"));
+        $pay_type   = $this->request->post('pay_type/d', 1);//支付方式 1 茶宝 2 Teac
+        if(empty($pledge_id) || empty($order_no) || in_array($pay_type, [1,2]) == false) $this->error(__("参数有误,无可用产品"));
 
         $pledge = $productPledges::get($pledge_id);
+        $count  = count($order_no);//选择商品数量    
+        if($pledge->type_id == $productPledges::Combin && count(explode(',', $pledge->product_id)) !=  $count) $this->error(__("质押商品数量与订单数量不匹配"));
 
-        if($pledge->type_id == $productPledges::Combin && count(explode(',', $pledge->product_id)) != count($order_no)) $this->error(__("质押商品数量与订单数量不匹配"));
-
+        //单品最大三个限制
+        if($pledge->type_id == $productPledges::Single &&  $count > config('pledge_single_max')) $this->error(__("单品最大三个限制"));
         if (empty($pledge)) $this->error(__("质抵活动不存在"));
         if (empty($pledge->status) )$this->error(__("质抵活动已结束"));
+
+        //余额判断
+        $user = $ledgerWalletModel::getWallet($this->auth->id);
+        if($user[$this->pay[$pay_type]] < $pledge[$this->pay[$pay_type]]) $this->error(__("余额不足"));
         Db::startTrans();
         try {
-         
+
             // 质抵押订单 
-            $pledgeLogic::setPledgeOrder($pledge, $order_no, $this->auth->id);
+            $pledgeLogic::setPledgeOrder($pledge, $order_no, $this->auth->id, $count, $this->pay[$pay_type], $pledge[$this->pay[$pay_type]]);
             // 提交事务
             Db::commit();
         } catch (Exception $e) {
@@ -160,5 +168,6 @@ class Pledge extends Api
             $this->success('ok', $res);
       }
    
+      //存储续费
  
 }

+ 16 - 11
application/api/logic/PledgeLogic.php

@@ -7,6 +7,8 @@ use think\Env;
 use think\Cache;
 use think\Loader ;
 use fast\Asset;
+use app\common\model\LedgerTokenChangeModel;
+use app\common\model\LedgerWalletModel;
 use app\common\model\ProductOrder;
 use app\common\model\LedgerTeacChangeModel;
 use app\common\model\ProductPledges;
@@ -38,10 +40,9 @@ class PledgeLogic
     }
 
     //添加质抵押订单
-    public static function setPledgeOrder(object $pledge, array $order_no, int $user_id)
+    public static function setPledgeOrder(object $pledge, array $order_no, int $user_id, int $count, string $pay_type, float $price)
     {
         $model  = Loader::model('ProductOrder');
-        $count = count($order_no);
         $product= $model::alias('a')
             ->join('product_list b', 'a.product_id = b.id', 'left')
             ->where('a.user_id', $user_id)
@@ -50,22 +51,23 @@ class PledgeLogic
         
         if(empty($product) || count($product) < $count)  throw new Exception('订单不存在');
         $pledge_num = 1;
-        if($pledge->type_id == ProductPledges::Single){
-            $pledge_num = $count;
-        }
-
+        if($pledge->type_id == ProductPledges::Single) $pledge_num = $count;
+        
         //添加订单 
         Loader::model('UserPledge')::setPledgeData($user_id, $pledge->id, $pledge->product_id, 
         $product, //订单信息
         $pledge->day_num, $pledge_num);
 
+        //扣除支付金额
+        $action = ($pay_type == Asset::TEAC)? LedgerTeacChangeModel::PledgeFee: LedgerTokenChangeModel::Pledge; //类型
+        (new LedgerWalletModel())->changeWalletAccount($user_id, $pay_type, $price, $action, 0);
+  
         //修改状态
         return $model->whereIn('id', array_column($product, 'id'))->setField('status', $model::Freeze);
     }
 
 
     //获取质抵押订单列表
-    //(60*60*24)*(当前时间-最后一次收取时间)
     public static function getPledgeOrderList(int $user_id)//: array
     {
         $model  = Loader::model('UserPledge');
@@ -73,7 +75,7 @@ class PledgeLogic
             ->join('product_pledge b', 'a.pledge_id = b.id', 'left')
             ->where('a.user_id', $user_id)
             ->where('a.status', '>', $model::Close)
-            ->field('a.*,b.title,b.day_num')
+            ->field('a.*,b.title,b.type_id,b.day_num,b.token,b.teac,b.is_renew')
             ->select();
         if(empty($list)) throw new Exception('暂无质押订单');
         $day   = 86400;
@@ -99,16 +101,18 @@ class PledgeLogic
     public static function setPledgeRemove(int $pledge_id, int $user_id)
     {
         $model  = Loader::model('UserPledge');
+        $time  = time();
         $rows   = $model::alias('a')
                 ->join('product_pledge b', 'a.pledge_id = b.id', 'left')
                 ->where('a.user_id', $user_id)
-                ->where('a.id', $pledge_id)->where('a.status', $model::Ongoing)
+                ->where('a.id', $pledge_id)
+                ->where('a.status', $model::Ongoing)
+                ->where('a.end_time', '<', $time)
                 ->field('a.*,b.day_num')
                 ->find();
         if(empty($rows))  throw new Exception('暂无质押订单');
         $day   = 86400;
         $total = 0; //当前累计收益
-        $time  = time();
         $reta  = bcdiv($rows->day_num, $day, 6); //天数
         $inter = ($rows->last_time == 0) ? $time - $rows->create_time: $time - $rows->last_time; //最后收取时间
         $total = bcmul($reta, $inter, 6) * $rows->num; //累计收益
@@ -129,17 +133,18 @@ class PledgeLogic
     public static function getPledgeCollect(int $user_id)
     {   
         $model  = Loader::model('UserPledge');
+        $time  = time();
         $list   = $model::alias('a')
                 ->join('product_pledge b', 'a.pledge_id = b.id', 'left')
                 ->where('a.user_id', $user_id)
                 ->where('a.status', '>', $model::Close)
+                ->where('a.end_time', '<', $time)
                 ->field('a.*,b.day_num')
                 ->select();
 
         if(empty($list)) throw new Exception('暂无质押订单');
         $day   = 86400;
         $total = 0; //当前累计收益
-        $time  = time();
         foreach ($list as $item) 
         {
             //解冻

+ 4 - 1
application/api/logic/WelfareLoginc.php

@@ -149,7 +149,7 @@ class WelfareLoginc
     }
 
     //推广空投产品
-    public static function setUserEcologyAirdrop(int $uid, int $productId): bool
+    public static function setUserEcologyAirdrop(int $uid, int $productId, int $parentId): bool
     {
         $ecology = config('ecology');
         if(!in_array($productId, $ecology['product_id'])){
@@ -173,6 +173,9 @@ class WelfareLoginc
             }
         }
 
+        //发放层级奖励
+        
+
         //发放标记茶宝
         Loader::model('LedgerWalletModel')->changeWalletAccount($uid, Asset::FROZEN, $ecology['frozen'], LedgerFrozenChangeModel::Ecology, 0);
         //修改生态节点标识

+ 4 - 1
application/common/model/LedgerTeacChangeModel.php

@@ -18,6 +18,7 @@ class LedgerTeacChangeModel extends Model
     const BuySell          = 4;
     const SellCancel       = 5;
     const Exchange         = 6;
+    const PledgeFee        = 7; //存储服务费
     /*
      * 支付状态
      * 0未支付 100支付中 200支付成功 400支付失败
@@ -31,6 +32,7 @@ class LedgerTeacChangeModel extends Model
         self::BuySell          => '存储出售',
         self::SellCancel       => '取消出售',
         self::SellCancel       => '兑换产品',
+        self::PledgeFee        => '存储服务费',
     ];
 
     //getStatusList
@@ -43,7 +45,8 @@ class LedgerTeacChangeModel extends Model
             self::Buying    => __('存储'),
             self::BuySell   => __('存储出售'),
             self::SellCancel   => __('取消出售'),
-            self::Exchange     =>__('兑换产品') 
+            self::Exchange     =>__('兑换产品') ,
+            self::PledgeFee    =>__('存储服务费'),
         ];
     }
 

+ 5 - 2
application/common/model/LedgerTokenChangeModel.php

@@ -30,7 +30,8 @@ class LedgerTokenChangeModel extends Model
      const Buying            = 16; //求购购买
      const BuySellg          = 17; //求购出售
      const BuyCancel         = 18; //求购取消
- 
+     const Pledge            = 19; //存储服务费
+
      /*
       * 支付状态
       * 0未支付 100支付中 200支付成功 400支付失败
@@ -51,6 +52,7 @@ class LedgerTokenChangeModel extends Model
          self::Community         => '社区津贴',
          self::Service           => '服务津贴',
          self::Together          => '共创津贴',
+         self::Pledge            => '存储服务费',
        
      ];
 
@@ -76,7 +78,8 @@ class LedgerTokenChangeModel extends Model
             self::Super => __('茶宝标记激活'),
             self::Buying => __('求购购买'),
             self::BuySellg => __('求购出售'),
-            self::BuyCancel => __('求购取消')
+            self::BuyCancel => __('求购取消'),
+            self::Pledge => __('存储服务费'),
            ];
     }
    

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

@@ -34,14 +34,16 @@ class UserPledge extends Model
     const Ongoing= 1;
     const Remove = 2;
 
+    //添加存储
     public static function setPledgeData($user_id, $pledge_id, $product_id, $product,$day_num, $num)
-    {
+    {   
         return self::create([
             'user_id'   => $user_id,
             'pledge_id' => $pledge_id,
             'product_id' => $product_id,
             'details'    => json_encode($product, JSON_UNESCAPED_UNICODE),
             'day_num'    => $day_num,
+            'end_time'   => time() + config('pledge_end_time'), //结束时间
             'num'        => $num
         ]);
     }

+ 3 - 5
application/config.php

@@ -322,6 +322,8 @@ return [
     'withdraw_in_amount' => 300, //提现金额手续费600
     'super_weal_end_time' => 168 * 3600, //168小时
     'min_frozen'          => 9.9, //最小保留标记金额
+    'pledge_end_time'     => 24 * 3600 * 30, //质押存储结束时间 30天
+    'pledge_single_max'   => 3, //单品最大数量
     //提现说明
     'withdraw_desc'       => "
         1.茶宝提现指的是将茶宝转化为 USDT,并提到指定地址。<br/>
@@ -361,11 +363,7 @@ return [
             2.成交顺序以发起求购成功的时间,顺序成交。<br/>
             3.求购期间成交,无法撤销。',   //求购说明
     ],
-    //福利对换配置
-    'welfare_rede_desc' => '1.转账数量务必准确,多转或者少转都会导致兑换失败。<BR>
-                            2.转入的 USDT 需为币安链钱包地址上的。<BR>
-                            3.每个地址最多可兑换 2 套。<BR>
-                            4.开放兑换时间:6 月 1 日~6 月 10 日。',
+  
     //生态节点推广
     'ecology' => [
         'product_id'    => [17],//购买指定产品

+ 3 - 0
public/assets/js/backend/product/pledges.js

@@ -34,7 +34,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'to_lang', title: __('To_lang'), searchList: {"en":__('英文'),"zh":__('中文')}, formatter: Table.api.formatter.label},
                         {field: 'day_num', title: __('Day_num')},
                         {field: 'income_reta', title: __('Income_reta'), operate: false},
+                        {field: 'token', title: __('Token'), operate: false},
+                        {field: 'teac', title: __('Teac'), operate: false},
                         {field: 'weigh', title: __('Weigh'), operate: false},
+                        {field: 'is_renew', title: __('续费'), searchList: {0:__('关闭'),1 :__('开启')}, formatter: Table.api.formatter.toggle},
                         {field: 'status', title: __('Status'), searchList: {0:__('关闭'),1 :__('正常')}, formatter: Table.api.formatter.toggle},
                         {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                         {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},