Commit e6d907e3 authored by hj's avatar hj

更新

parent 042711fd
...@@ -134,4 +134,15 @@ class RhawnProductRepositoryEloquent extends BaseRepository implements RhawnProd ...@@ -134,4 +134,15 @@ class RhawnProductRepositoryEloquent extends BaseRepository implements RhawnProd
} }
return null; 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 ...@@ -124,25 +124,28 @@ class RhawnProductService
public function getProductsWithPromotionsByCas($cas) public function getProductsWithPromotionsByCas($cas)
{ {
try{ try{
$returnProducts = [];
$products = $this->rhawnProductRepository->getProductsByCas($cas); $products = $this->rhawnProductRepository->getProductsByCas($cas);
if($products){ if($products){
$products = current($products); foreach($products as $product){
$promotions = $this->rhawnProductRepository->getProductPromotionByPid($products['p_id']); $promotions = $this->rhawnProductRepository->getProductPromotionByPid($product['p_id']);
$productPromotions = []; $productPromotions = [];
if($promotions){ if($promotions){
foreach($promotions as $promotion){ foreach($promotions as $promotion){
$productPromotions[$promotion->p_id] = $promotion; $productPromotions[$promotion->p_id] = $promotion;
}
} }
} $product['m_price'] = $product['p_price'];
$products['m_price'] = $products['p_price']; if(!empty($productPromotions) && isset($productPromotions[$product['p_id']])){
if(!empty($productPromotions) && isset($productPromotions[$products['p_id']])){ $pPromotions = $productPromotions[$product['p_id']];
$pPromotions = $productPromotions[$products['p_id']]; if($pPromotions->pt_discount != 0){
if($pPromotions->pt_discount != 0){ $product['p_price'] = round($pPromotions->pt_discount * $product['p_price']);
$products['p_price'] = round($pPromotions->pt_discount * $products['p_price']); }
} }
$returnProducts[] = $product;
} }
} }
return $products; return $returnProducts;
}catch(\Throwable $exception){ }catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':getProductsWithPromotionsByCas ','error'); SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':getProductsWithPromotionsByCas ','error');
return null; return null;
......
...@@ -68,8 +68,8 @@ class RhawnProductsService ...@@ -68,8 +68,8 @@ class RhawnProductsService
try{ try{
$products = $this->rhawnProductService->getProductsWithPromotionsByCas($requestParams['cas']); $products = $this->rhawnProductService->getProductsWithPromotionsByCas($requestParams['cas']);
if($products){ if($products){
$products = app(ProductsTransformer::class)->transform([$products],'bycas'); $products = app(ProductsTransformer::class)->transform($products,'bycas');
$products = current($products); //$products = current($products);
} }
return $products; return $products;
}catch(\Throwable $exception){ }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