Commit e6d907e3 authored by hj's avatar hj

更新

parent 042711fd
......@@ -134,4 +134,15 @@ class RhawnProductRepositoryEloquent extends BaseRepository implements RhawnProd
}
return null;
}
public function getProductIsHotByPid($pid)
{
$promotions = DB::connection($this->getConnectionName())
->raw("SELECT sum(`pstk_num` - `pstk_lock_num`) as `real_num` FROM `pstock` where `si_ids` = '' AND `p_id` = ".$pid)->getValue();
if($promotions){
$promotions = $promotions->toArray();
return $promotions;
}
return null;
}
}
......@@ -124,25 +124,28 @@ class RhawnProductService
public function getProductsWithPromotionsByCas($cas)
{
try{
$returnProducts = [];
$products = $this->rhawnProductRepository->getProductsByCas($cas);
if($products){
$products = current($products);
$promotions = $this->rhawnProductRepository->getProductPromotionByPid($products['p_id']);
$productPromotions = [];
if($promotions){
foreach($promotions as $promotion){
$productPromotions[$promotion->p_id] = $promotion;
foreach($products as $product){
$promotions = $this->rhawnProductRepository->getProductPromotionByPid($product['p_id']);
$productPromotions = [];
if($promotions){
foreach($promotions as $promotion){
$productPromotions[$promotion->p_id] = $promotion;
}
}
}
$products['m_price'] = $products['p_price'];
if(!empty($productPromotions) && isset($productPromotions[$products['p_id']])){
$pPromotions = $productPromotions[$products['p_id']];
if($pPromotions->pt_discount != 0){
$products['p_price'] = round($pPromotions->pt_discount * $products['p_price']);
$product['m_price'] = $product['p_price'];
if(!empty($productPromotions) && isset($productPromotions[$product['p_id']])){
$pPromotions = $productPromotions[$product['p_id']];
if($pPromotions->pt_discount != 0){
$product['p_price'] = round($pPromotions->pt_discount * $product['p_price']);
}
}
$returnProducts[] = $product;
}
}
return $products;
return $returnProducts;
}catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':getProductsWithPromotionsByCas ','error');
return null;
......
......@@ -68,8 +68,8 @@ class RhawnProductsService
try{
$products = $this->rhawnProductService->getProductsWithPromotionsByCas($requestParams['cas']);
if($products){
$products = app(ProductsTransformer::class)->transform([$products],'bycas');
$products = current($products);
$products = app(ProductsTransformer::class)->transform($products,'bycas');
//$products = current($products);
}
return $products;
}catch(\Throwable $exception){
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment