|
|
@@ -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');
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// 获取订单状态
|