afa 6 сар өмнө
parent
commit
1b1d831f3b

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

@@ -84,7 +84,7 @@ class Synthesis extends Api
         try {
           
             // 合成订单
-            $order_list = $productOrder->setSynthesisOrder($synthesis, $productList, $num, $this->auth->id);
+            $order_list = WelfareLoginc::setSynthesisOrder($synthesis, $productList, $num, $this->auth->id);
 
             // 添加新订单
             WelfareLoginc::setUserProductOrder($num, 0, $synthesis->id, 0, $synthesis->product_id, $this->auth->id, $productOrder::Synthesi);

+ 1 - 1
application/api/logic/MarketLogic.php

@@ -5,7 +5,7 @@ namespace app\api\logic;
 use Exception;
 use think\Env;
 use think\Cache;
-use think\Loader ;
+use think\Loader;
 use app\common\model\ProductOrder;
 use app\common\model\ProductLists;
 use app\common\model\ProductTransfer;

+ 27 - 15
application/api/logic/WelfareLoginc.php

@@ -9,6 +9,7 @@ use app\common\model\UserWelfare;
 use app\common\model\ProductPopular;
 use app\common\model\ProductOrder;
 use app\common\model\UserModel;
+use think\Loader;
 use think\Db;
 use think\Log;
 use Exception;
@@ -49,15 +50,8 @@ class WelfareLoginc
      */
     public static function getUserRwaProductNum(int $productId, int $rwa_num, $mod, $num): int
     {   
-        //读取当日新增数据
-        $list = ProductOrder::where('product_id', $productId)
-        ->whereIn('status', [ProductOrder::Paid, ProductOrder::Transferred, ProductOrder::Freeze])
-        //->where('popular_price', '>', config('min_rwa_price'))
-        ->field('user_id,sum(num) as total_num')
-        ->group('user_id')
-        ->field('user_id,count(num) as total_num')
-        ->group('user_id')
-        ->having('total_num>='.$rwa_num)->select();
+        //读取当前新增数据
+        $list = ProductOrder::getUserOrderByProductId($productId, $rwa_num);
         if(empty($list)) return 0;
         $total = 0; //总数量
         if($mod == 1 && $num > 0){
@@ -88,12 +82,8 @@ class WelfareLoginc
         $total = 0; //总数量
         // 使用bcdiv函数进行高精度除法运算,$num除以100,保留两位小数
         $div = bcdiv($num, 100, 2);
-        $list = ProductOrder::whereIn('status', [ProductOrder::Paid, ProductOrder::Transferred, ProductOrder::Freeze])
-            ->where('product_id', $rwaProductId)
-            //->where('popular_price', '>', config('min_rwa_price'))
-            ->group('user_id')->having('total_num>='.$rwa_num)
-            ->field('id,user_id,count(num) as total_num')
-            ->select();
+        $list = ProductOrder::getUserOrderByProductId($rwaProductId, $rwa_num);
+
         $user = new UserModel();
         foreach($list as $order){
                 //根据$mod的值决定是否需要对用户的rwa_num进行乘以$div的运算
@@ -108,6 +98,28 @@ class WelfareLoginc
        return $total;
     }
 
+    //合成订单
+    public static function setSynthesisOrder($synthesis, $productId, $num, $uid):array
+    {
+        $result = array();
+        $model = Loader::model('ProductOrder');
+        foreach ($productId as $key => $item) {
+
+            //获取需求数量
+            if(!isset($synthesis[$key.'_num'])) throw new Exception(__("参数有误,无可用产品"));
+            //判断持有数量足够
+            $total_num = $synthesis[$key.'_num'] * $num;
+            
+            $order_arr = $model::getUserOrderByProductNum($uid, $item, $total_num);
+            if($total_num != count($order_arr)) throw new Exception(__("材料不足"));
+
+            //关闭持有订单
+            $model::whereIn('id', $order_arr)->setField('status', $model::Closure);
+            $result[$key][] = ['combine'=>$item, 'new_order'=>$order_arr];
+        }
+        return $result;
+    }
+
 
     /**
      * 设置用户产品订单

+ 14 - 25
application/common/model/ProductOrder.php

@@ -86,26 +86,7 @@ class ProductOrder extends Model
         return $result;
     }
 
-    //合成订单
-    public static function setSynthesisOrder($synthesis, $productId, $num, $uid):array
-    {
-        $result = array();
-        foreach ($productId as $key => $item) {
-
-            //获取需求数量
-            if(!isset($synthesis[$key.'_num'])) throw new Exception(__("参数有误,无可用产品"));
-            //判断持有数量足够
-            $total_num = $synthesis[$key.'_num'] * $num;
-            
-            $order_arr = self::getUserOrderByProductNum($uid, $item, $total_num);
-            if($total_num != count($order_arr)) throw new Exception(__("材料不足"));
-
-            //关闭持有订单
-            self::whereIn('id', $order_arr)->setField('status', self::Closure);
-            $result[$key][] = ['combine'=>$item, 'new_order'=>$order_arr];
-        }
-        return $result;
-    }
+  
 
     /**
      * @param int   $orderId 订单id
@@ -147,18 +128,26 @@ class ProductOrder extends Model
         return $productId;
     }
 
-    //获取持有产品数量
-    private static function getUserOrderNum(int $uid, int $product_id): int
-    {
-        return  self::where('user_id', $uid)->where('product_id', $product_id)->where('status', '=', self::Paid)->sum('num');
+    //空投产品向达到一定持有量的用户
+    public static function getUserOrderByProductId(int $rwaProductId, int $rwaNum){
+        return ProductOrder::whereIn('status', [self::Paid, self::Transferred, self::Freeze])
+        ->where('product_id', $rwaProductId)
+        ->group('user_id')->having('total_num>='.$rwaNum)
+        ->field('id,user_id,count(num) as total_num')
+        ->select();
     }
 
     //获取持有产品数量订单
-    private static function getUserOrderByProductNum(int $uid, int $product_id, int $totalNum): array
+    public static function getUserOrderByProductNum(int $uid, int $product_id, int $totalNum): array
     {
         return  self::where('user_id', $uid)->where('product_id', $product_id)->where('status', '=', self::Paid)->limit($totalNum)->column('id');
     }
 
+    //获取持有产品数量
+    private static function getUserOrderNum(int $uid, int $product_id): int
+    {
+        return  self::where('user_id', $uid)->where('product_id', $product_id)->where('status', '=', self::Paid)->sum('num');
+    }
 
     // 获取订单状态
     public static function getProductOrder($orderId, $status, string $field){