본문으로 건너뛰기

네이버쇼핑 상품평 평점 컬럼 추가

PHP 7 · GODO25
변경 파일 수: 3개
변경 파일 목록
총 3개
변경 파일 코드
추가삭제
Component/Worker/DbUrl.php+123
변경 전DbUrl.php
use Component\Board\ArticleListAdmin;
use Component\Board\Board;
use Component\Board\BoardList;
 
use Component\Coupon\Coupon;
use Component\Database\DBTableField;
use Component\Delivery\Delivery;
public $totalDburlData;
public $totalDburlPage;
public $dburl_max_count;
 
 
public function __construct()
{
$result .= '<<<revct>>>' . $reviewCnt . chr(13) . chr(10);
}
 
 
 
$result .= '<<<deliv>>>' . gd_isset($deliveryPrice) . chr(13) . chr(10); // [선택] 배송비
 
if (gd_isset($installationCosts)) $result .= '<<<insco>>>' . gd_isset($installationCosts) . chr(13) . chr(10); // 추가설치비용
 
return $reviewCnt;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
}
 
변경 후DbUrl.php
use Component\Board\ArticleListAdmin;
use Component\Board\Board;
use Component\Board\BoardList;
use Component\Board\BoardUtil;
use Component\Coupon\Coupon;
use Component\Database\DBTableField;
use Component\Delivery\Delivery;
public $totalDburlData;
public $totalDburlPage;
public $dburl_max_count;
protected $useGoodsReviewBoardPt;
 
public function __construct()
{
$result .= '<<<revct>>>' . $reviewCnt . chr(13) . chr(10);
}
 
$result .= '<<<satisfylevel>>>' . $this->getNaverSatisfyLevel($data['goodsNo']) . chr(13) . chr(10); // [선택] 상품 평균 평점
 
$result .= '<<<deliv>>>' . gd_isset($deliveryPrice) . chr(13) . chr(10); // [선택] 배송비
 
if (gd_isset($installationCosts)) $result .= '<<<insco>>>' . gd_isset($installationCosts) . chr(13) . chr(10); // 추가설치비용
 
return $reviewCnt;
}
 
/**
* 네이버쇼핑 EP satisfylevel(상품 단위 평균 평점) 산출
*
* '네이버 쇼핑 상품평 개수' 설정(naverReviewChannel)과 동일한 소스에서 평점을 집계한다.
* both 는 평균의 평균이 아닌 (두 소스 평점 합계의 합 ÷ 두 소스 평점 입력 리뷰 수의 합)으로 계산한다.
*
* @param int $goodsNo 상품 번호
*
* @return float 소수 첫째 자리 반올림 평균 평점 (평점 입력 리뷰가 없으면 0)
*/
protected function getNaverSatisfyLevel(int $goodsNo): float
{
if (empty($goodsNo)) {
return 0;
}
 
if ($this->configData['naverReviewChannel'] === 'plusReview') {
$rating = $this->getReviewRating(DB_PLUS_REVIEW_ARTICLE, $goodsNo, ['applyFl' => 'y']);
} elseif ($this->configData['naverReviewChannel'] === 'both') {
$plusRating = $this->getReviewRating(DB_PLUS_REVIEW_ARTICLE, $goodsNo, ['applyFl' => 'y']);
$boardRating = ['sumGoodsPt' => 0, 'ratedCnt' => 0];
if ($this->useGoodsReviewBoardPoint()) {
$boardRating = $this->getReviewRating(DB_BD_ . 'goodsreview', $goodsNo, ['isDelete' => 'n', 'isSecret' => 'n']);
}
$rating = [
'sumGoodsPt' => $plusRating['sumGoodsPt'] + $boardRating['sumGoodsPt'],
'ratedCnt' => $plusRating['ratedCnt'] + $boardRating['ratedCnt'],
];
} else {
if (!$this->useGoodsReviewBoardPoint()) {
return 0;
}
$rating = $this->getReviewRating(DB_BD_ . 'goodsreview', $goodsNo, ['isDelete' => 'n', 'isSecret' => 'n']);
}
 
return $this->calculateSatisfyLevel($rating['sumGoodsPt'], $rating['ratedCnt']);
}
 
/**
* 평점 합계와 평점 입력 리뷰 수로 satisfylevel 계산
*
* @param float $sumGoodsPt 평점 합계
* @param int $ratedCnt 평점 입력(goodsPt > 0) 리뷰 수
*
* @return float 소수 첫째 자리 반올림 평균 평점 (모수가 없으면 0)
*/
protected function calculateSatisfyLevel(float $sumGoodsPt, int $ratedCnt): float
{
if ($ratedCnt <= 0) {
return 0;
}
 
return round($sumGoodsPt / $ratedCnt, 1);
}
 
/**
* 리뷰 평점 합계·평점 입력 리뷰 수 집계
*
* 집계 제외 조건은 NaverDbUrl::getReviewCounting() 과 동일하며, 평점 미입력(goodsPt = 0)
* 리뷰와 외부 유입 네이버 리뷰(externalNaverReviewFl = 'y')는 합계·모수에서 모두 제외한다.
*
* @param string $tableName 리뷰 테이블명
* @param int $goodsNo 상품 번호
* @param array $addWhere key-value 형태 추가 조건
*
* @return array sumGoodsPt(평점 합계), ratedCnt(평점 입력 리뷰 수)
*/
protected function getReviewRating(string $tableName, int $goodsNo, array $addWhere): array
{
$arrBind = $arrWhere = $arrOrWhere = [];
 
$this->db->strField = 'SUM(goodsPt) AS sumGoodsPt, COUNT(*) AS ratedCnt';
$arrWhere[] = "goodsNo = ?";
$this->db->bind_param_push($arrBind, 'i', $goodsNo);
$arrWhere[] = "goodsPt > 0";
 
if (!empty($addWhere)) {
foreach ($addWhere as $key => $value) {
$arrWhere[] = $key . " = ? ";
$this->db->bind_param_push($arrBind, 's', $value);
}
}
 
// 외부 유입 네이버 리뷰는 리뷰 개수 집계와 동일하게 평점 모수에서도 제외 (컬럼 NULL 과거 데이터 포함)
$arrWhere[] = "(externalNaverReviewFl != 'y' OR externalNaverReviewFl IS NULL)";
 
// 네이버페이 주문형 리뷰는 EP 전송 제외 대상이라 평점 산정에서 제외
$arrOrWhere[] = "(channel != 'naverpay' AND memNo > 0)";
if ($tableName === DB_BD_ . 'goodsreview') {
$arrOrWhere[] = "(channel IS NULL AND memNo > 0)";
}
 
$this->db->strWhere = implode(' AND ', $arrWhere) . " AND (" . implode(' OR ', $arrOrWhere) . ")";
 
$query = $this->db->query_complete();
$strSQL = 'SELECT ' . array_shift($query) . ' FROM ' . $tableName . implode(' ', $query);
$resultSet = $this->db->query_fetch($strSQL, $arrBind, false);
 
return [
'sumGoodsPt' => (float)$resultSet['sumGoodsPt'],
'ratedCnt' => (int)$resultSet['ratedCnt'],
];
}
 
/**
* 상품후기 게시판의 별점(점수) 사용 여부
*
* @return bool
*/
protected function useGoodsReviewBoardPoint(): bool
{
if ($this->useGoodsReviewBoardPt === null) {
$boardConfig = BoardUtil::getData(Board::BASIC_GOODS_REIVEW_ID);
$this->useGoodsReviewBoardPt = isset($boardConfig['bdGoodsPtFl']) && $boardConfig['bdGoodsPtFl'] == 'y';
}
 
return $this->useGoodsReviewBoardPt;
}
}
 
Component/Worker/NaverDbUrl3.php+2-1
변경 전NaverDbUrl3.php
{
/** @var array $header naver dburl 3.0 header */
//@formatter:off
protected $header = ['id','title','price_pc','normal_price','link','image_link','add_image_link','category_name1','category_name2','category_name3','category_name4','naver_category','naver_product_id','condition','import_flag','parallel_import','order_made','product_flag','rental_info','adult','brand','maker','origin','event_words','partner_coupon_download','interest_free_event',' point','installation_costs','search_tag','minimum_purchase_quantity','review_count','shipping','delivery_grade','delivery_detail','attribute','age_group','gender','npay_unable','npay_unable_acum','brand_certification','shipping_settings','unit_price'];
//@formatter:on
/** @var array $mobileConfig mobile.config policy */
protected $mobileConfig = [];
$totalcnt = StringUtils::strIsSet($this->getNaverReviewCount($goods), 0) . chr(9);
}
$result .= $totalcnt;
 
 
$result .= StringUtils::strIsSet($deliveryPrice) . chr(9); // [선택] 배송비
$result .= StringUtils::strIsSet($deliveryGrade) . chr(9); // 배송 · 설치비용
 
변경 후NaverDbUrl3.php
{
/** @var array $header naver dburl 3.0 header */
//@formatter:off
protected $header = ['id','title','price_pc','normal_price','link','image_link','add_image_link','category_name1','category_name2','category_name3','category_name4','naver_category','naver_product_id','condition','import_flag','parallel_import','order_made','product_flag','rental_info','adult','brand','maker','origin','event_words','partner_coupon_download','interest_free_event',' point','installation_costs','search_tag','minimum_purchase_quantity','review_count','satisfylevel','shipping','delivery_grade','delivery_detail','attribute','age_group','gender','npay_unable','npay_unable_acum','brand_certification','shipping_settings','unit_price'];
//@formatter:on
/** @var array $mobileConfig mobile.config policy */
protected $mobileConfig = [];
$totalcnt = StringUtils::strIsSet($this->getNaverReviewCount($goods), 0) . chr(9);
}
$result .= $totalcnt;
$result .= $this->getNaverSatisfyLevel($goods['goodsNo']) . chr(9); // [선택] 상품 평균 평점
 
$result .= StringUtils::strIsSet($deliveryPrice) . chr(9); // [선택] 배송비
$result .= StringUtils::strIsSet($deliveryGrade) . chr(9); // 배송 · 설치비용
 
Component/Worker/NaverDbUrl.php+125
변경 전NaverDbUrl.php
 
 
use Bundle\Component\Board\Board;
 
use Framework\Utility\NumberUtils;
use Framework\Utility\StringUtils;
use Monolog\Formatter\LineFormatter;
{
protected $salesIndexDbUrl, $salesDate, $db, $salesPath;
protected $salesHeader = ['mall_id', 'sale_count', 'sale_price', 'order_count', 'dt'];
 
 
/**
* DbUrl 정책 호출
if (($reviewCnt = $this->getNaverReviewCount($goods)) > 0) {
$this->writeDbUrl('<<<revct>>>' . $reviewCnt);
}
 
$this->writeDbUrl('<<<deliv>>>' . StringUtils::strIsSet($deliveryPrice)); // [선택] 배송비
if (StringUtils::strIsSet($installationCosts)) {
$this->writeDbUrl('<<<insco>>>' . StringUtils::strIsSet($installationCosts)); // 추가설치비용
return $reviewCnt;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**
* salesIndexInit
*
 
변경 후NaverDbUrl.php
 
 
use Bundle\Component\Board\Board;
use Component\Board\BoardUtil;
use Framework\Utility\NumberUtils;
use Framework\Utility\StringUtils;
use Monolog\Formatter\LineFormatter;
{
protected $salesIndexDbUrl, $salesDate, $db, $salesPath;
protected $salesHeader = ['mall_id', 'sale_count', 'sale_price', 'order_count', 'dt'];
protected $useGoodsReviewBoardPt;
 
/**
* DbUrl 정책 호출
if (($reviewCnt = $this->getNaverReviewCount($goods)) > 0) {
$this->writeDbUrl('<<<revct>>>' . $reviewCnt);
}
$this->writeDbUrl('<<<satisfylevel>>>' . $this->getNaverSatisfyLevel($goods['goodsNo'])); // [선택] 상품 평균 평점
$this->writeDbUrl('<<<deliv>>>' . StringUtils::strIsSet($deliveryPrice)); // [선택] 배송비
if (StringUtils::strIsSet($installationCosts)) {
$this->writeDbUrl('<<<insco>>>' . StringUtils::strIsSet($installationCosts)); // 추가설치비용
return $reviewCnt;
}
 
/**
* 네이버쇼핑 EP satisfylevel(상품 단위 평균 평점) 산출
*
* '네이버 쇼핑 상품평 개수' 설정(naverReviewChannel)과 동일한 소스에서 평점을 집계한다.
* both 는 평균의 평균이 아닌 (두 소스 평점 합계의 합 ÷ 두 소스 평점 입력 리뷰 수의 합)으로 계산한다.
*
* @param int $goodsNo 상품 번호
*
* @return float 소수 첫째 자리 반올림 평균 평점 (평점 입력 리뷰가 없으면 0)
*/
protected function getNaverSatisfyLevel(int $goodsNo): float
{
if (empty($goodsNo)) {
return 0;
}
 
if ($this->config['naverReviewChannel'] === 'plusReview') {
$rating = $this->getReviewRating(DB_PLUS_REVIEW_ARTICLE, $goodsNo, ['applyFl' => 'y']);
} elseif ($this->config['naverReviewChannel'] === 'both') {
$plusRating = $this->getReviewRating(DB_PLUS_REVIEW_ARTICLE, $goodsNo, ['applyFl' => 'y']);
$boardRating = ['sumGoodsPt' => 0, 'ratedCnt' => 0];
if ($this->useGoodsReviewBoardPoint()) {
$boardRating = $this->getReviewRating(DB_BD_ . 'goodsreview', $goodsNo, ['isDelete' => 'n', 'isSecret' => 'n']);
}
$rating = [
'sumGoodsPt' => $plusRating['sumGoodsPt'] + $boardRating['sumGoodsPt'],
'ratedCnt' => $plusRating['ratedCnt'] + $boardRating['ratedCnt'],
];
} else {
if (!$this->useGoodsReviewBoardPoint()) {
return 0;
}
$rating = $this->getReviewRating(DB_BD_ . 'goodsreview', $goodsNo, ['isDelete' => 'n', 'isSecret' => 'n']);
}
 
return $this->calculateSatisfyLevel($rating['sumGoodsPt'], $rating['ratedCnt']);
}
 
/**
* 평점 합계와 평점 입력 리뷰 수로 satisfylevel 계산
*
* @param float $sumGoodsPt 평점 합계
* @param int $ratedCnt 평점 입력(goodsPt > 0) 리뷰 수
*
* @return float 소수 첫째 자리 반올림 평균 평점 (모수가 없으면 0)
*/
protected function calculateSatisfyLevel(float $sumGoodsPt, int $ratedCnt): float
{
if ($ratedCnt <= 0) {
return 0;
}
 
return round($sumGoodsPt / $ratedCnt, 1);
}
 
/**
* 리뷰 평점 합계·평점 입력 리뷰 수 집계
*
* 집계 제외 조건은 getReviewCounting() 과 동일하며, 평점 미입력(goodsPt = 0) 리뷰와
* 외부 유입 네이버 리뷰(externalNaverReviewFl = 'y')는 합계·모수에서 모두 제외한다.
*
* @param string $tableName 리뷰 테이블명
* @param int $goodsNo 상품 번호
* @param array $addWhere key-value 형태 추가 조건
*
* @return array sumGoodsPt(평점 합계), ratedCnt(평점 입력 리뷰 수)
*/
protected function getReviewRating(string $tableName, int $goodsNo, array $addWhere): array
{
if ($this->db === null) {
$this->db = \App::load('DB');
}
$arrBind = $arrWhere = $arrOrWhere = [];
 
$this->db->strField = 'SUM(goodsPt) AS sumGoodsPt, COUNT(*) AS ratedCnt';
$arrWhere[] = "goodsNo = ?";
$this->db->bind_param_push($arrBind, 'i', $goodsNo);
$arrWhere[] = "goodsPt > 0";
 
if (!empty($addWhere)) {
foreach ($addWhere as $key => $value) {
$arrWhere[] = $key . " = ? ";
$this->db->bind_param_push($arrBind, 's', $value);
}
}
 
// 외부 유입 네이버 리뷰는 리뷰 개수 집계와 동일하게 평점 모수에서도 제외 (컬럼 NULL 과거 데이터 포함)
$arrWhere[] = "(externalNaverReviewFl != 'y' OR externalNaverReviewFl IS NULL)";
 
// 네이버페이 주문형 리뷰는 EP 전송 제외 대상이라 평점 산정에서 제외
$arrOrWhere[] = "(channel != 'naverpay' AND memNo > 0)";
if ($tableName === DB_BD_ . 'goodsreview') {
$arrOrWhere[] = "(channel IS NULL AND memNo > 0)";
}
 
$this->db->strWhere = implode(' AND ', $arrWhere) . " AND (" . implode(' OR ', $arrOrWhere) . ")";
 
$query = $this->db->query_complete();
$strSQL = 'SELECT ' . array_shift($query) . ' FROM ' . $tableName . implode(' ', $query);
$resultSet = $this->db->query_fetch($strSQL, $arrBind, false);
 
return [
'sumGoodsPt' => (float)$resultSet['sumGoodsPt'],
'ratedCnt' => (int)$resultSet['ratedCnt'],
];
}
 
/**
* 상품후기 게시판의 별점(점수) 사용 여부
*
* @return bool
*/
protected function useGoodsReviewBoardPoint(): bool
{
if ($this->useGoodsReviewBoardPt === null) {
$boardConfig = BoardUtil::getData(Board::BASIC_GOODS_REIVEW_ID);
$this->useGoodsReviewBoardPt = isset($boardConfig['bdGoodsPtFl']) && $boardConfig['bdGoodsPtFl'] == 'y';
}
 
return $this->useGoodsReviewBoardPt;
}
 
/**
* salesIndexInit
*