afa 7 сар өмнө
parent
commit
24b5ba5c9a

+ 10 - 10
application/api/controller/Pledge.php

@@ -66,7 +66,6 @@ class Pledge extends Api
             $product_id = $this->request->param('product_id', 0, 'intval');
             if(empty($product_id)) $this->error(__("参数有误,无可用产品"));
             $pledges = $pledgeLogic::getHoldProductList($this->auth->id, $product_id);
-            
             $this->success('', $pledges);
       }
 
@@ -80,12 +79,13 @@ class Pledge extends Api
         if(empty($pledge_id) || empty($order_no)) $this->error(__("参数有误,无可用产品"));
 
         $pledge = $productPledges::get($pledge_id);
-        if(count(explode(',', $pledge->product_id)) != count($order_no)) $this->error(__("参数有误,无可用产品"));
+        if(count(explode(',', $pledge->product_id)) != count($order_no)) $this->error(__("质押商品数量与订单数量不匹配"));
 
         if (empty($pledge)) $this->error(__("质抵活动不存在"));
         if (empty($pledge->status) )$this->error(__("质抵活动已结束"));
         Db::startTrans();
         try {
+
             // 质抵押订单 
             $pledgeLogic::setPledgeOrder($pledge, $order_no, $this->auth->id);
             // 提交事务
@@ -120,15 +120,13 @@ class Pledge extends Api
       */
       public function collect(PledgeLogic $pledgeLogic)
       {     
-            if($pledgeLogic::getCheckRequestApi('collect', $this->auth->id, 300) == false){
-                  $this->error(__("收取太pio啦,请稍后再试"));
-            }
-           
+            //if($pledgeLogic::getCheckRequestApi('collect', $this->auth->id, 300) == false) $this->error(__("收取太pio啦,请稍后再试"));
+
             Db::startTrans();
             try {
                   // 质抵押订单 
-                  $res = $pledgeLogic::getPledgeOrderList($this->auth->id);
-
+                  $res = $pledgeLogic::getPledgeCollect($this->auth->id);
+      
                  // 提交事务
                   Db::commit();
             } catch (Exception $e) {
@@ -149,9 +147,11 @@ class Pledge extends Api
             Db::startTrans();
             try {
                   // 质抵押订单 
-                  $res = $pledgeLogic::setPledgeRemove($pledge_id, $this->auth->id);
+                  $res = $pledgeLogic::setPledgeRemove($pledge_id,  $this->auth->id);
 
-                 // 提交事务
+                  //解冻
+                  
+                  // 提交事务
                   Db::commit();
             } catch (Exception $e) {
                   // 回滚事务

+ 56 - 11
application/common/logic/PledgeLogic.php

@@ -6,14 +6,16 @@ use Exception;
 use think\Env;
 use think\Cache;
 use think\Loader ;
-use app\common\model\UserPledge;
+use fast\Asset;
+use app\common\model\LedgerTeacChangeModel;
 use app\common\model\ProductPledges;
 
 class PledgeLogic
 {
 
+
   
-    //获取产品信息 user_pledge
+    //获取产品信息
     public  static function getByProductIdList(object $list, string $lan = 'zh')
     {
         $model  = Loader::model('ProductLists');
@@ -37,15 +39,21 @@ class PledgeLogic
     public static function setPledgeOrder(object $pledge, array $order_no, int $user_id)
     {
         $model  = Loader::model('ProductOrder');
-        $order  = $model::where('user_id', $user_id)->whereIn('order_no', $order_no)->select();
-        if(empty($order) || count($order) != count($order_no))  throw new Exception('订单不存在');
+        $product= $model::alias('a')
+            ->join('product_list b', 'a.product_id = b.id', 'left')
+            ->where('a.user_id', $user_id)
+            ->where('a.status', $model::Paid)
+            ->whereIn('a.order_no', $order_no)->column('a.id,b.thum');
+
+        if(empty($product) || count($product) != count($order_no))  throw new Exception('订单不存在');
         $pledge_num = 1;
         if($pledge->type_id == ProductPledges::Single){
-            $pledge_num = count($order);
+            $pledge_num = count($order_no);
         }
-      
         //添加订单 
-        Loader::model('UserPledge')::setPledgeData($user_id, $pledge->id, $pledge->product_id, $pledge->day_num, $pledge_num);
+        Loader::model('UserPledge')::setPledgeData($user_id, $pledge->id, $pledge->product_id, 
+        ['product'=>$product, 'order_no'=>$order_no], //订单信息
+        $pledge->day_num, $pledge_num);
    
         //修改状态
         return $model->whereIn('order_no', $order_no)->setField('status', $model::Freeze);
@@ -56,7 +64,13 @@ class PledgeLogic
     public static function getPledgeOrderList(int $user_id)
     {
         $model  = Loader::model('UserPledge');
-        $list   = $model::where('user_id', $user_id)->where('status', $model::Ongoing)->select();
+        $list   = $model::alias('a')
+            ->join('product_pledge b', 'a.pledge_id = b.id', 'left')
+            ->where('a.user_id', $user_id)
+            ->where('a.status', $model::Ongoing)
+            ->field('a.*,b.title')
+            ->select();
+
         if(empty($list))  throw new Exception('暂无质押订单');
         $day   = 86400;
         $total = 0; //当前累计收益
@@ -65,31 +79,62 @@ class PledgeLogic
         foreach ($list as $item) {
            $reta  = bcdiv($item->day_num, $day, 2); //天数
            $inter = ($item->last_time == 0) ? $time - $item->create_time: $time - $item->last_time; //最后收取时间
-           $total += bcmul($reta, $inter, 2) * $item->num; //累计收益
+           $total += bcmul($reta, $inter, 2)* $item->num; //累计收益
            $growth += $reta* $item->num;
         }
         return ['total' => $total, 'growth' => $growth, 'list' => $list];   
     }
 
     //解除质抵押订单
-    public static function setPledgeRemove(int $pledge_id,int $user_id)
+    public static function setPledgeRemove(int $pledge_id, int $user_id)
     {
         $model  = Loader::model('UserPledge');
         $rows   = $model::where('user_id', $user_id)->where('id', $pledge_id)->where('status', $model::Ongoing)->find();
         if(empty($rows))  throw new Exception('暂无质押订单');
         $day   = 86400;
         $total = 0; //当前累计收益
- 
         $time  = time();
         $reta  = bcdiv($rows->day_num, $day, 2); //天数
         $inter = ($rows->last_time == 0) ? $time - $rows->create_time: $time - $rows->last_time; //最后收取时间
         $total = bcmul($reta, $inter, 2) * $rows->num; //累计收益
         $rows->total_self= bcadd($total, $rows->total_self, 2);
+
+        $model->whereIn('order_no', $rows->order_no)->setField('status', $model::Paid);
+
         $rows->status    = $model::Remove;
         $rows->last_time = $time;
         return  $rows->save();   
     }
+
     
+    //收取质抵押订单列表
+    //(60*60*24)*(当前时间-最后一次收取时间)
+    public static function getPledgeCollect(int $user_id)
+    { 
+        $model  = Loader::model('UserPledge');
+        $list   = $model::where('user_id', $user_id)->where('status', '>', $model::Close)->select();
+        if(empty($list))  throw new Exception('暂无质押订单');
+        $day   = 86400;
+        $total = 0; //当前累计收益
+        $time  = time();
+        foreach ($list as $item) 
+        {
+            //解冻
+            if($item == $model::Remove) {
+                $total = $item->total_self;
+                $item->status = $model::Close; //关闭
+            }else{
+                $reta  = bcdiv($item->day_num, $day, 2); //天数
+                $inter = ($item->last_time == 0) ? $time - $item->create_time: $time - $item->last_time; //最后收取时间
+                $total = bcmul($reta, $inter, 2) * $item->num; //累计收益
+                $item->last_time = $time; //收取时间
+                $item->total_self= bcadd($total, $item->total_self, 2); //累计收益
+            }
+            Loader::model('LedgerWalletModel')->changeWalletAccount($user_id, Asset::TEAC, $item->total_self, LedgerTeacChangeModel::Pledge, 0);
+            $item->save();
+        }
+        return true;   
+    }
 
     //判断请求限制
     public static function getCheckRequestApi(string $key, int $user_id, int $time = 300)

+ 15 - 0
application/common/model/LedgerTeacChangeModel.php

@@ -9,4 +9,19 @@ class LedgerTeacChangeModel extends Model
     // LedgerPowerChangeModel
     protected $name = "ledger_teac_change";
 
+
+    //0支付 1转让支付 2 转让收款 3 充值 4 提现 5扣除书续费
+    const Pledge           = 0;
+ 
+    /*
+     * 支付状态
+     * 0未支付 100支付中 200支付成功 400支付失败
+     */
+    public $pay_status = [
+        '-1'                    => '全部',
+        self::Pledge           => '质押存储',
+
+    ];
+
+
 }

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

@@ -141,8 +141,8 @@ class LedgerWalletModel extends Model
                 $changeModel = new LedgerTokenChangeModel();
                 if($action == self::Giveaway || $action == self::Freight) $frozen = $available->frozen;
                 break;
-            case Asset::DECLARATION:
-                $changeModel = new LedgerDeclarationChangeModel();
+            case Asset::TEAC:
+                $changeModel = new LedgerTeacChangeModel();
                 break;
             case Asset::SMH:
                 $changeModel = new LedgerSmhChangeModel();

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

@@ -167,6 +167,9 @@ class ProductOrder extends Model
                 ->find();
     }
 
+
+
+    
     public static function getStatusList()
     {
         return [self::Ordered => __('已下单'), self::Paid  => __('已付款'), self::Transferred => __('已转让'), 

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

@@ -34,12 +34,13 @@ class UserPledge extends Model
     const Ongoing= 1;
     const Remove = 2;
 
-    public static function setPledgeData($user_id, $pledge_id, $product_id, $day_num, $num)
+    public static function setPledgeData($user_id, $pledge_id, $product, $product_id, $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,
             'num'        => $num
         ]);

+ 2 - 2
extend/fast/Asset.php

@@ -26,10 +26,10 @@ class Asset
     const TOKEN = 'token';
 
     /**
-     * 报单算力
+     * Teac
      * @var string
      */
-    const DECLARATION = 'declaration';
+    const TEAC = 'teac';
 
     /**
      * 服务器算力