|
|
@@ -479,6 +479,88 @@ class ProductClass extends BaseClass
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取零售客户当前清单中各花材的限购情况(Redis 键为 hd_limit_buy:,与批发商 limit_buy_ 区分)
|
|
|
+ * @param array $list 花材列表,项含 id 及 bigCount/smallCount 或 bigNum/smallNum
|
|
|
+ * @param int|string $customId 零售端 xhCustom.id(花店客户)
|
|
|
+ */
|
|
|
+ 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 = \bizGhs\product\classes\ProductClass::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 = \bizGhs\product\classes\ProductClass::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,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $respond;
|
|
|
+ }
|
|
|
+
|
|
|
//取消限购的缓存
|
|
|
public static function cancelLimitBuy($productId)
|
|
|
{
|