afa 7 månader sedan
förälder
incheckning
d474b72405

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

@@ -155,7 +155,7 @@ class Market extends Api
         try {
 
             // 记录出售订单
-            $chabao =$userBuying::getCreateUserBuying($this->auth->id, $params['buying_id'], $buying->user_id, $buying->min_price);
+            $chabao =$userBuying::getCreateUserBuying($this->auth->id, $params['buying_id'], $params['order_id'], $buying->user_id, $buying->min_price);
 
             // 添加扣除茶币
             $ledgerWalletModel->changeWalletAccount($this->auth->id,  Asset::TOKEN, $chabao, LedgerTokenChangeModel::BuySellg, $buying->user_id);

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

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

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

@@ -89,18 +89,22 @@ class ProductOrder extends Model
     }
 
     //合成订单
-    public static function setSynthesisOrder($synthesis, $productId, $num, $uid):bool
+    public static function setSynthesisOrder($synthesis, $productId, $num, $uid):array
     {
-        $result = true;
+        $result = array();
         foreach ($productId as $key => $item) {
 
             //获取需求数量
-            if(!isset($synthesis[$key.'_num'])) throw new Exception(__("参数有误,无可用产品"));;
+            if(!isset($synthesis[$key.'_num'])) throw new Exception(__("参数有误,无可用产品"));
             //判断持有数量足够
             $total_num = $synthesis[$key.'_num'] * $num;
-            if($total_num > self::getUserOrderNum($uid, $item)) throw new Exception(__("材料不足"));;
+            
+            $order_arr = self::getUserOrderByProductNum($uid, $item, $total_num);
+            if($total_num != count($order_arr)) throw new Exception(__("材料不足"));
+
             //关闭持有订单
-            $result = self::where('user_id', $uid)->where('product_id', $item)->where('status', self::Paid)->limit($total_num)->setField('status', self::Closure);
+            self::whereIn('id', $order_arr)->setField('status', self::Closure);
+            $result[$key][] = ['combine'=>$item, 'new_order'=>$order_arr];
         }
         return $result;
     }
@@ -151,6 +155,11 @@ class ProductOrder extends Model
         return  self::where('user_id', $uid)->where('product_id', $product_id)->where('status', '=', self::Paid)->sum('num');
     }
 
+    //获取持有产品数量订单
+    private 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');
+    }
 
 
     // 获取订单状态

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

@@ -42,12 +42,13 @@ class UserBuying  extends Model
     ];
 
     //出售记录
-    public static function getCreateUserBuying(int $uid, int $orderId, int $fromId, float $amount)
+    public static function getCreateUserBuying(int $uid, int $orderId, int $buyingId, int $fromId, float $amount)
     {
         $fee = bcmul(config('market_transfer.serve_fee'), $amount, 2);
         $income = bcsub($amount, $fee, 2);
         self::create([
             'user_id'       => $uid,
+            'buying_id'     => $buyingId,
             'order_id'      => $orderId,
             'from_id'       => $fromId,
             'amount'        => $amount,