|
|
@@ -1496,8 +1496,12 @@ class ProductClass extends BaseClass
|
|
|
if ($book == 1 && $customShopAdminId > 0) {
|
|
|
$itemPrice = 0.1;
|
|
|
} else {
|
|
|
+ $limitKey = self::LIMIT_BUY_KEY . $ghsProductId;
|
|
|
+ $hasBuyNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $custom['id']]);
|
|
|
+ $hasBuyNum = $itemNum + ($hasBuyNum == null ? 0 : $hasBuyNum); // 已购买总数量
|
|
|
+
|
|
|
//今日特价、会员价
|
|
|
- $itemPrice = self::getFinalPrice($currentGhsProduct, $level, $priceMap, $addPriceMap, $changePrice, $itemNum);
|
|
|
+ $itemPrice = self::getFinalPrice($currentGhsProduct, $level, $priceMap, $addPriceMap, $changePrice, $itemNum, $hasBuyNum);
|
|
|
}
|
|
|
$thisPrice = $itemPrice;
|
|
|
|
|
|
@@ -3003,6 +3007,84 @@ class ProductClass extends BaseClass
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ // 获取客户当前采购清单中各花材的限购情况
|
|
|
+ public static function getLimitBuyInfoByList($list, $customId)
|
|
|
+ {
|
|
|
+ if (empty($list) || !is_array($list)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ $buyNumMap = [];
|
|
|
+ $ids = [];
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $productId = $item['id'] ?? 0;
|
|
|
+ if (empty($productId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $productId = intval($productId);
|
|
|
+ $bigNum = $item['bigCount'] ?? ($item['bigNum'] ?? 0);
|
|
|
+ $smallNum = $item['smallCount'] ?? ($item['smallNum'] ?? 0);
|
|
|
+ if (isset($buyNumMap[$productId]) == false) {
|
|
|
+ $buyNumMap[$productId] = [
|
|
|
+ 'bigNum' => 0,
|
|
|
+ 'smallNum' => 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $buyNumMap[$productId]['bigNum'] = bcadd($buyNumMap[$productId]['bigNum'], $bigNum, 2);
|
|
|
+ $buyNumMap[$productId]['smallNum'] = bcadd($buyNumMap[$productId]['smallNum'], $smallNum, 2);
|
|
|
+ $ids[] = $productId;
|
|
|
+ }
|
|
|
+
|
|
|
+ $ids = array_values(array_unique($ids));
|
|
|
+ if (empty($ids)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ $productData = self::getProductByIds($ids);
|
|
|
+ $productData = array_column($productData, null, 'id');
|
|
|
+ $respond = [];
|
|
|
+ foreach ($ids as $productId) {
|
|
|
+ $product = $productData[$productId] ?? [];
|
|
|
+ if (empty($product)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $limitBuy = $product['limitBuy'] ?? 0;
|
|
|
+ $isLimit = $limitBuy > 0 ? true : false;
|
|
|
+ $hasBuyNum = 0;
|
|
|
+ if ($isLimit) {
|
|
|
+ $limitKey = self::LIMIT_BUY_KEY . $productId;
|
|
|
+ $hasBuyNum = Yii::$app->redis->executeCommand('HGET', [$limitKey, $customId]);
|
|
|
+ $hasBuyNum = $hasBuyNum == null ? 0 : $hasBuyNum;
|
|
|
+ }
|
|
|
+
|
|
|
+ $buyNum = $buyNumMap[$productId] ?? [];
|
|
|
+ $ratio = $product['ratio'] ?? 1;
|
|
|
+ $currentBuyNum = self::mergeItemNum($buyNum['bigNum'] ?? 0, $buyNum['smallNum'] ?? 0, $ratio);
|
|
|
+ $totalBuyNum = bcadd($hasBuyNum, $currentBuyNum, 2);
|
|
|
+ $specialPrice = (
|
|
|
+ ($product['hjDiscountPrice'] ?? 0) > 0
|
|
|
+ && ($product['discountPrice'] ?? 0) > 0
|
|
|
+ && ($product['skDiscountPrice'] ?? 0) > 0
|
|
|
+ ) ? true : false;
|
|
|
+
|
|
|
+ $respond[] = [
|
|
|
+ 'id' => $productId,
|
|
|
+ 'name' => $product['name'] ?? '',
|
|
|
+ 'isLimit' => $isLimit, //是否限购
|
|
|
+ 'limitBuy' => (float)$limitBuy, //限购数量
|
|
|
+ 'specialPrice' => $specialPrice, //是否特价
|
|
|
+ 'hasBuyNum' => $isLimit ? (float)$hasBuyNum : 0, //已购买数量
|
|
|
+ 'currentBuyNum' => (float)$currentBuyNum, //此次购买的数量
|
|
|
+ 'reachLimitBuyNum' => ($isLimit && $totalBuyNum > $limitBuy) ? true : false, //是否达到限购数量
|
|
|
+ 'exceedNum' => $isLimit ? (float)bcsub($hasBuyNum, $limitBuy, 2) : 0, //超出数量, 小于等于0表示未超出
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $respond;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 限购处理
|
|
|
* @param $product
|