/** * 予約一覧(マイ予約)をFlexで返信 */ if (!function_exists('lrs_reply_my_resv_flex')) { function lrs_reply_my_resv_flex($bot, $replyToken, $rows) { try { $flex = lrs_build_my_resv_flex_json($rows); if (class_exists('\\LINE\\LINEBot\\MessageBuilder\\RawMessageBuilder')) { $builder = new \\LINE\\LINEBot\\MessageBuilder\\RawMessageBuilder($flex); $resp = $bot->replyMessage($replyToken, $builder); if (method_exists($resp, 'isSucceeded') && $resp->isSucceeded()) { if (function_exists('error_log')) { error_log('[LRS] Flex my reservations sent successfully'); } return; } } } catch (\Throwable $e) { if (function_exists('error_log')) { error_log('[LRS] Flex my reservations failed: '.$e->getMessage()); } } catch (\Exception $e) { if (function_exists('error_log')) { error_log('[LRS] Flex my reservations failed: '.$e->getMessage()); } } // フォールバック(テキスト) $lines = []; if (empty($rows)) { $lines[] = "現在、予約はありません。"; } else { $lines[] = "ご予約一覧:"; foreach ($rows as $r) { $lines[] = "・".$r['text']; if (!empty($r['can_modify'])) { $lines[] = " キャンセル: 「キャンセル{$r['id']}」と送信"; } } } $text = implode("\n", $lines); if (class_exists('\\LINE\\LINEBot\\MessageBuilder\\TextMessageBuilder')) { $textBuilder = new \\LINE\\LINEBot\\MessageBuilder\\TextMessageBuilder($text); $bot->replyMessage($replyToken, $textBuilder); } } } if (!function_exists('lrs_build_my_resv_flex_json')) { /** * 予約一覧FlexのJSONを生成 * $rows = [ * ["id"=>int, "date"=>"Y-m-d", "time"=>"HH:MM", "text"=>"..", "can_modify"=>bool] * ] */ function lrs_build_my_resv_flex_json($rows = []) { if (empty($rows)) { return [ "type" => "flex", "altText" => "ご予約はありません", "contents" => [ "type" => "bubble", "body" => [ "type" => "box", "layout" => "vertical", "contents" => [ ["type"=>"text","text"=>"現在、予約はありません。","wrap"=>true] ] ] ] ]; } $list = []; foreach ($rows as $r) { $title = $r['text']; // 例: 08/21(木) 10:00 フットリフレ40分 $buttons = [ [ "type" => "button", "style" => "secondary", "height" => "sm", "action" => ["type"=>"postback","label"=>"変更","data"=>"action=start","displayText"=>"変更"] ] ]; if (!empty($r['can_modify'])) { $buttons[] = [ "type" => "button", "style" => "secondary", "height" => "sm", "action" => ["type"=>"postback","label"=>"キャンセル","data"=>"action=cancel_resv&id=".$r['id'],"displayText"=>"キャンセル"] ]; } else { $buttons[] = [ "type" => "box", "layout" => "vertical", "contents" => [ ["type"=>"text","text"=>"(2時間前を過ぎたため変更不可)","size"=>"xs","color"=>"#888888","wrap"=>true] ] ]; } $list[] = [ "type" => "box", "layout" => "vertical", "margin" => "md", "spacing" => "sm", "contents" => array_merge( [ ["type"=>"text","text"=>$title,"wrap"=>true,"weight"=>"bold","size"=>"sm"] ], $buttons ) ]; $list[] = ["type"=>"separator","margin"=>"md"]; } // 最後のseparatorを削除 if (!empty($list) && end($list)['type']==='separator') { array_pop($list); } return [ "type" => "flex", "altText" => "ご予約一覧", "contents" => [ "type" => "bubble", "header" => [ "type" => "box", "layout" => "vertical", "contents" => [ ["type"=>"text","text"=>"📆 ご予約一覧","size"=>"xl","weight"=>"bold","color"=>"#FFFFFF"] ], "backgroundColor" => "#0d6efd", "paddingAll" => "16px" ], "body" => [ "type" => "box", "layout" => "vertical", "spacing" => "md", "contents" => $list, "paddingAll" => "16px" ] ] ]; } } ?> https://aroma-fondu.com/wp-sitemap-posts-post-1.xmlhttps://aroma-fondu.com/wp-sitemap-posts-page-1.xmlhttps://aroma-fondu.com/wp-sitemap-posts-lrs_menu-1.xmlhttps://aroma-fondu.com/wp-sitemap-taxonomies-category-1.xmlhttps://aroma-fondu.com/wp-sitemap-users-1.xml