|
|
@@ -121,47 +121,25 @@ class HomePageModuleClass
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- public static function saveNavGrid($mainId, $data)
|
|
|
+ /**
|
|
|
+ * 保存金刚区导航;请求形态校验由 SaveNavGridForm 完成
|
|
|
+ *
|
|
|
+ * @param int $mainId
|
|
|
+ * @param array $payload {cols, list}
|
|
|
+ * @param int $enabled
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public static function saveNavGrid($mainId, $payload, $enabled = 0)
|
|
|
{
|
|
|
$mainId = intval($mainId);
|
|
|
if ($mainId <= 0) {
|
|
|
util::fail('无效门店');
|
|
|
}
|
|
|
- $enabled = !empty($data['enabled']) ? 1 : 0;
|
|
|
- $cols = isset($data['cols']) ? intval($data['cols']) : 5;
|
|
|
- if (!in_array($cols, [4, 5], true)) {
|
|
|
- util::fail('排列规则无效');
|
|
|
- }
|
|
|
- $rawList = self::decodeList($data['list'] ?? []);
|
|
|
- if (count($rawList) > self::MAX_NAV_COUNT) {
|
|
|
- util::fail('最多可配置' . self::MAX_NAV_COUNT . '个导航');
|
|
|
- }
|
|
|
- $list = [];
|
|
|
- foreach ($rawList as $index => $item) {
|
|
|
- if (!is_array($item)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $name = trim(strval($item['name'] ?? ''));
|
|
|
- $icon = trim(strval($item['icon'] ?? ''));
|
|
|
- $type = intval($item['type'] ?? 0);
|
|
|
- $value = trim(strval($item['value'] ?? ''));
|
|
|
- $no = $index + 1;
|
|
|
- if ($name === '' || $icon === '' || $value === '') {
|
|
|
- util::fail("请完善第{$no}个导航项");
|
|
|
- }
|
|
|
- if (!in_array($type, [self::LINK_CATEGORY, self::LINK_USE_CASE], true)) {
|
|
|
- util::fail("第{$no}个导航关联类型无效");
|
|
|
- }
|
|
|
- $list[] = [
|
|
|
- 'id' => strval($item['id'] ?? ('nav_' . ($index + 1))),
|
|
|
- 'name' => mb_substr($name, 0, 20),
|
|
|
- 'icon' => $icon,
|
|
|
- 'iconType' => intval($item['iconType'] ?? 1) === 2 ? 2 : 1,
|
|
|
- 'enabled' => !empty($item['enabled']) ? 1 : 0,
|
|
|
- 'type' => $type,
|
|
|
- 'value' => $value,
|
|
|
- ];
|
|
|
+ if (!is_array($payload)) {
|
|
|
+ util::fail('参数错误');
|
|
|
}
|
|
|
+ $cols = isset($payload['cols']) ? intval($payload['cols']) : 5;
|
|
|
+ $list = isset($payload['list']) && is_array($payload['list']) ? $payload['list'] : [];
|
|
|
self::setJson($mainId, self::REDIS_NAV_GRID, ['cols' => $cols, 'list' => $list]);
|
|
|
HomePageConfigClass::updateModuleEnabled($mainId, 'navGrid', $enabled);
|
|
|
return true;
|
|
|
@@ -186,21 +164,33 @@ class HomePageModuleClass
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- public static function saveSeckill($mainId, $data)
|
|
|
+ /**
|
|
|
+ * 保存秒杀专区;请求形态校验由 SaveSeckillForm 完成,此处做商品归属与库存业务校验
|
|
|
+ *
|
|
|
+ * @param int $mainId
|
|
|
+ * @param array $base 已校验的活动基础字段
|
|
|
+ * @param array $goods 已校验的商品列表(形态)
|
|
|
+ * @param int $enabled
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public static function saveSeckill($mainId, $base, $goods = [], $enabled = 0)
|
|
|
{
|
|
|
$mainId = intval($mainId);
|
|
|
if ($mainId <= 0) {
|
|
|
util::fail('无效门店');
|
|
|
}
|
|
|
- $base = self::validateActivityBase($data);
|
|
|
- $goods = self::validateSeckillGoods($mainId, self::decodeList($data['goods'] ?? []));
|
|
|
+ if (!is_array($base)) {
|
|
|
+ util::fail('参数错误');
|
|
|
+ }
|
|
|
+ $goods = self::validateSeckillGoods($mainId, is_array($goods) ? $goods : []);
|
|
|
self::setJson($mainId, self::REDIS_SECKILL, array_merge($base, ['goods' => $goods]));
|
|
|
- HomePageConfigClass::updateModuleEnabled($mainId, 'seckill', !empty($data['enabled']) ? 1 : 0);
|
|
|
+ HomePageConfigClass::updateModuleEnabled($mainId, 'seckill', $enabled);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 校验并规范化秒杀商品;秒杀库存不得超过实际商品库存
|
|
|
+ * 业务校验并规范化秒杀商品:归属当前门店,秒杀库存不得超过实际商品库存
|
|
|
+ * 字段形态校验由 SaveSeckillForm 完成
|
|
|
*/
|
|
|
public static function validateSeckillGoods($mainId, $rawList)
|
|
|
{
|
|
|
@@ -214,18 +204,6 @@ class HomePageModuleClass
|
|
|
$price = floatval($item['price'] ?? 0);
|
|
|
$stock = intval($item['stock'] ?? 0);
|
|
|
$limit = intval($item['limit'] ?? 0);
|
|
|
- if ($goodsId <= 0) {
|
|
|
- util::fail("请选择第{$no}个秒杀商品");
|
|
|
- }
|
|
|
- if ($price <= 0) {
|
|
|
- util::fail("请填写第{$no}个秒杀价格");
|
|
|
- }
|
|
|
- if ($stock <= 0) {
|
|
|
- util::fail("请填写第{$no}个秒杀库存");
|
|
|
- }
|
|
|
- if ($limit <= 0) {
|
|
|
- util::fail("请填写第{$no}个单人限购");
|
|
|
- }
|
|
|
$goods = GoodsClass::getById($goodsId, true);
|
|
|
if (empty($goods) || intval($goods->mainId ?? 0) !== intval($mainId)) {
|
|
|
util::fail("第{$no}个秒杀商品无效");
|
|
|
@@ -441,19 +419,34 @@ class HomePageModuleClass
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- public static function saveGroupBuy($mainId, $data)
|
|
|
+ /**
|
|
|
+ * 保存团购专区;请求形态校验由 SaveGroupBuyForm 完成,此处做商品归属与库存业务校验
|
|
|
+ *
|
|
|
+ * @param int $mainId
|
|
|
+ * @param array $base 已校验的活动基础字段
|
|
|
+ * @param array $goods 已校验的商品列表(形态)
|
|
|
+ * @param int $enabled
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public static function saveGroupBuy($mainId, $base, $goods = [], $enabled = 0)
|
|
|
{
|
|
|
$mainId = intval($mainId);
|
|
|
if ($mainId <= 0) {
|
|
|
util::fail('无效门店');
|
|
|
}
|
|
|
- $base = self::validateActivityBase($data);
|
|
|
- $goods = self::validateGroupBuyGoods($mainId, self::decodeList($data['goods'] ?? []));
|
|
|
+ if (!is_array($base)) {
|
|
|
+ util::fail('参数错误');
|
|
|
+ }
|
|
|
+ $goods = self::validateGroupBuyGoods($mainId, is_array($goods) ? $goods : []);
|
|
|
self::setJson($mainId, self::REDIS_GROUP_BUY, array_merge($base, ['goods' => $goods]));
|
|
|
- HomePageConfigClass::updateModuleEnabled($mainId, 'groupBuy', !empty($data['enabled']) ? 1 : 0);
|
|
|
+ HomePageConfigClass::updateModuleEnabled($mainId, 'groupBuy', $enabled);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 业务校验并规范化团购商品:归属当前门店,库存不得超过实际商品库存
|
|
|
+ * 字段形态校验由 SaveGroupBuyForm 完成
|
|
|
+ */
|
|
|
public static function validateGroupBuyGoods($mainId, $rawList)
|
|
|
{
|
|
|
$list = [];
|
|
|
@@ -467,12 +460,6 @@ class HomePageModuleClass
|
|
|
$stock = intval($item['stock'] ?? 0);
|
|
|
$limit = intval($item['limit'] ?? 0);
|
|
|
$groupSize = intval($item['groupSize'] ?? 3);
|
|
|
- if (!in_array($groupSize, [2, 3, 5], true)) {
|
|
|
- util::fail("第{$no}个成团人数无效");
|
|
|
- }
|
|
|
- if ($goodsId <= 0 || $price <= 0 || $stock <= 0 || $limit <= 0) {
|
|
|
- util::fail("请完善第{$no}个团购商品");
|
|
|
- }
|
|
|
$goods = GoodsClass::getById($goodsId, true);
|
|
|
if (empty($goods) || intval($goods->mainId ?? 0) !== intval($mainId)) {
|
|
|
util::fail("第{$no}个团购商品无效");
|
|
|
@@ -483,9 +470,6 @@ class HomePageModuleClass
|
|
|
}
|
|
|
$virtualGroup = !empty($item['virtualGroup']) ? 1 : 0;
|
|
|
$virtualMinutes = intval($item['virtualMinutes'] ?? 0);
|
|
|
- if ($virtualGroup && $virtualMinutes <= 0) {
|
|
|
- util::fail("请填写第{$no}个虚拟成团时间");
|
|
|
- }
|
|
|
$list[] = [
|
|
|
'goodsId' => $goodsId,
|
|
|
'price' => round($price, 2),
|
|
|
@@ -577,37 +561,29 @@ class HomePageModuleClass
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- public static function saveGoodsSection($mainId, $moduleKey, $data)
|
|
|
+ /**
|
|
|
+ * 保存热门/上新/下拉商品;请求形态校验由 SaveGoodsSectionForm 完成
|
|
|
+ *
|
|
|
+ * @param int $mainId
|
|
|
+ * @param string $moduleKey hot|new|pullGoods
|
|
|
+ * @param array $payload {name,type,value,sort}
|
|
|
+ * @param int $enabled
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public static function saveGoodsSection($mainId, $moduleKey, $payload, $enabled = 0)
|
|
|
{
|
|
|
$mainId = intval($mainId);
|
|
|
$suffix = self::sectionSuffix($moduleKey);
|
|
|
- $name = trim(strval($data['name'] ?? ''));
|
|
|
- $type = intval($data['type'] ?? 0);
|
|
|
- $value = trim(strval($data['value'] ?? ''));
|
|
|
- $sort = intval($data['sort'] ?? self::SORT_PRODUCT);
|
|
|
- // layoutCols/displayCount 由读取时按真实商品数量自动推导,保存时不再接收商家手动配置
|
|
|
- if ($name === '') {
|
|
|
- util::fail('请输入首页展示名称');
|
|
|
- }
|
|
|
- if (mb_strlen($name) > 20) {
|
|
|
- util::fail('展示名称不能超过20字');
|
|
|
- }
|
|
|
- if (!in_array($type, [self::LINK_GOODS, self::LINK_CATEGORY, self::LINK_USE_CASE], true)) {
|
|
|
- util::fail('关联类型无效');
|
|
|
- }
|
|
|
- if ($value === '') {
|
|
|
- util::fail('请选择关联内容');
|
|
|
- }
|
|
|
- if (!in_array($sort, [self::SORT_PRODUCT, self::SORT_SALES, self::SORT_NEW], true)) {
|
|
|
- util::fail('排序规则无效');
|
|
|
+ if (!is_array($payload)) {
|
|
|
+ util::fail('参数错误');
|
|
|
}
|
|
|
self::setJson($mainId, $suffix, [
|
|
|
- 'name' => $name,
|
|
|
- 'type' => $type,
|
|
|
- 'value' => $value,
|
|
|
- 'sort' => $sort,
|
|
|
+ 'name' => strval($payload['name'] ?? ''),
|
|
|
+ 'type' => intval($payload['type'] ?? 0),
|
|
|
+ 'value' => strval($payload['value'] ?? ''),
|
|
|
+ 'sort' => intval($payload['sort'] ?? self::SORT_PRODUCT),
|
|
|
]);
|
|
|
- HomePageConfigClass::updateModuleEnabled($mainId, $moduleKey, !empty($data['enabled']) ? 1 : 0);
|
|
|
+ HomePageConfigClass::updateModuleEnabled($mainId, $moduleKey, $enabled);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -877,49 +853,6 @@ class HomePageModuleClass
|
|
|
return ['layoutCols' => 3, 'displayCount' => 3];
|
|
|
}
|
|
|
|
|
|
- public static function validateActivityBase($data)
|
|
|
- {
|
|
|
- $title = trim(strval($data['title'] ?? ''));
|
|
|
- $subtitle = trim(strval($data['subtitle'] ?? ''));
|
|
|
- $desc = trim(strval($data['desc'] ?? ''));
|
|
|
- $startTime = intval($data['startTime'] ?? 0);
|
|
|
- $endTime = intval($data['endTime'] ?? 0);
|
|
|
- // layoutCols/displayCount 由读取时按商品数量自动推导,保存时不再接收商家手动配置
|
|
|
- if ($title === '') {
|
|
|
- util::fail('请输入活动标题');
|
|
|
- }
|
|
|
- if (mb_strlen($title) > 10) {
|
|
|
- util::fail('活动标题不能超过10字');
|
|
|
- }
|
|
|
- if ($subtitle === '') {
|
|
|
- util::fail('请输入活动副标题');
|
|
|
- }
|
|
|
- if (mb_strlen($subtitle) > 20) {
|
|
|
- util::fail('活动副标题不能超过20字');
|
|
|
- }
|
|
|
- if ($startTime <= 0 || $endTime <= 0) {
|
|
|
- util::fail('请选择活动时间');
|
|
|
- }
|
|
|
- if ($endTime <= $startTime) {
|
|
|
- util::fail('结束时间必须大于开始时间');
|
|
|
- }
|
|
|
- if ($desc === '') {
|
|
|
- util::fail('请输入活动说明');
|
|
|
- }
|
|
|
- if (mb_strlen($desc) > 500) {
|
|
|
- util::fail('活动说明不能超过500字');
|
|
|
- }
|
|
|
- return [
|
|
|
- 'title' => $title,
|
|
|
- 'subtitle' => $subtitle,
|
|
|
- 'showCountdown' => !empty($data['showCountdown']) ? 1 : 0,
|
|
|
- 'expand' => !empty($data['expand']) ? 1 : 0,
|
|
|
- 'startTime' => $startTime,
|
|
|
- 'endTime' => $endTime,
|
|
|
- 'desc' => $desc,
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 活动状态:0未开始 1进行中 2已结束;模块关闭视为已结束展示用
|
|
|
*/
|