app/Customize/Service/ReviewService.php line 178

Open in your IDE?
  1. <?php
  2. /**
  3.  * @version EC=CUBE4
  4.  * @copyright 株式会社 翔 kakeru.co.jp
  5.  * @author
  6.  * 2022年08月18日作成
  7.  *
  8.  * app/Customize/Service/ReviewService.php
  9.  *
  10.  *
  11.  * レヴュージサービス
  12.  *
  13.  *
  14.  *                               C= C= C= ┌(;・_・)┘トコトコ
  15.  ******************************************************/
  16. namespace Customize\Service;
  17. use Lm\Service\Db\SqlService;
  18. use Lm\Engine\EC\Entity\GoodsWithRelated;
  19. class ReviewService{
  20.     const REVIEW_GET_MAX 50;
  21.     public function __construct()
  22.     {
  23.     $this->Sql = new SqlService();
  24.     }
  25.     /**
  26.      * @var SqlService $Sql
  27.      */
  28.     protected $Sql;
  29.     /**
  30.      * 未使用 $main_category_id = null, $category_id = null, $limit = '', $offset = 0
  31.      * sex ege 使われていない
  32.      */
  33.     public function GetReview($id, &$count null$limit GoodsWithRelated::REVIEW_GET_MAX$offset 0){
  34.         return GoodsWithRelated::getReviewListById($id$limit$offset$count);
  35.     }
  36.     protected function getGoodsLinkSelectSql($data$count false)
  37.     {
  38.         if (is_array($data)) {
  39.             $whereGoods "target_goods_id IN (" implode(","$data) . ")";
  40.         } else {
  41.             $whereGoods "target_goods_id = " $data;
  42.         }
  43.         $max = ($count 0) ? $count 14;
  44.         $Sql = new SqlService();
  45.         $results $Sql->Table('goods_link_table AS T')
  46.             ->Select('DISTINCT T.goods_id, T1.goods_canonical_hinban, IFNULL(T1.goods_canonical_hinban, T1.goods_id) AS item_id, T.goods_name, T.goods_count, T.min_gp_price, T.count_gp_price')
  47.             ->Join('goods_table AS T1''T.goods_id = T1.goods_id''INNER')
  48.             ->Set('T1.goods_ddate'NULL)
  49.             ->Set('T1.goods_status'1)
  50.             ->Where($whereGoods)
  51.             ->Order('T.goods_count''DESC')
  52.             ->Limit('0'$max)
  53.             ->FindAll();
  54.         // 表示価格 (gp_display != 99) の最安値に min_gp_price を上書き
  55.         if (!empty($results)) {
  56.             foreach ($results as &$row) {
  57.                 $priceSql = new SqlService();
  58.                 $minPrice $priceSql->Table('goods_price_table')
  59.                     ->Select('MIN(gp_price2) AS min_price')
  60.                     ->Set('gp_goods'$row['goods_id'])
  61.                     ->Where('gp_display != 99')
  62.                     ->Find();
  63.                 if (!empty($minPrice['min_price'])) {
  64.                     $row['min_gp_price'] = $minPrice['min_price'];
  65.                 }
  66.             }
  67.             unset($row); // 明示的に参照解除
  68.         } else {
  69.             // 必要であればログなどで追跡できるようにする
  70.             error_log('getGoodsLinkSelectSql returned null');
  71.         }
  72.         return $results;
  73.     }
  74.     // 口コミ平均評価取得
  75.     protected function getReviewAverageSql($goods_id=null)
  76.     {
  77.         $Sql = new SqlService();
  78.         if($goods_id){
  79.             $whereGoods "cra_goods_id =".$goods_id;
  80.         }
  81.         return  $Sql->Table('customer_review_average_table')
  82.                     ->Select('cra_goods_id,cra_average_points,cra_target_count')
  83.                     ->Where('cra_target_count >= 1')
  84.                     ->Where($whereGoods)
  85.                     ->FindAll();
  86.     }
  87.     protected function getReviewAverage($goods_id=null) {
  88.         $temp $this->getReviewAverageSql($goods_id);
  89.         $average = array();
  90.         foreach((array)$temp as $data){
  91.             $average[$data['cra_goods_id']] = $data['cra_average_points'];
  92.         }
  93.         return $average;
  94.     }
  95.     protected function getReviewSql($id$isSecret true$main_category_id null$category_id null$limit ''$offset 0)
  96.     {
  97.         $SELECT = !empty($limit) ? "SELECT SQL_CALC_FOUND_ROWS" "SELECT";
  98.         $sql "$SELECT
  99.                 DISTINCT
  100.                 cr_oh_id
  101.                 ,cr_goods_id
  102.                 ,cr_customer_id
  103.                 ,cr_name
  104.                 ,cr_points
  105.                 ,cr_title
  106.                 ,cr_comment
  107.                 ,cr_staff_comment
  108.                 ,CASE cr_age
  109.                     WHEN '1' THEN '10代'
  110.                     WHEN '2' THEN '20代'
  111.                     WHEN '3' THEN '30代'
  112.                     WHEN '4' THEN '40代'
  113.                     WHEN '5' THEN '50代'
  114.                     WHEN '6' THEN '60代'
  115.                     ELSE '秘密'
  116.                  END cr_age
  117.                 ,CASE cr_sex
  118.                     WHEN '0' THEN '男性'
  119.                     WHEN '1' THEN '女性'
  120.                     ELSE '秘密'
  121.                  END cr_sex
  122.                 ,cr_approval
  123.                 ,app_datetime
  124.                 ,upd_datetime
  125.                 ,add_datetime
  126.                 ,goods_name
  127.                 ,(SELECT min(gp_kataban) FROM goods_price_table where cr_goods_id = gp_goods GROUP BY gp_goods) as gp_kataban
  128.                 FROM customer_review_table
  129.                 LEFT JOIN goods_table ON goods_id = cr_goods_id
  130.                 WHERE cr_approval = '1' AND cr_site_id = 0";
  131.         if (!empty($id) && empty($main_category_id)) {
  132.             // 商品ページのみに表示
  133.             $sql .= " AND cr_goods_id = {$id}
  134.                       AND cr_main_category_id = 0
  135.                       AND EXISTS (
  136.                         SELECT * FROM goods_table WHERE goods_id = {$id} AND goods_ddate IS NULL";
  137.             if(!$isSecret){
  138.                 $sql .= " AND goods_status = 1 ";
  139.             }
  140.             $sql .= " )";
  141.         } else if (!empty($main_category_id) && empty($category_id)) {
  142.             // 親カテページのみに表示
  143.             $sql .= " AND cr_main_category_id = {$main_category_id}
  144.                       AND cr_category_id = 0";
  145.         } else if (!empty($main_category_id) && !empty($category_id)) {
  146.             // 子カテページのみに表示
  147.             $sql .= " AND cr_main_category_id = {$main_category_id}
  148.                       AND cr_category_id = '{$category_id}'";
  149.         }
  150.         $sql .= " ORDER BY `customer_review_table`.`app_datetime` desc";
  151.         if (!empty($limit)) {
  152.             // 商品ページのみに表示
  153.             $sql .= " LIMIT {$offset}{$limit}";
  154.         }
  155.         return $this->Sql->SQL($sql)->FetchAll();
  156.     }
  157.     public function LM_displayTogetherBuyDetail_new3 ($goods_id$count false)
  158.     {
  159.         // 一緒に購入されている商品
  160.         $result = array();
  161.         $temp $this->getGoodsLinkSelectSql($goods_id$count);
  162.         if($temp){
  163.             foreach ($temp as $row) {
  164.                 $goodsId $row['goods_id'];
  165.                 $result[$goodsId] = $row;
  166.                 $result[$goodsId]['min_gp_price_inc_tax'] = round($row['min_gp_price'] * 1.1);
  167.                 $average $this->getReviewAverage($row['goods_id']);
  168.                 $average = (!empty($average[$row['goods_id']])) ? $average[$row['goods_id']] : 0;
  169.                 $image_name = (int)($average 2) / 10;
  170.                 $result[$goodsId]['average'] = $average;
  171.                 $result[$goodsId]['average_img'] = "<img class=\"history-average-img\" alt=\"お客様からの口コミレビュー評価の星の数{$average}\" src=\"/images/review/star_m".$image_name.".gif\">";
  172.                 $count=0;
  173.                 if($tempRow $this->getReviewSql($row['goods_id'])) $count=count($tempRow);
  174.                 $result[$goodsId]['review_count'] = $count;
  175.                 $result[$goodsId]['img'] = "/goods.img/"substr($goodsId, -11) . "/" $goodsId "/main.jpg";
  176.             }
  177.         }
  178.         return $result;
  179.     }
  180.     public function getReviewExists($ohId$goodsId$customerId)
  181.     {
  182.         $result = (new SqlService())
  183.             ->Select('cr_id')
  184.             ->Table('customer_review_table')
  185.             ->Set('cr_oh_id'$ohId)
  186.             ->Set('cr_goods_id'$goodsId)
  187.             ->Set('cr_customer_id'$customerId)
  188.             ->Find();
  189.         return $result;
  190.     }
  191.     public function insertReview($values)
  192.     {
  193.         $sql = new SqlService();
  194.         $sql->Table('customer_review_table')
  195.             ->Insert(false$values);
  196.     }
  197. }