app/Customize/Service/ReviewService.php line 154

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.         if ($count 0) {
  44.             $max $count;
  45.         } else {
  46.             $max 14;
  47.         }
  48.         $Sql = new SqlService();
  49.         return  $Sql->Table('goods_link_table')
  50.                     ->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, min_gp_price, count_gp_price')
  51.                     ->Join('goods_table','T.goods_id = T1.goods_id','INNER')
  52.                     ->Set('T1.goods_ddate'NULL)
  53.                     ->Set('T1.goods_status',1)
  54.                     ->Where($whereGoods)
  55.                     ->Order('T.goods_count','DESC')
  56.                     ->Limit('0',$max)
  57.                     ->FindAll();
  58.     }
  59.     // 口コミ平均評価取得
  60.     protected function getReviewAverageSql($goods_id=null)
  61.     {
  62.         $Sql = new SqlService();
  63.         if($goods_id){
  64.             $whereGoods "cra_goods_id =".$goods_id;
  65.         }
  66.         return  $Sql->Table('customer_review_average_table')
  67.                     ->Select('cra_goods_id,cra_average_points,cra_target_count')
  68.                     ->Where('cra_target_count >= 1')
  69.                     ->Where($whereGoods)
  70.                     ->FindAll();
  71.     }
  72.     protected function getReviewAverage($goods_id=null) {
  73.         $temp $this->getReviewAverageSql($goods_id);
  74.         $average = array();
  75.         foreach((array)$temp as $data){
  76.             $average[$data['cra_goods_id']] = $data['cra_average_points'];
  77.         }
  78.         return $average;
  79.     }
  80.     protected function getReviewSql($id$isSecret true$main_category_id null$category_id null$limit ''$offset 0)
  81.     {
  82.         $SELECT = !empty($limit) ? "SELECT SQL_CALC_FOUND_ROWS" "SELECT";
  83.         $sql "$SELECT
  84.                 DISTINCT
  85.                 cr_oh_id
  86.                 ,cr_goods_id
  87.                 ,cr_customer_id
  88.                 ,cr_name
  89.                 ,cr_points
  90.                 ,cr_title
  91.                 ,cr_comment
  92.                 ,cr_staff_comment
  93.                 ,CASE cr_age
  94.                     WHEN '1' THEN '10代'
  95.                     WHEN '2' THEN '20代'
  96.                     WHEN '3' THEN '30代'
  97.                     WHEN '4' THEN '40代'
  98.                     WHEN '5' THEN '50代'
  99.                     WHEN '6' THEN '60代'
  100.                     ELSE '秘密'
  101.                  END cr_age
  102.                 ,CASE cr_sex
  103.                     WHEN '0' THEN '男性'
  104.                     WHEN '1' THEN '女性'
  105.                     ELSE '秘密'
  106.                  END cr_sex
  107.                 ,cr_approval
  108.                 ,app_datetime
  109.                 ,upd_datetime
  110.                 ,add_datetime
  111.                 ,goods_name
  112.                 ,(SELECT min(gp_kataban) FROM goods_price_table where cr_goods_id = gp_goods GROUP BY gp_goods) as gp_kataban
  113.                 FROM customer_review_table
  114.                 LEFT JOIN goods_table ON goods_id = cr_goods_id
  115.                 WHERE cr_approval = '1' AND cr_site_id = 0";
  116.         if (!empty($id) && empty($main_category_id)) {
  117.             // 商品ページのみに表示
  118.             $sql .= " AND cr_goods_id = {$id}
  119.                       AND cr_main_category_id = 0
  120.                       AND EXISTS (
  121.                         SELECT * FROM goods_table WHERE goods_id = {$id} AND goods_ddate IS NULL";
  122.             if(!$isSecret){
  123.                 $sql .= " AND goods_status = 1 ";
  124.             }
  125.             $sql .= " )";
  126.         } else if (!empty($main_category_id) && empty($category_id)) {
  127.             // 親カテページのみに表示
  128.             $sql .= " AND cr_main_category_id = {$main_category_id}
  129.                       AND cr_category_id = 0";
  130.         } else if (!empty($main_category_id) && !empty($category_id)) {
  131.             // 子カテページのみに表示
  132.             $sql .= " AND cr_main_category_id = {$main_category_id}
  133.                       AND cr_category_id = '{$category_id}'";
  134.         }
  135.         $sql .= " ORDER BY `customer_review_table`.`app_datetime` desc";
  136.         if (!empty($limit)) {
  137.             // 商品ページのみに表示
  138.             $sql .= " LIMIT {$offset}{$limit}";
  139.         }
  140.         return $this->Sql->SQL($sql)->FetchAll();
  141.     }
  142.     public function LM_displayTogetherBuyDetail_new3 ($goods_id$count false)
  143.     {
  144.         // 一緒に購入されている商品
  145.         $result = array();
  146.         $temp $this->getGoodsLinkSelectSql($goods_id$count);
  147.         if($temp){
  148.             foreach ($temp as $row) {
  149.                 $goodsId $row['goods_id'];
  150.                 $result[$goodsId] = $row;
  151.                 $average $this->getReviewAverage($row['goods_id']);
  152.                 $average = (!empty($average[$row['goods_id']])) ? $average[$row['goods_id']] : 0;
  153.                 $image_name = (int)($average 2) / 10;
  154.                 $result[$goodsId]['average'] = $average;
  155.                 $result[$goodsId]['average_img'] = "<img class=\"history-average-img\" alt=\"お客様からの口コミレビュー評価の星の数{$average}\" src=\"/images/review/star_m".$image_name.".gif\">";
  156.                 $count=0;
  157.                 if($tempRow $this->getReviewSql($row['goods_id'])) $count=count($tempRow);
  158.                 $result[$goodsId]['review_count'] = $count;
  159.                 $result[$goodsId]['img'] = "/goods.img/"substr($goodsId, -11) . "/" $goodsId "/main.jpg";
  160.             }
  161.         }
  162.         return $result;
  163.     }
  164.     public function getReviewExists($ohId$goodsId$customerId)
  165.     {
  166.         $result = (new SqlService())
  167.             ->Select('cr_id')
  168.             ->Table('customer_review_table')
  169.             ->Set('cr_oh_id'$ohId)
  170.             ->Set('cr_goods_id'$goodsId)
  171.             ->Set('cr_customer_id'$customerId)
  172.             ->Find();
  173.         return $result;
  174.     }
  175.     public function insertReview($values)
  176.     {
  177.         $sql = new SqlService();
  178.         $sql->Table('customer_review_table')
  179.             ->Insert(false$values);
  180.     }
  181. }