|
|
@@ -288,22 +288,32 @@ class GroupBuyActivityClass extends BaseClass
|
|
|
* @param int $mainId
|
|
|
* @param int $shopId
|
|
|
* @param int $activityGoodsId
|
|
|
+ * @param bool $strict true 时按原因抛错:活动未开始/已结束、商品已下架
|
|
|
* @return array|null
|
|
|
*/
|
|
|
- public static function getActiveGoodsRowById($mainId, $shopId, $activityGoodsId)
|
|
|
+ public static function getActiveGoodsRowById($mainId, $shopId, $activityGoodsId, $strict = false)
|
|
|
{
|
|
|
$mainId = intval($mainId);
|
|
|
$shopId = intval($shopId);
|
|
|
$activityGoodsId = intval($activityGoodsId);
|
|
|
if ($mainId <= 0 || $activityGoodsId <= 0) {
|
|
|
+ if ($strict) {
|
|
|
+ util::fail('请选择团购商品');
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
$row = GroupBuyGoodsClass::getById($activityGoodsId, true);
|
|
|
- if (empty($row) || intval($row->mainId) !== $mainId || intval($row->delStatus) !== 0 || intval($row->status) !== 1) {
|
|
|
+ if (empty($row) || intval($row->mainId) !== $mainId) {
|
|
|
+ if ($strict) {
|
|
|
+ util::fail('商品已下架');
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
$activity = self::getById(intval($row->activityId), true);
|
|
|
if (empty($activity) || intval($activity->mainId) !== $mainId || intval($activity->delStatus) !== 0) {
|
|
|
+ if ($strict) {
|
|
|
+ util::fail('团购活动已结束');
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
$enabled = HomePageConfigClass::getModuleEnabled($mainId, $shopId, 'groupBuy');
|
|
|
@@ -313,6 +323,15 @@ class GroupBuyActivityClass extends BaseClass
|
|
|
$enabled
|
|
|
);
|
|
|
if ($status !== 1) {
|
|
|
+ if ($strict) {
|
|
|
+ self::failIfActivityNotRunning($status);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (intval($row->delStatus) !== 0 || intval($row->status) !== 1) {
|
|
|
+ if ($strict) {
|
|
|
+ util::fail('商品已下架');
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
return [
|
|
|
@@ -341,24 +360,44 @@ class GroupBuyActivityClass extends BaseClass
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 开团/落地页核价:取有效商品行,活动未开始/已结束、商品已下架分别报错
|
|
|
+ *
|
|
|
+ * @param int $mainId
|
|
|
+ * @param int $shopId
|
|
|
+ * @param int $activityGoodsId
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public static function requireActiveGoodsRowById($mainId, $shopId, $activityGoodsId)
|
|
|
+ {
|
|
|
+ return self::getActiveGoodsRowById($mainId, $shopId, $activityGoodsId, true);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 按商品 id 取当前进行中活动的有效商品行
|
|
|
*
|
|
|
* @param int $mainId
|
|
|
* @param int $shopId
|
|
|
* @param int $goodsId
|
|
|
+ * @param bool $strict true 时按原因抛错:活动未开始/已结束、商品已下架
|
|
|
* @return array|null
|
|
|
*/
|
|
|
- public static function getActiveGoodsRowByGoodsId($mainId, $shopId, $goodsId)
|
|
|
+ public static function getActiveGoodsRowByGoodsId($mainId, $shopId, $goodsId, $strict = false)
|
|
|
{
|
|
|
$mainId = intval($mainId);
|
|
|
$shopId = intval($shopId);
|
|
|
$goodsId = intval($goodsId);
|
|
|
if ($mainId <= 0 || $goodsId <= 0) {
|
|
|
+ if ($strict) {
|
|
|
+ util::fail('请选择商品');
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
$activity = self::getCurrentActivity($mainId);
|
|
|
if (empty($activity)) {
|
|
|
+ if ($strict) {
|
|
|
+ util::fail('团购活动已结束');
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
$enabled = HomePageConfigClass::getModuleEnabled($mainId, $shopId, 'groupBuy');
|
|
|
@@ -368,6 +407,9 @@ class GroupBuyActivityClass extends BaseClass
|
|
|
$enabled
|
|
|
);
|
|
|
if ($status !== 1) {
|
|
|
+ if ($strict) {
|
|
|
+ self::failIfActivityNotRunning($status);
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
$row = GroupBuyGoodsClass::getByCondition([
|
|
|
@@ -378,8 +420,37 @@ class GroupBuyActivityClass extends BaseClass
|
|
|
'delStatus' => 0,
|
|
|
], true);
|
|
|
if (empty($row)) {
|
|
|
+ if ($strict) {
|
|
|
+ util::fail('商品已下架');
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
- return self::getActiveGoodsRowById($mainId, $shopId, intval($row->id));
|
|
|
+ return self::getActiveGoodsRowById($mainId, $shopId, intval($row->id), $strict);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 落地页核价:按商品 id 取有效行,活动未开始/已结束、商品已下架分别报错
|
|
|
+ *
|
|
|
+ * @param int $mainId
|
|
|
+ * @param int $shopId
|
|
|
+ * @param int $goodsId
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public static function requireActiveGoodsRowByGoodsId($mainId, $shopId, $goodsId)
|
|
|
+ {
|
|
|
+ return self::getActiveGoodsRowByGoodsId($mainId, $shopId, $goodsId, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 活动非进行中时给出明确错误
|
|
|
+ *
|
|
|
+ * @param int $status 0未开始 1进行中 2已结束
|
|
|
+ */
|
|
|
+ private static function failIfActivityNotRunning($status)
|
|
|
+ {
|
|
|
+ if (intval($status) === 0) {
|
|
|
+ util::fail('团购活动未开始');
|
|
|
+ }
|
|
|
+ util::fail('团购活动已结束');
|
|
|
}
|
|
|
}
|