|
|
@ -40,29 +40,21 @@ class GoodsActivityService implements GoodsActivityServiceInterface |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
if (empty($goods)) { |
|
|
if (empty($goods)) { |
|
|
$message = ErrorCode::getMessage(ErrorCode::GOODS_ACTIVITY_NOT_EXISTS); |
|
|
|
|
|
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION_LOG_DATA, ['message' => $message, 'buy_num' => $num, 'user_id' => $userId, 'logData' => json_encode($goods)]); |
|
|
|
|
|
return ErrorCode::GOODS_ACTIVITY_NOT_EXISTS; |
|
|
return ErrorCode::GOODS_ACTIVITY_NOT_EXISTS; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 活动是否已经结束
|
|
|
// 活动是否已经结束
|
|
|
if ($goods->expire_time < time()) { |
|
|
if ($goods->expire_time < time()) { |
|
|
$message = ErrorCode::getMessage(ErrorCode::GOODS_ACTIVITY_EXPIRED); |
|
|
|
|
|
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION_LOG_DATA, ['message' => $message, 'buy_num' => $num, 'user_id' => $userId, 'logData' => json_encode($goods)]); |
|
|
|
|
|
return ErrorCode::GOODS_ACTIVITY_EXPIRED; |
|
|
return ErrorCode::GOODS_ACTIVITY_EXPIRED; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 商户歇业
|
|
|
// 商户歇业
|
|
|
if($goods->store->is_rest == 1){ |
|
|
if($goods->store->is_rest == 1){ |
|
|
$message = ErrorCode::getMessage(ErrorCode::STORE_REST); |
|
|
|
|
|
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION_LOG_DATA, ['message' => $message, 'buy_num' => $num, 'user_id' => $userId, 'logData' => json_encode($goods)]); |
|
|
|
|
|
return ErrorCode::STORE_REST; |
|
|
return ErrorCode::STORE_REST; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 商品下架或已删除
|
|
|
// 商品下架或已删除
|
|
|
if($goods->on_sale == 0 || !is_null($goods->deleted_at)){ |
|
|
if($goods->on_sale == 0 || !is_null($goods->deleted_at)){ |
|
|
$message = ErrorCode::getMessage(ErrorCode::GOODS_ACTIVITY_ON_SALE_NO); |
|
|
|
|
|
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION_LOG_DATA, ['message' => $message, 'buy_num' => $num, 'user_id' => $userId, 'logData' => json_encode($goods)]); |
|
|
|
|
|
return ErrorCode::GOODS_ACTIVITY_ON_SALE_NO; |
|
|
return ErrorCode::GOODS_ACTIVITY_ON_SALE_NO; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -71,15 +63,11 @@ class GoodsActivityService implements GoodsActivityServiceInterface |
|
|
$inventoryFrozen = $this->goodsInventoryService->getSold(2, $goods->id); |
|
|
$inventoryFrozen = $this->goodsInventoryService->getSold(2, $goods->id); |
|
|
// $inventoryFrozen = 0;
|
|
|
// $inventoryFrozen = 0;
|
|
|
if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){ |
|
|
if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){ |
|
|
$message = ErrorCode::getMessage(ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR); |
|
|
|
|
|
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION_LOG_DATA, ['message' => $message, 'buy_num' => $num, 'activity_type' => 2, 'inventoryFrozen' => $inventoryFrozen, 'user_id' => $userId, 'logData' => json_encode($goods)]); |
|
|
|
|
|
return ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR; |
|
|
return ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 是否超过限购数量
|
|
|
// 是否超过限购数量
|
|
|
if ($goods->restrict_num != 0 && $goods->restrict_num < $num) { |
|
|
if ($goods->restrict_num != 0 && $goods->restrict_num < $num) { |
|
|
$message = ErrorCode::getMessage(ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT); |
|
|
|
|
|
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION_LOG_DATA, ['message' => $message, 'buy_num' => $num, 'user_id' => $userId, 'logData' => json_encode($goods)]); |
|
|
|
|
|
return ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT; |
|
|
return ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -87,8 +75,6 @@ class GoodsActivityService implements GoodsActivityServiceInterface |
|
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); |
|
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); |
|
|
$hasBuy = $ssdb->exec('get', SsdbKeys::ACTIVITY_GOODS_BUY_RECORD.$userId.'_'.$goods->type.'_'.$goods->id); |
|
|
$hasBuy = $ssdb->exec('get', SsdbKeys::ACTIVITY_GOODS_BUY_RECORD.$userId.'_'.$goods->type.'_'.$goods->id); |
|
|
if ($hasBuy && $hasBuy >= $goods->time_limit_num) { |
|
|
if ($hasBuy && $hasBuy >= $goods->time_limit_num) { |
|
|
$message = ErrorCode::getMessage(ErrorCode::GOODS_ACTIVITY_BUY); |
|
|
|
|
|
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION_LOG_DATA, ['message' => $message, 'has_buy' => $hasBuy, 'ssdb_key' => SsdbKeys::ACTIVITY_GOODS_BUY_RECORD.$userId.'_'.$goods->type.'_'.$goods->id, 'buy_num' => $num, 'user_id' => $userId, 'logData' => json_encode($goods)]); |
|
|
|
|
|
return ErrorCode::GOODS_ACTIVITY_BUY; |
|
|
return ErrorCode::GOODS_ACTIVITY_BUY; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|