app/Customize/Service/MessageService.php line 119

Open in your IDE?
  1. <?php
  2. /**
  3.  * @version EC=CUBE4
  4.  * @copyright 株式会社 翔 kakeru.co.jp
  5.  * @author
  6.  * 2022年08月15日作成
  7.  *
  8.  * app/Customize/Service/MessageSErvice.php
  9.  *
  10.  *
  11.  * メッセージサービス
  12.  *
  13.  *
  14.  *                               C= C= C= ┌(;・_・)┘トコトコ
  15.  ******************************************************/
  16. namespace Customize\Service;
  17. use Lm\Service\Db\SqlService;
  18. class MessageService
  19. {
  20.     private $lmHelper;
  21.     public function __construct(LmHelper $lmHelper)
  22.     {
  23.         $this->lmHelper $lmHelper;
  24.     }
  25. public function GetMessage($GoodsId null ,$CategoryId null){
  26.     $Sql = new SqlService();
  27.     $Sql->Table('customer_message_table')
  28.         ->Set('display',)
  29.         ->Set('approval' ,1)
  30.         ->Order('cm_id','DESC');
  31.     if (!is_null($GoodsId)){
  32.         $Sub ='oh_id IN (SELECT S1.ol_oh FROM order_list_table AS S1 INNER JOIN goods_table AS S2 ON S1.ol_goods = S2.goods_id WHERE S2.goods_ddate IS NULL AND S1.ol_goods = :GoodsId)';
  33.         $Sql->Where($Sub)
  34.         ->Param(':GoodsId',$GoodsId);
  35.     }elseif (!is_null($CategoryId)){
  36.         $Sql->Set('cm_id',,'>')
  37.             ->Set('category','"'.$CategoryId.'"','LIKE');
  38.     }
  39.         return $Sql->FindAll();
  40. }
  41. public function GetGoodsList($Id){
  42.     $Sql = new SqlService();
  43.     return  $Sql->Table('customer_message_table')
  44.                 ->Select('T.*,T1.*,T2.*')
  45.                 ->Join('order_list_table','oh_id = ol_oh','INNER')
  46.                 ->Join('goods_table''T1.ol_goods = goods_id''INNER')
  47.                 ->Set('T.cm_id',$Id)
  48.                 ->Order('T.display_datetime','DESC')
  49.                 ->FindAll();
  50. }
  51. public function GetCategoryList(){
  52.     $Sql = new SqlService();
  53.     return  $Sql->Table('customer_message_category_table')
  54.                 ->Set('delete',0)
  55.                 ->FindAll();
  56. }
  57.     public function getCustomerMessagesAndCount($goodsId$limit)
  58.     {
  59.         $messages = (new SqlService())
  60.             ->Sql("
  61.                 SELECT SQL_CALC_FOUND_ROWS
  62.                     customer_message_table.cm_id,
  63.                     customer_message_table.oh_id,
  64.                     customer_message_table.customer_name,
  65.                     customer_message_table.title,
  66.                     customer_message_table.comment,
  67.                     customer_message_table.staff_comment,
  68.                     customer_message_table.category,
  69.                     customer_message_table.use,
  70.                     customer_message_table.file,
  71.                     customer_message_table.display,
  72.                     customer_message_table.approval,
  73.                     customer_message_table.app_datetime,
  74.                     customer_message_table.upd_datetime,
  75.                     customer_message_table.add_datetime,
  76.                     customer_message_table.display_datetime,
  77.                     CASE WHEN customer_message_table.file IS NULL THEN 0 ELSE 1 END AS file_exits,
  78.                     customer_table.customer_user_name
  79.                 FROM customer_message_table
  80.                 INNER JOIN order_header_table ON order_header_table.oh_id = customer_message_table.oh_id
  81.                 INNER JOIN customer_table ON oh_customer = customer_table.customer_id
  82.                 INNER JOIN order_list_table ON customer_message_table.oh_id = ol_oh
  83.                 INNER JOIN goods_table ON ol_goods = goods_id
  84.                 WHERE goods_id = :goods_id AND display = '1' AND approval = '1'
  85.                 GROUP BY customer_message_table.cm_id
  86.                 ORDER BY file_exits DESC, customer_message_table.display_datetime DESC
  87.                 LIMIT :limit;
  88.             ")
  89.             ->Params(['goods_id' => $goodsId'limit' => $limit])
  90.             ->FetchAll();
  91.         if (empty($messages)) {
  92.             return [[], 0];
  93.         }
  94.         $foundMessages = (new SqlService())->Sql('SELECT FOUND_ROWS() AS total')->Fetch();
  95.         return [$messages$foundMessages['total'] ?? 0];
  96.     }
  97.     public function formatCustomerMessages($messages)
  98.     {
  99.         return array_map(function ($message) {
  100.             $message['display_datetime'] = date('Y年m月d日'strtotime($message['display_datetime']));
  101.             $attachments unserialize($message['file']);
  102.             if ($attachments) {
  103.                 $message['file'] = $this->lmHelper->getConfig('CFIMG_BACK_URL') . '/images/koe_admin/'
  104.                     $message['cm_id'] . '/' reset($attachments);
  105.             }
  106.             if ($message['comment']) {
  107.                 $comment strip_tags(str_replace("<br />"""$message['comment']));
  108.                 $message['shorted_comment'] = mb_substr($comment0216);
  109.                 $message['extra_comment'] = mb_substr(strip_tags($comment), 216);
  110.             }
  111.             if ($message['staff_comment']) {
  112.                 $staffComment strip_tags($message['staff_comment']);
  113.                 $message['shorted_staff_comment'] = mb_substr($staffComment0216);
  114.                 $message['extra_staff_comment'] = mb_substr(strip_tags($staffComment), 216);
  115.             }
  116.             return $message;
  117.         }, $messages);
  118.     }
  119. }