array( 'orderId' => array('name' => 'orderId', 'require' => true, 'desc' => '注文ID'), ), 'verification' => array( 'orderId' => array('name' => 'orderId', 'require' => true, 'desc' => '注文ID'), 'uuid' => array('name' => 'uuid', 'require' => true, 'desc' => 'デバイスの一意の識別子'), 'ciphertext' => array('name' => 'ciphertext', 'require' => true, 'desc' => '暗号文') ), 'getOrderInfo' => array( 'orderId' => array('name' => 'orderId', 'require' => true, 'desc' => '注文ID'), ), 'updateOrderInfo' => array( 'orderId' => array('name' => 'orderId', 'require' => true, 'desc' => '注文ID'), 'contactId' => array('name' => 'contactId', 'require' => true, 'desc' => '連絡先ID'), ), 'downloadImg' => array( 'orderId' => array('name' => 'orderId', 'require' => true, 'desc' => '注文ID'), 'fileName' => array('name' => 'fileName', 'require' => false, 'desc' => '写真の名前'), ), 'downloadImgV2' => array( 'fileName' => array('name' => 'fileName', 'require' => true, 'desc' => '写真の名前'), 'fileDir' => array('name' => 'fileDir', 'require' => true, 'desc' => '文件目录'), ), 'viewImg' => array( 'fileName' => array('name' => 'fileName', 'require' => true, 'desc' => '写真の名前'), ), 'downloadFile' => array( 'fileName' => array('name' => 'fileName', 'require' => true, 'desc' => 'ファイルの名前'), 'fileDir' => array('name' => 'fileDir', 'require' => true, 'desc' => '文件目录'), ), 'downloadPdf' => array( 'fileName' => array('name' => 'fileName', 'require' => true, 'desc' => 'ファイルの名前'), ), 'downloadImgV3' => array( 'imgUrl' => array('name' => 'imgUrl', 'require' => true, 'desc' => '图片地址'), ), 'uploadData' => array( 'orderId' => array('name' => 'orderId', 'require' => true, 'desc' => '注文ID'), 'customerId' => array('name' => 'customerId', 'require' => false, 'desc' => 'お客様ID'), 'year' => array('name' => 'year', 'require' => false, 'desc' => '年式'), 'number' => array('name' => 'number', 'require' => false, 'desc' => '登录番号'), 'vin' => array('name' => 'vin', 'require' => false, 'desc' => '車台番号'), 'syodoDate' => array('name' => 'syodoDate', 'require' => false, 'desc' => '登录年月日'), 'katashiki' => array('name' => 'katashiki', 'require' => false, 'desc' => '型式'), 'katashikiShitei' => array('name' => 'katashikiShitei', 'require' => false, 'desc' => '型式指定番号'), 'ruibetsu' => array('name' => 'ruibetsu', 'require' => false, 'desc' => '類別区分番号'), 'gendouki' => array('name' => 'gendouki', 'require' => false, 'desc' => '原動機型式'), 'drive' => array('name' => 'drive', 'require' => false, 'desc' => '駆動'), 'nenryou' => array('name' => 'nenryou', 'require' => false, 'desc' => '燃料'), 'syaken' => array('name' => 'syaken', 'require' => false, 'desc' => '车检有效期限'), 'millage' => array('name' => 'millage', 'require' => false, 'desc' => '走行距離'), 'delivaryDate' => array('name' => 'delivaryDate', 'require' => false, 'desc' => '交付年月日'), 'keijyou' => array('name' => 'keijyou', 'require' => false, 'desc' => '車体の形状'), 'jyuuryou' => array('name' => 'jyuuryou', 'require' => false, 'desc' => '車両重量'), 'syoyuusyaName' => array('name' => 'syoyuusyaName', 'require' => false, 'desc' => '所有者名'), 'syoyuusyaAddress' => array('name' => 'syoyuusyaAddress', 'require' => false, 'desc' => '所有者住所'), 'shiyousyaName' => array('name' => 'shiyousyaName', 'require' => false, 'desc' => '使用者名'), 'shiyousyaAddress' => array('name' => 'shiyousyaAddress', 'require' => false, 'desc' => '使用者住所'), 'dataR1' => array('name' => 'dataR1', 'require' => false, 'desc' => '右上から1番目の査定値'), 'dataR2' => array('name' => 'dataR2', 'require' => false, 'desc' => '右上から2番目の査定値'), 'dataR3' => array('name' => 'dataR3', 'require' => false, 'desc' => '右上から3番目の査定値'), 'dataR4' => array('name' => 'dataR4', 'require' => false, 'desc' => '右上から4番目の査定値'), 'dataR5' => array('name' => 'dataR5', 'require' => false, 'desc' => '右上から5番目の査定値'), 'dataR6' => array('name' => 'dataR6', 'require' => false, 'desc' => '右上から6番目の査定値'), 'dataR7' => array('name' => 'dataR7', 'require' => false, 'desc' => '右上から7番目の査定値'), 'dataR8' => array('name' => 'dataR8', 'require' => false, 'desc' => '右上から8番目の査定値'), 'dataR9' => array('name' => 'dataR9', 'require' => false, 'desc' => '右上から9番目の査定値'), 'dataR10' => array('name' => 'dataR10', 'require' => false, 'desc' => '右上から10番目の査定値'), 'dataR11' => array('name' => 'dataR11', 'require' => false, 'desc' => '右上から11番目の査定値'), 'dataR12' => array('name' => 'dataR12', 'require' => false, 'desc' => '右上から12番目の査定値'), 'dataL1' => array('name' => 'dataL1', 'require' => false, 'desc' => '左上から1番目の査定値'), 'dataL2' => array('name' => 'dataL2', 'require' => false, 'desc' => '左上から2番目の査定値'), 'dataL3' => array('name' => 'dataL3', 'require' => false, 'desc' => '左上から3番目の査定値'), 'dataL4' => array('name' => 'dataL4', 'require' => false, 'desc' => '左上から4番目の査定値'), 'dataL5' => array('name' => 'dataL5', 'require' => false, 'desc' => '左上から5番目の査定値'), 'dataL6' => array('name' => 'dataL6', 'require' => false, 'desc' => '左上から6番目の査定値'), 'dataL7' => array('name' => 'dataL7', 'require' => false, 'desc' => '左上から7番目の査定値'), 'dataL8' => array('name' => 'dataL8', 'require' => false, 'desc' => '左上から8番目の査定値'), 'dataL9' => array('name' => 'dataL9', 'require' => false, 'desc' => '左上から9番目の査定値'), 'dataL10' => array('name' => 'dataL10', 'require' => false, 'desc' => '左上から10番目の査定値'), 'dataL11' => array('name' => 'dataL11', 'require' => false, 'desc' => '左上から11番目の査定値'), 'dataL12' => array('name' => 'dataL12', 'require' => false, 'desc' => '左上から12番目の査定値'), 'dataRoof1' => array('name' => 'dataRoof1', 'require' => false, 'desc' => 'ルーフの査定値(前)'), 'dataRoof2' => array('name' => 'dataRoof2', 'require' => false, 'desc' => 'ルーフの査定値(後)'), 'contactComment' => array('name' => 'contactComment', 'require' => false, 'desc' => '連絡備考'), 'contactWay' => array('name' => 'contactWay', 'require' => false, 'desc' => '連絡方法'), 'damageLevel' => array('name' => 'damageLevel', 'require' => false, 'desc' => 'ダメージの程度'), 'obd' => array('name' => 'obd', 'type' => 'array', 'format' => 'explode', 'separator' => ',', 'desc' => '障害番号'), 'adminName' => array("name" => "adminName", "require" => false, "desc" => "管理者名") ), "checkImgSourceUpdate" => array( "crc32" => array('name' => "crc32", 'require' => true, 'desc' => "crc32b"), 'orderId' => array('name' => 'orderId', 'require' => true, 'desc' => '注文ID'), 'fileName' => array('name' => 'fileName', 'require' => false, 'desc' => '写真の名前'), ), "logout" => array( "orderId" => array("name" => "orderId", "require" => true, "desc" => "注文ID"), 'timestamp' => array("name" => "timestamp", "require" => true, "desc" => "タイムスタンプ") ), "orderList" => array( "serviceStatus" => array("name" => "serviceStatus", "desc" => "用件"), "serviceStatusList" => array("name" => "serviceStatusList", "require" => false, "type" => "array", "format" => "json", "desc" => "多个服务"), "state" => array("name" => "state", "desc" => "状態"), "shopId" => array("name" => "shopId", "desc" => "担当者"), "freeword" => array("name" => "freeword", "desc" => "自由词"), "orderId" => array("name" => "orderId", "desc" => "注文ID", "require" => false ), ), "orderListV2" => array( "serviceStatus" => array("name" => "serviceStatus", "desc" => "用件"), "serviceStatusList" => array("name" => "serviceStatusList", "require" => false, "type" => "array", "format" => "json", "desc" => "多个服务"), "state" => array("name" => "state", "desc" => "状態"), "shopId" => array("name" => "shopId", "desc" => "担当者"), "freeword" => array("name" => "freeword", "desc" => "自由词"), ), "getSSAndCarNameByOrderId" => array( "orderId" => array("name" => "orderId", "require" => true, "desc" => "注文ID") ), 'updateRemark' => array( "orderId" => array("name" => "orderId", "require" => true, "desc" => "注文ID"), 'remark' => array('name' => 'remark', 'desc' => '備考') ), 'updateState' => array( "orderId" => array("name" => "orderId", "require" => true, "desc" => "注文ID"), 'state' => array('name' => 'state', 'desc' => '状態(1査定前 2査定済 3見積済 -1未成約)'), 'reason' => array('name' => 'reason', 'require' => false, 'desc' => '未成約事由'), ), 'getFormCtrlInfo' => array( 'viewId' => array('name' => 'viewId', 'require' => true, 'desc' => 'ビューID') ), 'addGeneralOrder' => array( 'carId' => array('name' => 'carId', 'require' => false, 'desc' => '車両ID'), 'shopId' => array('name' => 'shopId', 'require' => true, 'desc' => 'ショップID'), 'customerId' => array('name' => 'customerId', 'require' => true, 'desc' => '顧客ID'), 'serviceStatus' => array('name' => 'serviceStatus', 'desc' => 'サービスの選択'), ), 'saveGeneralMaintenanceRequests' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), 'requestMatters' => array('name' => 'requestMatters', 'require' => false, 'type' => 'array', 'format' => 'json', 'desc' => '依頼事項'), ), 'uploadDataV2' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), 'carInfo' => array("name" => "carInfo", "require" => false, "type" => "array", "format" => "json", "desc" => "车辆情报"), 'vehicleInspectionQuoteInfo' => array("name" => "vehicleInspectionQuoteInfo", "require" => false, "type" => "array", "format" => "json", "desc" => "车检报价"), 'generalMaintenanceRequestsInfo' => array("name" => "generalMaintenanceRequestsInfo", "require" => false, "type" => "array", "format" => "json", "desc" => "一般整备"), ), 'doSaveInspect' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), ), 'getCarPhotos' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), ), 'getOrderPdfs' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), ), 'doSavePaymentProof' => array( 'paymentProofData' => array("name" => "paymentProofData", "require" => true, "type" => "array", "format" => "json", "desc" => "收款证明数据"), ), 'getBudgetData' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), ), 'doSaveBudget' => array( 'budgetData' => array("name" => "budgetData", "require" => true, "type" => "array", "format" => "json", "desc" => "车检报价预算"), 'pdfType' => array("name" => "pdfType", "require" => false, "desc" => "pdfタイプ"), ), 'doSaveSagyo' => array( 'budgetData' => array("name" => "budgetData", "require" => true, "type" => "array", "format" => "json", "desc" => "车检报价预算"), 'pdfType' => array("name" => "pdfType", "require" => false, "desc" => "pdfタイプ"), ), 'previewBudget' => array( 'budgetData' => array("name" => "budgetData", "require" => true, "type" => "array", "format" => "json", "desc" => "车检报价预算"), 'pdfType' => array("name" => "pdfType", "require" => false, "desc" => "pdfタイプ"), ), 'doSaveMcQrPage' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), ), 'doCopyOrder' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), ), 'cancelOrder' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), ), 'doSaveDicounts' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), 'discounts' => array("name" => "discounts", "require" => true, "type" => "array", "format" => "json", "desc" => "値引きID"), ), 'doSaveExtraDiscount' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), 'discount' => array("name" => "discount", "require" => true, "desc" => "値引き"), ), 'doUpdateCarInfo' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), 'carInfo' => array("name" => "carInfo", "require" => true, "type" => "array", "format" => "json", "desc" => "更新データ"), 'customerInfo' => array("name" => "customerInfo", "require" => false, "type" => "array", "format" => "json", "desc" => "更新customerデータ"), ), 'doNotifyOrderCanceled' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID") ), 'clearNewFlag' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID") ), 'checkReserveState' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID") ), 'getSalesList' => array( 'startDate' => array("name" => "startDate", "require" => true, "desc" => "開始日"), 'endDate' => array("name" => "endDate", "require" => true, "desc" => "終了日"), ), 'getSalesByYear' => array( 'year' => array("name" => "year", "require" => true, "desc" => "年"), ), 'updateCollectionFlag' => array( 'orderId' => array("name" => "orderId", "require" => true, "desc" => "注文ID"), 'collectionFlag' => array("name" => "collectionFlag", "require" => true, "desc" => "収集フラグ"), ), 'doSaveWholeBudget' => array( 'customerId' => array("name" => "customerId", "require" => true, "desc" => "お客様のID"), 'month' => array("name" => "month", "require" => true, "desc" => "月"), ), 'doSaveNoPayedBudgetByMonth' => array( 'month' => array("name" => "month", "require" => true, "desc" => "月"), ), ); } /** * @brief QR コード画像を生成します * * orderIdに基づくAES暗号化 * 暗号文に「 」を加えた形式に従って orderId を追加します (例: aq5Z2Hx2MTtlAAZmiqy5Fu1 101) * 対応する QR コード画像は Base64 エンコード後に生成されます。 * @param orderId 注文 ID * @return QRcode コード画像のバイナリ ストリームを返します */ public function qrCodePng() { //注文ID $orderId = $this->orderId; DI()->logger->info('qrCodePng', 'orderId:' . $orderId); if (empty($this->orderId)) { throw new BadRequestException('Parameter is invalid'); } //注文 ID による AES 暗号化 $result = DI()->aes->encrypt($orderId); DI()->logger->info('qrCodePng', "aes encrypt:" . $result); //暗号文と注文 ID は、間にスペースを追加することで結合され、Base 64 に従ってエンコードされます。 $data = base64_encode($result . " " . $orderId); DI()->logger->info('qrCodePng', 'base64 encode:' . $data); //QRコードを生成するサービスクラスを取得する $qrcode = \PhalApi\DI()->get('qrcode', new \PhalApi\QrCode\Lite()); //QRコード画像を出力 $qrcode->png($data, false); exit(); } /** * @brief QRコード認証 * * 受信した注文ID、UUID、暗号文に基づいてQRコードを検出します * -# 不正な QR フォーマットが認識された場合は、「ステータス 403、メッセージ: QRフォーマットが不正確です。ご確認ください」を返します。 * -# QRフォーマットが正しい場合は、オーダーの検証状態を判定します。 * - オーダーを取得できず場合、「ステータス401、メッセージ:車両情報の取得に失敗しました」を返す。 * - 検証状態は評価中場合、「 "ステータス 402、メッセージ: 該当車両が査定中です"」を返します。 * - 検証状態は評価中ではなく場合、「ステータス200、データ:完全な注文情報の JSON データ」を返します。 * * @param orderId 注文ID * @param uuid デバイスの一意の識別子 * @param ciphertext 暗号文 * @return 認証結果のJSONデータ * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - msg: プロンプトメッセージ * - data: 完全な注文情報の JSON データ * - car: 車情報 * - mtVcFormCtrl: フォーム表示制御 * - vcContact: 連絡情報 * - vcFilmThickness: 膜厚データ */ public function verification() { //注文ID $orderId = $this->orderId; //uuid $uuid = $this->uuid; //暗号文 $ciphertext = $this->ciphertext; DI()->logger->info("verification", "params:" . json_encode(array("orderId" => $orderId, "uuid" => $uuid, "ciphertext" => $ciphertext))); //QRフォーマットが正しいかどうかを検出する 記録を検証する //AES経由で暗号文を復号化する $result = DI()->aes->decrypt($ciphertext); DI()->logger->info("verification", "aes decrypt:" . $result); if ($result != $orderId) {//復号化された注文 ID がパラメータとして渡された注文 ID と等しいかどうかを判断します。 throw new BadRequestException('QRフォーマットが不正確です。ご確認ください', 3); } //注文IDに基づいて注文レコードを取得する $orderDomain = new DatSyakenOrderListDomain(); $orderInfo = $orderDomain->get($orderId); if (empty($orderInfo)) { throw new BadRequestException('車両情報の取得に失敗しました', 1); } //系统时间戳 $timestamp = time(); //注文の評価ステータスを判断し、チェック状態が 1 の場合は評価中であることを意味し、それ以外の場合はチェック状態ステータスを更新します if ($orderInfo['check_state'] == 1) {//評価する //オーダー ID によってバインドされた UUID をクエリします $orderUuidDomain = new DatOrderUuidDomain(); $orderUuid = $orderUuidDomain->getUuidByOrderId($orderId); //uuidがバインドされている場合は、バインドされたuuidがパラメータで渡されたuuidと等しいかどうかを判断し、そうでない場合は直接リターンします。 if ($orderUuid['uuid'] != $uuid) { throw new BadRequestException('該当車両が査定中です', 2); } //更新时间戳 $orderUuidDomain->updateOrderUuid($orderId, ['ts' => $timestamp]); } else { //チェック状態を 1 に更新し、評価します $data = ['check_state' => 1]; $orderDomain->updateOrderInfoByOrderId($orderId, $data); //orderUuidData $orderUuidData = ['order_id' => $orderId, 'uuid' => $uuid, 'create_time' => date('Y-m-d H:i:s', $timestamp), 'ts' => $timestamp]; //バインドレコードを挿入する $orderUuidDomain = new DatOrderUuidDomain(); $orderUuidDomain->insert($orderUuidData); } $data = array(); $data['timestamp'] = $timestamp; //NFC api $accessId =isset($_ENV['NFC_API_ACCESS_ID']) ? $_ENV['NFC_API_ACCESS_ID'] : "AID000000010930"; $accessKey =isset($_ENV['NFC_API_ACCESS_KEY']) ? $_ENV['NFC_API_ACCESS_KEY'] : "1f69a5fc-4503-4818-baf3-6194adfbd9b2"; $data['accessId'] = $accessId; $data['accessKey'] = $accessKey; return $this->getOrderAllInfo($orderInfo, $data); } /** * @brief オーダー情報取得 * * 受信した注文IDに基づいてオーダー情報を検出します * * @param orderId 注文ID * @return オーダー情報のJSONデータ * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - msg: プロンプトメッセージ * - data: 完全な注文情報の JSON データ * - car: 車情報 * - mtVcFormCtrl: フォーム表示制御 * - vcContact: 連絡情報 * - vcFilmThickness: 膜厚データ */ public function getOrderInfo() { //注文ID $orderId = $this->orderId; //注文IDに基づいて注文レコードを取得する $orderDomain = new DatSyakenOrderListDomain(); $orderInfo = $orderDomain->get($orderId); if (empty($orderInfo)) { throw new BadRequestException('車両情報の取得に失敗しました', 1); } $data = array(); return $this->getOrderAllInfo($orderInfo, $data); } /** * @brief 車情報、フォーム表示制御、連絡情報、膜厚データ、顧客情報、obd障害情報取得する * * * carIdで車両情報を取得し、取得した車両情報をcar配列に設定します * carIdで膜厚情報を取得し、取得した膜厚情報をvcFilmThickness配列に設定する * carIdでobd障害情報を取得し、取得したobd障害情報をobd配列に設定します * contactIdで連絡先情報を取得し、取得した連絡先情報をvcContact配列に設定します * customerIdから顧客情報を取得し、取得した顧客情報をdatCustomer配列に設定します * 取得したフォーム表示コントロールをmtVcFormCtrl配列に設定します * このまとめてデータを戻り値とする * * @param orderInfo DatSyakenOrderListから取得された情報、中にはCar_IDとcontact_idがあります * @return 完璧なオーダー情報のJSONデータ * - car: 車情報 * - mtVcFormCtrl: フォーム表示制御 * - vcContact: 連絡情報 * - vcFilmThickness: 膜厚データ * - datCustomer: 顧客情報 * - obd: obd障害情報 * */ private function getOrderAllInfo($orderInfo, $data) { //車の情報 $data['car'] = array(); //連絡情報 $data['vcContact'] = array(); //膜厚データ $data['vcFilmThickness'] = array(); //フォーム表示制御 $data['mtVcFormCtrl'] = array(); //顧客情報 $data['datCustomer'] = array(); //obd $data['obd'] = array(); //obd price $data['obdPrice'] = array(); //服务状态 $data['service'] = $orderInfo['service']; //shopId $data['ssid'] = $orderInfo['Shop_ID']; //車のID $carId = $orderInfo['Car_ID']; //連絡ID $contactId = $orderInfo['contact_id']; //顧客ID $customerId = $orderInfo['Customer_ID']; $data['customerId'] = $customerId; $data['state'] = $orderInfo['state']; //連絡先IDが空ではありません if ($contactId) { //連絡先IDに基づいて連絡先情報を取得する $contactDomain = new DatVcContact(); $contactInfo = $contactDomain->get($contactId); //クエリ結果が空かどうかを判断し、空の場合は空のオブジェクトを返し、空でない場合は通常どおりクエリ結果を返します $data['vcContact'] = is_array($contactInfo) ? $contactInfo : (object)$data['vcContact']; } if ($carId) {//車のIDが空ではありません //Car_IDにより、車情報を取得する $carsDomain = new DatCarsDomain(); $carInfo = $carsDomain->getCarInfo($carId); //クエリ結果が空かどうかを判断し、空の場合は空のオブジェクトを返し、空でない場合は通常どおりクエリ結果を返します $data['car'] = is_array($carInfo) ? $carInfo : (object)$data['car']; //Car_IDにより、膜厚情報を取得 $filmThicknessDomain = new DatVcFilmThickness(); $filmThicknessInfo = $filmThicknessDomain->get($carId); //クエリ結果が空かどうかを判断し、空の場合は空のオブジェクトを返し、空でない場合は通常どおりクエリ結果を返します $data['vcFilmThickness'] = is_array($filmThicknessInfo) ? $filmThicknessInfo : (object)$data['vcFilmThickness']; //obd故障信息 $datVcObdDomain = new DatVcObdDomain(); $datVcObdInfo = $datVcObdDomain->getObdErrorListByCarId($carId); //クエリ結果が空かどうかを判断し、空の場合は空のオブジェクトを返し、空でない場合は通常どおりクエリ結果を返します $data['obd'] = is_array($datVcObdInfo) ? $datVcObdInfo : (object)$data['obd']; if(!empty($carInfo['katashiki'])){ $mtObdUnitPrice = new MtObdUnitPriceDomain(); $mtPriceList = $mtObdUnitPrice->getObdUnitPriceByKatashiki($carInfo['katashiki']); $data['obdPrice'] = is_array($mtPriceList) ? $mtPriceList : (object)$data['obdPrice']; } } if ($customerId) { //顧客IDに基づいて顧客情報を照会する $customerDomain = new DatCustomerDomain(); $customerInfo = $customerDomain->get($customerId); //クエリ結果が空かどうかを判断し、空の場合は空のオブジェクトを返し、空でない場合は通常どおりクエリ結果を返します $data['datCustomer'] = is_array($customerInfo) ? $customerInfo : (object)$data['datCustomer']; } //获取フィールド制御 $formCtrlDomain = new MtVcFormCtrlDomain(); $data['mtVcFormCtrl'] = $formCtrlDomain->getFormCtrlInfo(['view_id' => 'car']); return $data; } /** * @brief オーダー情報更新 * * 受信したオーダー ID に従ってオーダー情報を照会し、contactId と checkState を更新します * -# 更新が成功し、ステータス 200 を返します。 * -# 更新に失敗しました。ステータス 400 を返します。msg: 失敗メッセージ。 * * @param orderId 注文ID * @param contactId 連絡先 ID * @return 変更結果のJSONデータ * - ret: ステータスコード、200 は成功を意味し、4xx は失敗を意味します * - msg: プロンプトメッセージ */ public function updateOrderInfo() { //注文ID $orderId = $this->orderId; //連絡先 ID $contactId = $this->contactId; //ロギング DI()->logger->info("updateOrderInfo", "params:" . json_encode(array("orderId" => $orderId, "contactId" => $contactId))); $domain = new DatSyakenOrderListDomain(); //注文IDで注文が存在するかどうかを確認する if (!$domain->checkOrder($orderId)) { throw new BadRequestException('order is invalid'); } //連絡先IDを更新し、注文のステータスを確認してください $data = ['contact_id' => $contactId, 'check_state' => 0]; $domain->updateOrderInfoByOrderId($orderId, $data); return array('msg' => "アップデートが完了しました"); } public function doUpdateCarInfo() { //注文ID $orderId = $this->orderId; $carData = $this->carInfo; $customerInfo = $this->customerInfo; $orderDomain = new DatSyakenOrderListDomain(); //注文IDで注文が存在するかどうかを確認する if (!$orderDomain->checkOrder($orderId)) { throw new BadRequestException('order is invalid'); } //orderId による注文データのクエリ $orderInfo = $orderDomain->get($orderId); // SSID $ssId = $orderInfo['Shop_ID']; // SS情報を取得する $mtssDomain = new MtssDomain(); $mtss = $mtssDomain->get($ssId); //車両ID $carId = $orderInfo['Car_ID']; $carData['customer_ID'] = $orderInfo['Customer_ID']; DI()->logger->info("uploadData", 'update dat_cars data:' . json_encode($carData)); if($orderInfo['Customer_ID']){ $customerDomain = new DatCustomerDomain(); $customerInfoRecord = $customerDomain->get($orderInfo['Customer_ID']); if($customerInfoRecord){ // $customerInfoRecord['name'] = $customerInfo['name']; // $customerInfoRecord['kensaku'] = $customerInfo['kensaku']; // $customerInfoRecord['customer_name'] = $customerInfo['customer_name']; // $customerInfoRecord['customer_address'] = $customerInfo['customer_address']; // $customerInfoRecord['Customer_address_2'] = $customerInfo['Customer_address_2']; $customerInfoRecord['customer_telnumber'] = $customerInfo['customer_telnumber']; $customerDomain->updateCustomer($orderInfo['Customer_ID'],$customerInfoRecord); } } $carsDomain = new DatCarsDomain(); //車のIDが存在するかどうかを確認する if (empty($carId) || !$carsDomain->checkSyakenCar($carId)) { $carData['Custmer_Trigger'] = 7;//シマース査定車両 if ($mtss['ss_name'] == 'apple') { $carData['Custmer_Trigger'] = 1; } $carData['Create_Date'] = date('Y-m-d'); //顧客IDに基づいて顧客情報を照会する $customerId = $orderInfo['Customer_ID']; $customerDomain = new DatCustomerDomain(); $customerInfo = $customerDomain->get($customerId); //依頼者 dat_customer name dat_cars.contruct_customer にもコピー $data['contruct_customer'] = $customerInfo['name']; //依頼者 dat_customer customer_address dat_cars.addr にもコピー $data['addr'] = $customerInfo['customer_address']; //新しい車両情報を追加します $carId = $carsDomain->insert($carData); //注文情報の車 ID フィールドを更新します。 $orderDomain->updateOrderInfoByOrderId($orderId, ['Car_ID' => $carId]); } else { //車両インテリジェンス情報を更新する $carsDomain->updateCarsInfo($carId, $carData); } return array('msg' => "正常にアップロードされました"); } /** * @brief 画像更新判定 * * サーバにあるAppViewのCRC32を計算する、取得されたCRC32の値をアプリから取得するCRC32の値と判定する。 * - 同一の場合、「更新なし」を返信する * - 同一ではない場合、「更新ある」を返信する * * @param crc32 アプリで計算するソースのCRC32 * @return 判定結果のJSONデータ * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - msg: プロンプトメッセージ * - data: 判定結果、Trueは更新ある、Falseは更新無し */ public function checkImgSourceUpdate() { DI()->logger->info('checkImgSourceUpdate', 'params:' . json_encode(array('orderId' => $this->orderId, 'fileName' => $this->orderId, 'crc32' => $this->crc32))); //注文ID $orderId = $this->orderId; //写真の名前 $fileName = $this->fileName; //サーバー上に保存されている画像のファイル名 $name = $orderId . '_' . $fileName; //設定ファイル内の画像のアップロードアドレスを取得します。 $srcFile = DI()->config->get("app.imageUploadDir"); //画像アクセスパス $imgPath = sprintf($srcFile . '%s', $name); $PSize = filesize($imgPath); DI()->logger->info('checkImgSourceUpdate', 'filesize:' . $PSize); // APP CRC32 $appCrc = $this->crc32; DI()->logger->info('checkImgSourceUpdate', 'file:' . $imgPath); //指定されたファイルの内容を使用してハッシュ値を生成します $hash = hash_file('crc32b', $imgPath, false); $crc32 = $hash; DI()->logger->info('checkImgSourceUpdate', 'crc32:' . $crc32); //2 つのファイルのサイズを比較し、比較結果が 0 の場合は更新がないことを意味します if (strcasecmp($appCrc, $crc32) == 0) { return false; } return true; } /** * @brief 画像のダウンロード * * 注文IDとファイル名に従って画像のバイナリストリームを取得します * * @param orderId 注文ID * @param fileName 写真の名前 * @return 画像のバイナリ ストリームを返します */ public function downloadImg() { //注文ID $orderId = $this->orderId; //写真の名前 $fileName = $this->fileName; DI()->logger->info("downloadImg", "params:" . json_encode(array("orderId" => $orderId, "fileName" => $fileName))); //サーバー上に保存されている画像のファイル名 $name = $orderId . '_' . $fileName; //設定ファイル内の画像のアップロードアドレスを取得します。 $imageUploadDir = DI()->config->get("app.imageUploadDir"); // $imgPath = sprintf('https://%s/shima-clc.com/car/detail/upload/zebra/%s', $_SERVER['SERVER_NAME'], $name); //画像アクセスパス $imgPath = sprintf($imageUploadDir . '%s', $name); DI()->logger->info("downloadImg", "img path url:" . $imgPath); //画像リソースが存在するかどうかを確認する if (file_exists($imgPath)) { header("Content-type: image/jpg"); //画像ファイルのサイズを取得する // $PSize = filesize($imgPath); // //画像リソースを読む // $picturedata = fread(fopen($imgPath, "r"), $PSize); // echo $picturedata; $out_file_size = stat($imgPath)['size']; header("Content-Range:0-" . ($out_file_size - 1) . "/$out_file_size"); header("Content-Length:" . $out_file_size); echo file_get_contents($imgPath); exit(); } else { //カスタム応答コード http_response_code(404); throw new BadRequestException('Image not exists'); } } private function get_int_val($strval) { if ($strval != null && $strval != "") { return $strval; } return null; } /** * @brief 画像のダウンロード * * 注文IDとファイル名に従って画像のバイナリストリームを取得します * * @param fileDir ファイルディレクトリ * @param fileName 写真の名前 * @return 画像のバイナリ ストリームを返します */ public function downloadImgV2() { //写真の名前 $fileName = $this->fileName; $fileDir = $this->fileDir; DI()->logger->info("downloadImgV2", "params:" . json_encode(array("path" => $fileDir, "fileName" => $fileName))); //サーバー上に保存されている画像のファイル名 // $imgPath = sprintf('https://%s/shima-clc.com/car/detail/upload/zebra/%s', $_SERVER['SERVER_NAME'], $name); //画像アクセスパス $imgPath = sprintf($fileDir . '%s', $fileName); DI()->logger->info("downloadImgV2", "imgPath:" . $imgPath); //画像リソースが存在するかどうかを確認する if (file_exists($imgPath)) { header("Content-type: image/jpg"); //画像ファイルのサイズを取得する // $PSize = filesize($imgPath); // //画像リソースを読む // $picturedata = fread(fopen($imgPath, "r"), $PSize); // echo $picturedata; $out_file_size = stat($imgPath)['size']; header("Content-Range:0-" . ($out_file_size - 1) . "/$out_file_size"); header("Content-Length:" . $out_file_size); echo file_get_contents($imgPath); exit(); } else { //カスタム応答コード http_response_code(404); throw new BadRequestException('Image not exists'); } } /** * @brief 画像のダウンロード * * 注文IDとファイル名に従って画像のバイナリストリームを取得します * * @param fileDir ファイルディレクトリ * @param fileName 写真の名前 * @return 画像のバイナリ ストリームを返します */ public function viewImg() { //写真の名前 $fileName = $this->fileName; $fileDir = DI()->config->get("app.carPhotoUploadDir"); DI()->logger->info("viewImg", "params:" . json_encode(array("path" => $fileDir, "fileName" => $fileName))); //サーバー上に保存されている画像のファイル名 // $imgPath = sprintf('https://%s/shima-clc.com/car/detail/upload/zebra/%s', $_SERVER['SERVER_NAME'], $name); //画像アクセスパス $imgPath = sprintf($fileDir . '%s', $fileName); DI()->logger->info("viewImg", "imgPath:" . $imgPath); //画像リソースが存在するかどうかを確認する if (file_exists($imgPath)) { header("Content-type: image/jpg"); //画像ファイルのサイズを取得する // $PSize = filesize($imgPath); // //画像リソースを読む // $picturedata = fread(fopen($imgPath, "r"), $PSize); // echo $picturedata; $out_file_size = stat($imgPath)['size']; header("Content-Range:0-" . ($out_file_size - 1) . "/$out_file_size"); header("Content-Length:" . $out_file_size); echo file_get_contents($imgPath); exit(); } else { //カスタム応答コード http_response_code(404); throw new BadRequestException('Image not exists'); } } /** * @brief ファイルのダウンロード * * 注文IDとファイル名に従ってバイナリストリームを取得します * * @param fileDir ファイルディレクトリ * @param fileName ファイルの名前 * @return 画像のバイナリ ストリームを返します */ public function downloadFile() { //ファイルの名前 $fileName = $this->fileName; $fileDir = $this->fileDir; DI()->logger->info("downloadFile", "params:" . json_encode(array("path" => $fileDir, "fileName" => $fileName))); //サーバー上に保存されている画像のファイル名 // $imgPath = sprintf('https://%s/shima-clc.com/car/detail/upload/zebra/%s', $_SERVER['SERVER_NAME'], $name); //ファイルアクセスパス $filePath = sprintf($fileDir . '%s', $fileName); DI()->logger->info("downloadFile", "imgPath:" . $filePath); //画像リソースが存在するかどうかを確認する if (file_exists($filePath)) { header("Content-type: octet/stream"); //画像ファイルのサイズを取得する // $PSize = filesize($imgPath); // //画像リソースを読む // $picturedata = fread(fopen($imgPath, "r"), $PSize); // echo $picturedata; $out_file_size = stat($filePath)['size']; header("Content-Range:0-" . ($out_file_size - 1) . "/$out_file_size"); header("Content-Length:" . $out_file_size); echo file_get_contents($filePath); exit(); } else { //カスタム応答コード http_response_code(404); throw new BadRequestException('File not exists'); } } /** * @brief ファイルのダウンロード * * 注文IDとファイル名に従ってバイナリストリームを取得します * * @param fileDir ファイルディレクトリ * @param fileName ファイルの名前 * @return 画像のバイナリ ストリームを返します */ public function downloadPdf() { //ファイルの名前 $fileName = $this->fileName; $fileDir = DI()->config->get('app.pdfUploadDir'); DI()->logger->info("downloadPdf", "params:" . json_encode(array("path" => $fileDir, "fileName" => $fileName))); //サーバー上に保存されている画像のファイル名 // $imgPath = sprintf('https://%s/shima-clc.com/car/detail/upload/zebra/%s', $_SERVER['SERVER_NAME'], $name); //ファイルアクセスパス $filePath = sprintf($fileDir . '%s', $fileName); DI()->logger->info("downloadPdf", "imgPath:" . $filePath); //画像リソースが存在するかどうかを確認する if (file_exists($filePath)) { header("Content-type: octet/stream"); //画像ファイルのサイズを取得する // $PSize = filesize($imgPath); // //画像リソースを読む // $picturedata = fread(fopen($imgPath, "r"), $PSize); // echo $picturedata; $out_file_size = stat($filePath)['size']; header("Content-Range:0-" . ($out_file_size - 1) . "/$out_file_size"); header("Content-Length:" . $out_file_size); echo file_get_contents($filePath); exit(); } else { //カスタム応答コード http_response_code(404); throw new BadRequestException('File not exists'); } } public function downloadImgV3() { //写真の名前 $imgUrl = $this->imgUrl; $index = mb_strpos($imgUrl, '.jpg'); if ($index == false) { return "图片不存在"; } // 获取字符最后出现的索引位置 $last_index = strrpos($imgUrl, '/'); //倒数第二次出现的位置 $last_index_next = strrpos(substr($imgUrl, 0, $last_index), '/'); $dir = substr($imgUrl, $last_index_next + 1, $last_index - $last_index_next - 1); $fileName = substr($imgUrl, ($last_index + 1)); DI()->logger->info("downloadImgV3", "params:" . json_encode(array("imgUrl" => $imgUrl, "fileName" => $fileName))); //サーバー上に保存されている画像のファイル名 // $imgPath = sprintf('https://%s/shima-clc.com/car/detail/upload/zebra/%s', $_SERVER['SERVER_NAME'], $name); //画像アクセスパス switch ($dir) { case "zebra" : $imageUploadDir = DI()->config->get("app.imageUploadDir"); break; case "general": $imageUploadDir = DI()->config->get("app.generalImageUploadDir"); break; case "quote": $imageUploadDir = DI()->config->get("app.quoteImageUploadDir"); break; case "cars": $imageUploadDir = DI()->config->get("app.carPhotoUploadDir"); break; } $imgPath = sprintf($imageUploadDir . '%s', $fileName); DI()->logger->info("downloadImgV3", "imgPath:" . $imgPath); //画像リソースが存在するかどうかを確認する if (file_exists($imgPath)) { header("Content-type: image/jpg"); //画像ファイルのサイズを取得する // $PSize = filesize($imgPath); // //画像リソースを読む // $picturedata = fread(fopen($imgPath, "r"), $PSize); // echo $picturedata; $out_file_size = stat($imgPath)['size']; header("Content-Range:0-" . ($out_file_size - 1) . "/$out_file_size"); header("Content-Length:" . $out_file_size); echo file_get_contents($imgPath); exit(); } else { //カスタム応答コード http_response_code(404); throw new BadRequestException('Image not exists'); } } /** * @brief 車両の写真を取得する * -注文IDに基づいて車両のすべての写真を取得します * @param orderId 注文ID * @return array|void */ public function getCarPhotos() { //注文ID $orderId = $this->orderId; DI()->logger->info("getCarPhotos", "params:" . json_encode(array("orderId" => $orderId))); //サーバー上に保存されている画像のファイル名 $name = $orderId . '_'; //設定ファイル内の画像のアップロードアドレスを取得します。 $imageUploadDir = DI()->config->get("app.carPhotoUploadDir"); //判断目录是否存在 if (is_dir($imageUploadDir)) { if ($dh = opendir($imageUploadDir)) { $i = 0; while (($file = readdir($dh)) !== false) { if (str_starts_with($file, $name)) { $files[$i]['name'] = $file;//获取文件名 $files[$i]["time"] = date("Y-m-d H:i:s", filemtime($file));//获取文件最近修改日期 $i++; } } } closedir($dh); foreach ($files as $k => $v) { $time[$k] = $v['time']; } array_multisort($time, SORT_ASC, SORT_STRING, $files);//按时间排序 foreach ($files as $k => $v) { $carPhotos[$k]['name'] = $v['name']; $carPhotos[$k]['path'] = $imageUploadDir; } return $carPhotos; } } /** * @brief 車検情報の一元アップロード * * -1車 ID に従って車両レコードをクエリします。車両レコードが存在しない場合は、受信した車両情報を dat_cars テーブルに追加します。 * 車両記録が存在する場合は受信した車両情報を更新する。 * -2車の ID に従って膜厚レコードをクエリします。膜厚レコードが存在しない場合は、受け取った膜厚情報を dat_vc_film_thickness テーブルに追加します。 * 膜厚記録が存在する場合は受信した膜厚情報を更新する。 * -3連絡先 ID に従って連絡先レコードをクエリします。連絡先レコードが存在しない場合は、受信した連絡先情報を dat_vc_contact テーブルに追加します * 連絡先レコードが存在する場合は、受信した連絡先情報を更新します。 * -4車の ID に従って obd 障害レコードをクエリします。obd 障害レコードが存在しない場合は、受信した obd 障害を dat_vc_obd テーブルに追加します。 * obd 障害レコードが存在する場合は、それを直接スキップし、更新しないでください。 * -5連絡先IDを更新し、注文テーブルのステータスを初期ステータスに確認します * -6注文にバインドされたuuidを削除します * * * @param orderId 注文ID * @param customerId お客様ID * @param number 登録番号 * @param vin 車台番号 * @param syodoDate 登録年月日 * @param katashiki 型式 * @param katashikiShitei 型式指定番号 * @param ruibetsu 類別区分番号 * @param gendouki 原動機型式 * @param drive 駆動 * @param nenryou 燃料 * @param syaken 車検有効期限 * @param millage 走行距離 * @param orderId オーダーID * @param dataR1 右上から1番目の査定値 * @param dataR2 右上から2番目の査定値 * @param dataR3 右上から3番目の査定値 * @param dataR4 右上から4番目の査定値 * @param dataR5 右上から5番目の査定値 * @param dataR6 右上から6番目の査定値 * @param dataR7 右上から7番目の査定値 * @param dataR8 右上から8番目の査定値 * @param dataR9 右上から9番目の査定値 * @param dataR10 右上から10番目の査定値 * @param dataR11 右上から11番目の査定値 * @param dataR12 右上から12番目の査定値 * @param dataL1 左上から1番目の査定値 * @param dataL2 左上から2番目の査定値 * @param dataL3 左上から3番目の査定値 * @param dataL4 左上から4番目の査定値 * @param dataL5 左上から5番目の査定値 * @param dataL6 左上から6番目の査定値 * @param dataL7 左上から7番目の査定値 * @param dataL8 左上から8番目の査定値 * @param dataL9 左上から9番目の査定値 * @param dataL10 左上から10番目の査定値 * @param dataL11 左上から11番目の査定値 * @param dataL12 左上から12番目の査定値 * @param dataRoof1 ルーフの査定値(前) * @param dataRoof2 ルーフの査定値(後) * @param contactComment 連絡備考 * @param contactWay 連絡方法 * @param damageLevel ダメージの程度 * @param errorNos 障害番号 * * @return 更新結果、フォーマットはJSON * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - data: データ * - msg: 正常にアップロードされました * - msg: プロンプトメッセージ */ public function uploadData() { //注文ID $orderId = $this->orderId; DI()->logger->info("uploadData", 'orderId:' . $orderId); $orderDomain = new DatSyakenOrderListDomain(); //orderId による注文データのクエリ $orderInfo = $orderDomain->get($orderId); if (empty($orderInfo)) { throw new BadRequestException("order is invalid"); } // SSID $ssId = $orderInfo['Shop_ID']; // SS情報を取得する $mtssDomain = new MtssDomain(); $mtss = $mtssDomain->get($ssId); //車両ID $carId = $orderInfo['Car_ID']; $syaken = $this->syaken; if (strlen($syaken) > 10) { $syaken = substr($syaken, 0, 10); } try { //車の情報 $carData = ['customer_ID' => $this->customerId, 'Number' => $this->number, 'VIN' => $this->vin, 'syodo_date' => $this->syodoDate, 'katashiki' => $this->katashiki, 'Katashiki_Shitei' => $this->katashikiShitei, 'ruibetsu' => $this->ruibetsu, 'gendouki' => $this->gendouki, 'drive' => $this->drive, 'nenryou' => $this->nenryou, 'Syaken' => $syaken, 'Millage' => $this->millage, 'ss_id' => $ssId, 'ss_id' => $ssId, 'Year' => $this->year, 'Inspection_Date' => date("Y-m-d"), 'LastModify_Date' => date('Y-m-d'), 'Delivary_Date' => $this->delivaryDate, 'keijyou' => $this->keijyou, 'jyuuryou' => $this->jyuuryou, 'syoyuusya_name' => $this->syoyuusyaName, 'syoyuusya_address' => $this->syoyuusyaAddress, 'shiyousya_name' => $this->shiyousyaName, 'shiyousya_address' => $this->shiyousyaAddress]; //Null値をフィルタリングする $carData = array_filter($carData); DI()->logger->info("uploadData", 'update dat_cars data:' . json_encode($carData)); $carsDomain = new DatCarsDomain(); //車のIDが存在するかどうかを確認する if (empty($carId) || !$carsDomain->checkSyakenCar($carId)) { $carData['Custmer_Trigger'] = 7;//シマース査定車両 if ($mtss['ss_name'] == 'apple') { $carData['Custmer_Trigger'] = 1; } $carData['Create_Date'] = date('Y-m-d'); //顧客IDに基づいて顧客情報を照会する $customerId = $orderInfo['Customer_ID']; $customerDomain = new DatCustomerDomain(); $customerInfo = $customerDomain->get($customerId); //依頼者 dat_customer name dat_cars.contruct_customer にもコピー $data['contruct_customer'] = $customerInfo['name']; //依頼者 dat_customer customer_address dat_cars.addr にもコピー $data['addr'] = $customerInfo['customer_address']; //新しい車両情報を追加します $carId = $carsDomain->insert($carData); //注文情報の車 ID フィールドを更新します。 $orderDomain->updateOrderInfoByOrderId($orderId, ['Car_ID' => $carId]); } else { //車両インテリジェンス情報を更新する $carsDomain->updateCarsInfo($carId, $carData); } $dataR1 = $this->get_int_val($this->dataR1); $dataR2 = $this->get_int_val($this->dataR2); $dataR3 = $this->get_int_val($this->dataR3); $dataR4 = $this->get_int_val($this->dataR4); $dataR5 = $this->get_int_val($this->dataR5); $dataR6 = $this->get_int_val($this->dataR6); $dataR7 = $this->get_int_val($this->dataR7); $dataR8 = $this->get_int_val($this->dataR8); $dataR9 = $this->get_int_val($this->dataR9); $dataR10 = $this->get_int_val($this->dataR10); $dataR11 = $this->get_int_val($this->dataR11); $dataR12 = $this->get_int_val($this->dataR12); $dataL1 = $this->get_int_val($this->dataL1); $dataL2 = $this->get_int_val($this->dataL2); $dataL3 = $this->get_int_val($this->dataL3); $dataL4 = $this->get_int_val($this->dataL4); $dataL5 = $this->get_int_val($this->dataL5); $dataL6 = $this->get_int_val($this->dataL6); $dataL7 = $this->get_int_val($this->dataL7); $dataL8 = $this->get_int_val($this->dataL8); $dataL9 = $this->get_int_val($this->dataL9); $dataL10 = $this->get_int_val($this->dataL10); $dataL11 = $this->get_int_val($this->dataL11); $dataL12 = $this->get_int_val($this->dataL12); $dataRoof1 = $this->get_int_val($this->dataRoof1); $dataRoof2 = $this->get_int_val($this->dataRoof2); //膜厚データ $filmThicknessData = ['car_id' => $carId, 'data_r1' => $dataR1, 'data_r2' => $dataR2, 'data_r3' => $dataR3, 'data_r4' => $dataR4, 'data_r5' => $dataR5, 'data_r6' => $dataR6, 'data_r7' => $dataR7, 'data_r8' => $dataR8, 'data_r9' => $dataR9, 'data_r10' => $dataR10, 'data_r11' => $dataR11, 'data_r12' => $dataR12, 'data_l1' => $dataL1, 'data_l2' => $dataL2, 'data_l3' => $dataL3, 'data_l4' => $dataL4, 'data_l5' => $dataL5, 'data_l6' => $dataL6, 'data_l7' => $dataL7, 'data_l8' => $dataL8, 'data_l9' => $dataL9, 'data_l10' => $dataL10, 'data_l11' => $dataL11, 'data_l12' => $dataL12, 'data_roof1' => $dataRoof1, 'data_roof2' => $dataRoof2 ]; DI()->logger->info("uploadData", 'update dat_vc_film_thickness data:' . json_encode($filmThicknessData)); //Null値をフィルタリングする $filmThicknessData = array_filter($filmThicknessData); //膜厚データの保存または更新 if (!empty($filmThicknessData)) { $filmThicknessDomain = new DatVcFilmThickness(); $filmThicknessDomain->saveOrUpdateFilmThickness($carId, $filmThicknessData); } //連絡情報の登録 //連絡情報ID $contactId = $orderInfo['contact_id']; //連絡情報数据 $contactData = ['contact_comment' => $this->contactComment, 'contact_way' => $this->contactWay, 'damage_level' => $this->damageLevel]; DI()->logger->info("uploadData", 'update dat_vc_contact data:' . json_encode($contactData)); $contactData = array_filter($contactData); if (!empty($contactData)) { $contactDomain = new DatVcContactDomain(); //連絡先インテリジェンス データを保存または更新する $contactId = $contactDomain->saveOrUpdateContact($contactId, $contactData); } //OBD障害番号を保存 DI()->logger->info("saveVcOBD", "params:" . json_encode(array("carId" => $carId, "errorNos" => $this->obd))); if (!empty($this->obd)) { $obdDomain = new DatVcObdDomain(); $obdDomain->saveVcOBD($carId, $this->obd); if(!empty($this->katashiki)){ $mtObdUnitPrice = new MtObdUnitPriceDomain(); $mtPriceList = $mtObdUnitPrice->saveObdUnitPrice($this->katashiki,$this->obd); } } //更新订单state状态,如果service是查定把state从1更新成2,如果service是其他把state从4更新到5 $state = State::WAITING_REPLY; //查定情况下,state是査定前 if ($orderInfo['service'] == ServiceStatus::CHECK) { $state = State::ASSESSED; } $data = ['contact_id' => $contactId, 'check_state' => CheckState::NOT_UNDER_ASSESSMENT, 'state' => $state,'reply_date' => date('Y-m-d H:i', time())]; DI()->logger->info("uploadData", 'update order data:' . json_encode($data)); //更新 $orderDomain->updateOrderInfoByOrderId($orderId, $data); //完成之后删除order绑定的uuid $orderUuidDomain = new DatOrderUuidDomain(); $orderUuidDomain->deleteByOrderId($orderId); //重新生成车检图片 $this->doSaveInspect(); if ($orderInfo['service'] == 1) { // 20240508 Add 判断是否是第一次发送,防止多次发送 Start $datVcLineNotifyDomain = new DatVcLineNotifyDomain(); $sendInfo = $datVcLineNotifyDomain->getSendRecord($orderId); if ($sendInfo === false) { $newCarInfo = $carsDomain->get($carId); $lineDomain = new DatLineMsgDomain(); $lineDomain->saveMsg( sprintf("🚗%sより新規査定登録がありました。%s、%s、%s", $mtss['ss_name'], $this->year, $newCarInfo['Car_Name'], date('Y-m-d H:i:s') ), null,$orderId); $datVcLineNotifyDomain->save($orderId); } else { DI()->logger->info("uploadData", 'sendInfo '. json_encode($sendInfo)); DI()->logger->info("uploadData", 'Order ' .$orderId. ' Line Notify is already sent at :' . $sendInfo['create_date']); } // 20240508 Add 判断是否是第一次发送,防止多次发送 End } } catch (Exception $e) { DI()->logger->error("uploadData", "exception:" . $e); throw new BadRequestException("Failed to upload data"); } DI()->response->setMsg("upload data success"); return array('msg' => "正常にアップロードされました"); } /** * @brief ログアウト * * 注文 ID とタイムスタンプを使用してバインドされた UUID レコードをクエリし、クエリ後にレコードを削除します。 * 注文テーブルのチェック状態を初期状態に更新します * 正常に削除されました。true を返します * 削除に失敗しました。false を返します * * @param orderId 注文ID * @param timestamp タイムスタンプ * * @return 判定結果のJSONデータ * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - msg: プロンプトメッセージ * - data: 判定結果、Trueは更新ある、Falseは更新無し */ public function logout() { //注文ID $orderId = $this->orderId; //タイムスタンプ $timestamp = $this->timestamp; DI()->logger->info("logout", "params:" . json_encode(array("orderId" => $orderId, "timestamp" => $timestamp))); $orderUuidDomain = new DatOrderUuidDomain(); //注文 ID とタイムスタンプに基づいてバインドされた UUID レコードをクエリします $data = $orderUuidDomain->getData(['order_id' => $orderId, 'ts <= ?' => $timestamp]); if ($data) { //バインドされたuuidレコードを削除する $result = $orderUuidDomain->deleteByOrderId($orderId); DI()->logger->info("logout", "delete count:" . $result); } //注文テーブルのチェック状態を初期状態に更新します $orderDomain = new DatSyakenOrderListDomain(); $orderDomain->updateOrderInfoByOrderId($orderId, ['check_state' => 0]); return true; } /** * @brief 案件検索 * * 受信した申請内容、ステータス、担当者に応じて該当する案件データを問い合わせ、JSON形式で返す * * @param serviceStatus サービスの選択 * @param serviceStatusList 複数のサービスタイプ * @param state 状態 * @param shopId 担当者ID * * @return 結果のJSONデータ * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - msg: プロンプトメッセージ * - data: アンケート情報JSONデータ * */ public function orderList() { //サービスの選択 $serviceStatus = $this->serviceStatus; //複数のサービスタイプ $serviceStatusList = $this->serviceStatusList; //状態 $state = $this->state; //担当者ID $shopId = $this->shopId; //自由词 $freeword = $this->freeword; //注文ID $orderId = $this->orderId; DI()->logger->info("orderList", "shopId:" . $shopId); if ($shopId == null) { $decoder = new JWTDecoder(); $jwt = $decoder->decode(); DI()->logger->info("orderList", "jwt:" . json_encode($jwt)); if ($jwt != null) { $jwtData = $jwt["data"]; $shopId = $jwtData->ssid; } if ($shopId == null) { $shopId = -1; } } //ロギング DI()->logger->info("orderList", "params:" . json_encode(array('serviceStatus' => $serviceStatus, 'state' => $state, 'shopId' => $shopId, '$freeword' => $freeword, '$orderId' => $orderId))); $orderDomain = new DatSyakenOrderListDomain(); //クエリ条件に従って注文リストデータを取得する $result = $orderDomain->getOrderList($serviceStatus, $state, $shopId, $freeword,$orderId, $serviceStatusList); // DI()->logger->info("orderList", "result: ".json_encode($result)); return $result; } /** * @brief 案件検索 * * 受信した申請内容、ステータス、担当者に応じて該当する案件データを問い合わせ、JSON形式で返す * * @param serviceStatus サービスの選択 * @param serviceStatusList 複数のサービスタイプ * @param state 状態 * @param shopId 担当者ID * * @return 結果のJSONデータ * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - msg: プロンプトメッセージ * - data: アンケート情報JSONデータ * */ public function orderListV2() { //サービスの選択 $serviceStatus = $this->serviceStatus; //複数のサービスタイプ $serviceStatusList = $this->serviceStatusList; //状態 $state = $this->state; //担当者ID $shopId = $this->shopId; //自由词 $freeword = $this->freeword; DI()->logger->info("orderListV2", "shopId:" . $shopId); if ($shopId == null) { $decoder = new JWTDecoder(); $jwt = $decoder->decode(); DI()->logger->info("orderListV2", "jwt:" . json_encode($jwt)); if ($jwt != null) { $jwtData = $jwt["data"]; $shopId = $jwtData->ssid; } if ($shopId == null) { $shopId = -1; } } //ロギング DI()->logger->info("orderListV2", "params:" . json_encode(array('serviceStatus' => $serviceStatus, 'state' => $state, 'shopId' => $shopId, '$freeword' => $freeword))); $orderDomain = new DatSyakenOrderListDomain(); //クエリ条件に従って注文リストデータを取得する $result = $orderDomain->getOrderListV2($serviceStatus, $state, $shopId, $freeword, $serviceStatusList); // DI()->logger->info("orderList", "result: ".json_encode($result)); return $result; } /** * @brief 案件検索V3 * * 受信した申請内容、ステータス、担当者に応じて該当する案件データを問い合わせ、JSON形式で返す * * @param serviceStatus サービスの選択 * @param serviceStatusList 複数のサービスタイプ * @param state 状態 * @param shopId 担当者ID * * @return 結果のJSONデータ * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - msg: プロンプトメッセージ * - data: アンケート情報JSONデータ * */ public function orderListV3() { //サービスの選択 $serviceStatus = $this->serviceStatus; //複数のサービスタイプ $serviceStatusList = $this->serviceStatusList; //状態 $state = $this->state; //担当者ID $shopId = $this->shopId; //自由词 $freeword = $this->freeword; DI()->logger->info("orderListV3", "shopId:" . $shopId); if ($shopId == null) { $decoder = new JWTDecoder(); $jwt = $decoder->decode(); DI()->logger->info("orderListV3", "jwt:" . json_encode($jwt)); if ($jwt != null) { $jwtData = $jwt["data"]; $shopId = $jwtData->ssid; } if ($shopId == null) { $shopId = -1; } } //ロギング DI()->logger->info("orderListV3", "params:" . json_encode(array('serviceStatus' => $serviceStatus, 'state' => $state, 'shopId' => $shopId, '$freeword' => $freeword))); $orderDomain = new DatSyakenOrderListDomain(); //クエリ条件に従って注文リストデータを取得する $result = $orderDomain->getOrderListV3($serviceStatus, $state, $shopId, $freeword, $serviceStatusList); // DI()->logger->info("orderList", "result: ".json_encode($result)); return $result; } public function getSSAndCarNameByOrderId() { $orderId = $this->orderId; DI()->logger->info("orderId", "result: " . $orderId); $orderDomain = new DatSyakenOrderListDomain(); $order = $orderDomain->get($orderId); if (empty($order)) { throw new BadRequestException('注文は存在しません', 0); } $carId = $order['Car_ID']; $ssId = $order['Shop_ID']; $dataCarModel = new DataCarModel(); $carName = $dataCarModel->findCarsByCarId($carId)['Car_Name']; $mtSsDomain = new MtSsDomain(); $ssName = $mtSsDomain->get($ssId)['ss_name']; return array('carName' => $carName, 'ssName' => $ssName); } /** * @brief 備考更新IF * 渡された注文IDとコメントに基づいて更新操作を実行します * * @param orderId 注文ID * @param remark 備考 * * @return 結果のJSONデータ * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - msg: プロンプトメッセージ * - data: JSONデータ */ public function updateRemark() { //注文ID $orderId = $this->orderId; //備考 $remark = $this->remark; //ロギング DI()->logger->info("updateRemark", "params:" . json_encode(array('orderId' => $orderId, 'remark' => $remark))); $datSyakenOrderList = new DatSyakenOrderListDomain(); //注文メモを更新する $data = ['remark' => $remark]; $updateOrderInfoByOrderId = $datSyakenOrderList->updateOrderInfoByOrderId($orderId, $data); //ロギング DI()->logger->info("updateRemark", "updateOrderInfoByOrderId result:" . $updateOrderInfoByOrderId); return array("msg" => 'アップデートが完了しました'); } /** * @brief 状態更新IF * 渡された注文IDと状態と未成約事由に基づいて更新操作を実行します * * @param orderId 注文ID * @param state 状態 * @param Void_reason 未成約事由 * * @return 結果のJSONデータ * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - msg: プロンプトメッセージ * - data: JSONデータ */ public function updateState() { //注文ID $orderId = $this->orderId; //備考 $state = $this->state; $reason = $this->reason; $datSyakenOrderList = new DatSyakenOrderListDomain(); //orderId による注文データのクエリ $orderInfo = $datSyakenOrderList->get($orderId); if (empty($orderInfo)) { throw new BadRequestException("order is invalid"); } $oldState = $orderInfo['state']; //Car_IDにより、車情報を取得する $carsDomain = new DatCarsDomain(); $carInfo = $carsDomain->getCarInfo($orderInfo['Car_ID']); //ロギング DI()->logger->info("updateState", "params:" . json_encode(array('orderId' => $orderId, 'state' => $state, 'reason' => $reason))); //注文メモを更新する if ($reason != null) { $data = ['state' => $state, 'reason' => $reason]; } else { $data = ['state' => $state]; } $now = date('Y-m-d H:i', time()); if ($state == 6) { $data['Arrival_Date'] = $now; } if($state == 7){ $data['mc_stock_date'] = $now; } if ($state == 8) { $data['ss_return_date'] = $now; } if($state == 9){ $data['Complete_Date'] = $now; } if($state == State::WAITING_PAYMENT){ $data['settle_date'] = $now; } if($state == State::DELIVERED){ $data['delivered_date'] = $now; } if($state == State::SYAKEN_SEND){ $data['syaken_send_date'] = $now; if($orderInfo['cancel_flag'] == 1){ $state = State::CANCELED; $data['state'] = $state; } } $updateOrderInfoByOrderId = $datSyakenOrderList->updateOrderInfoByOrderId($orderId, $data); //ロギング DI()->logger->info("updateState", "updateOrderInfoByOrderId result:" . $updateOrderInfoByOrderId); $mtssDomain = new MtssDomain(); // $mtssInfo = $mtssDomain->get($orderInfo['Shop_ID']); // $openIds = $mtssInfo['line_openid']; $mcInfo = $mtssDomain->getUserByLoginId('mecha'); // $mcId = $mcInfo['line_openid']; // if ($mcId != null) { // if ($state == 6) { // $openIds = $mcId; // }elseif ($state == 7) { // $openIds = $openIds.",".$mcId; // } // } $toUserIDs = null; $mtssInfo = $mtssDomain->get($orderInfo['Shop_ID']); $datLineUserDomain = new DatLineUserDomain(); if(LineMessagingApiConfig::newApi == 1){ $ssid = $orderInfo['Shop_ID']; $mcSsid = $mcInfo['ID']; if ($state == 6) { $ssid = null; }elseif ($state == 9) { $mcSsid = null; } $lineUserIds = $datLineUserDomain->getLineUserIdBySsid($ssid,$mcSsid); $toUserIDs = implode(',',array_map(function($item) { return $item['userId']; }, $lineUserIds)); }else{ $toUserIDs = $mtssInfo['line_openid']; $mcId = $mcInfo['line_openid']; if ($mcId != null) { if ($state == 6) { $toUserIDs = $mcId; }elseif ($state == 7) { $toUserIDs = $toUserIDs.",".$mcId; } } } //顧客IDに基づいて顧客情報を照会する $customerId = $orderInfo['Customer_ID']; $customerDomain = new DatCustomerDomain(); $customerInfo = $customerDomain->get($customerId); $lineDomain = new DatLineMsgDomain(); if ($state == 6) { $datCarsStorageReservationDomain = new DatCarsStorageReservationDomain(); $mcStorageDate = $datCarsStorageReservationDomain->getStorageDateByOrderId($orderId); $dateTime = new DateTime($mcStorageDate); $formattedDate = $dateTime->format('Y年m月d日'); $lineDomain->saveMsg( sprintf("🚗新しい整備依頼が発生しました。(%s、%s、%s、MC入庫予定日:%s)", $mtssInfo['ss_name'],$carInfo['carName'], $carInfo['number'],$formattedDate ), $toUserIDs,$orderId); } elseif ($state == 7) { $lineDomain->saveMsg( sprintf("🚗SS出庫準備が整いました。(%s、%s、%s)", $mtssInfo['ss_name'],$carInfo['carName'], $carInfo['number'] ), $toUserIDs,$orderId); } elseif ($state == 9 && $oldState == 8) { $lineDomain->saveMsg( sprintf("🚗作業が完了しました。(%s、%s、%s)", $customerInfo['name'].$customerInfo['customer_name'],$carInfo['carName'], $carInfo['number'] ), $toUserIDs,$orderId); }elseif($state == 3){//成約 //成約flag $receivers = $datLineUserDomain->list(['seiyakuNoticeSw'=>1]); $toNoticeIDs = implode(',',array_map(function($item) { return $item['userId']; }, $receivers)); if(!empty($toNoticeIDs)){ $lineDomain->saveMsg( sprintf("🚗案件が成約しました。(ID:%s、%s、%s)", $orderId,$mtssInfo['ss_name'],$carInfo['carName'] ), $toNoticeIDs,$orderId); } } return array("msg" => 'アップデートが完了しました'); } /** * @brief 获取フィールド制御 * 根据接收到的viewId获取表单字段控制信息 * @param viewId ビューID * @return 結果のJSONデータ * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - msg: プロンプトメッセージ * - data: JSONデータ */ public function getFormCtrlInfo() { //获取フィールド制御 $viewId = $this->viewId; DI()->logger->info("getFormCtrlInfo", "params:" . json_encode(array('viewId' => $viewId))); $formCtrlDomain = new MtVcFormCtrlDomain(); $data['mtVcFormCtrl'] = $formCtrlDomain->getFormCtrlInfo(['view_id' => $viewId]); return $data; } /** * @brief 一般整備 * * 受け取った車両 ID、店舗 ID、顧客 ID、およびサービスの選択に基づいて新しい一般注文レコードを作成します * * @param carId 車両ID * @param shopId ショップID * @param customerId 顧客ID * @param serviceStatus サービスの選択 * * @return 結果のJSONデータ * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - msg: プロンプトメッセージ * - data: JSONデータ */ public function addGeneralOrder() { //車両ID $carId = $this->carId; //ショップID $shopId = $this->shopId; //顧客ID $customerId = $this->customerId; //サービスの選択 $serviceStatus = $this->serviceStatus; DI()->logger->info("addGeneralOrder", "params:" . json_encode(array("carId" => $carId, "shopId" => $shopId, "customerId" => $customerId, 'serviceStatus' => $serviceStatus))); //注文の作成 $orderDomain = new DatSyakenOrderListDomain(); $data = ['Customer_ID' => $customerId, 'Car_ID' => $carId, 'Shop_ID' => $shopId, 'service' => $serviceStatus, 'check_state' => CheckState::NOT_UNDER_ASSESSMENT, 'state' => State::ACCEPTING, 'recept_date'=>date('Y-m-d H:i', time())]; //去除空字段 $data = array_filter($data); $orderId = $orderDomain->insert($data); DI()->logger->info("addGeneralOrder", "新创建的订单记录id:" . $orderId); return array("msg" => "正常に保存"); } /** * @brief 一般整備依頼事項の登録 * * 1、根据获取到传过来的一般整備依頼事項在dat_general_order表和dat_general_order_detail表新增对应的记录, * 2、通过orderId把新增好的general_order_id更新到dat_syaken_order_list表 * -# 更新が成功し、ステータス 200 を返します。 * -# 更新に失敗しました。ステータス 400 を返します。msg: 失敗メッセージ。 * * @param orderId 注文ID * @param index 索引 * @param freeword 自由词 * @param photo 图片地址 * */ public function saveGeneralMaintenanceRequests() { //注文ID $orderId = $this->orderId; //依頼事項 $requestMatters = $this->requestMatters; DI()->logger->info("saveGeneralMaintenanceRequests", "params:" . json_encode(array("orderId" => $orderId, "requestMatters" => $requestMatters))); $datGeneralOrder = new DatGeneralOrder(); //新しい一般注文レコードを追加し、主キー ID を返します $generalOrderId = $datGeneralOrder->insert(); DI()->logger->info("saveGeneralMaintenanceRequests", "新创建的一般订单记录id:" . $generalOrderId); $datGeneralOrderDetail = new DatGeneralOrderDetail(); //依頼事項保存 $datGeneralOrderDetail->saveGeneralOrderDetail($generalOrderId, $requestMatters); $datSyakenOrderList = new DatSyakenOrderListDomain(); //更新dat_syaken_order_list表对应记录的general_order_id字段 $data = ['general_order_id' => $generalOrderId]; $datSyakenOrderList->updateOrderInfoByOrderId($orderId, $data); return array("msg" => "正常に保存"); } /** * @brief 統合されたデータのアップロード * * @param orderId 注文ID * @param carInfo 车辆情报 * @param vehicleInspectionQuoteInfo 车检报价 * @param generalMaintenanceRequestsInfo 一般整备 * * @return 更新結果、フォーマットはJSON * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - data: データ配列 * - msg 正常に保存 * - msg: プロンプトメッセージ */ public function uploadDataV2() { $orderId = $this->orderId; $carInfo = $this->carInfo; $carId = $carInfo['carId']; $vehicleInspectionQuoteInfo = $this->vehicleInspectionQuoteInfo; $generalMaintenanceRequestsInfo = $this->generalMaintenanceRequestsInfo; DI()->logger->info("uploadDataV2", "車両情報:" . json_encode($carInfo)); DI()->logger->info("uploadDataV2", "車検見積もり:" . json_encode($vehicleInspectionQuoteInfo)); DI()->logger->info("uploadDataV2", "一般整备:" . json_encode($generalMaintenanceRequestsInfo)); if (empty($orderId)) { return "注文は存在しません"; } //根据orderId获取订单信息 $orderDomain = new DatSyakenOrderListDomain(); $orderInfo = $orderDomain->get($orderId); // SS情報を取得する $mtssDomain = new MtssDomain(); $mtss = $mtssDomain->get($orderInfo['Shop_ID']); $customerBasicFeeDomain = new MtCustomerBasicFeeDomain(); $customerBasicFee = $customerBasicFeeDomain->getCustomerBasicFee($orderId); if (!empty($customerBasicFee)) { $customerBasicFee = $customerBasicFee[0]; } else { $customerBasicFee = []; } $katashiki = ""; if (!empty($carInfo)) { //更新が必要な車両情報を収集中 $data = ['customer_ID' => $carInfo["customerId"], 'Number' => $carInfo["number"], 'VIN' => $carInfo["vin"], 'syodo_date' => $carInfo["syodoDate"], 'katashiki' => $carInfo["katashiki"], 'Katashiki_Shitei' => $carInfo["katashikiShitei"], 'ruibetsu' => $carInfo["ruibetsu"], 'gendouki' => $carInfo["gendouki"], 'drive' => $carInfo["drive"], 'nenryou' => $carInfo["nenryou"], 'Syaken' => $carInfo["syaken"], 'Millage' => $carInfo["millage"], 'Delivary_Date' => $carInfo["delivaryDate"], 'keijyou' => $carInfo["keijyou"], 'jyuuryou' => $carInfo["jyuuryou"], 'syoyuusya_name' => $carInfo["syoyuusyaName"],'syoyuusya_address' => $carInfo["syoyuusyaAddress"], 'shiyousya_name' => $carInfo["shiyousyaName"], 'shiyousya_address' => $carInfo["shiyousyaAddress"], 'Registry_Name' => $carInfo["syoyuusyaName"],'Registry_Address' => $carInfo["syoyuusyaAddress"], 'ex_shiyousya_name' => $carInfo["shiyousyaName"], 'ex_shiyousya_address' => $carInfo["shiyousyaAddress"], 'Year' => $carInfo['year']]; //Null値をフィルタリングする $data = array_filter($data); DI()->logger->info("updateCarsInfo", "update dat_cars data:" . json_encode($data)); //車のIDカード情報を更新する $carsDomain = new DatCarsDomain(); //車のIDが存在するかどうかを確認する if (empty($carId)) { $data['Custmer_Trigger'] = 7;//シマース査定車両 if ($mtss['ss_name'] == 'apple') { $data['Custmer_Trigger'] = 1; } $data['Create_Date'] = date('Y-m-d'); //顧客IDに基づいて顧客情報を照会する $customerId = $orderInfo['Customer_ID']; $customerDomain = new DatCustomerDomain(); $customerInfo = $customerDomain->get($customerId); //依頼者 dat_customer name dat_cars.contruct_customer にもコピー $data['contruct_customer'] = $customerInfo['name']; //依頼者 dat_customer customer_address dat_cars.addr にもコピー $data['addr'] = $customerInfo['customer_address']; //新しい車両情報を追加します $carId = $carsDomain->insert($data); } else { //車両インテリジェンス情報を更新する $carsDomain->updateCarsInfo($carId, $data); } $katashiki = $carInfo["katashiki"]; } if (!empty($vehicleInspectionQuoteInfo)) { $datVehicleInspectionQuote = new DatVehicleInspectionQuote(); //車検見積内容の保存 $datVehicleInspectionQuote->saveVehicleInspectionQuote($orderId, $vehicleInspectionQuoteInfo); } if (!empty($generalMaintenanceRequestsInfo)) { $datGeneralOrder = new DatGeneralOrder(); //一般整備依頼事項の登録 $datGeneralOrder->saveGeneralMaintenanceRequests($orderId, $generalMaintenanceRequestsInfo); } // 生成需要的诸费用 $datMiscellaneousExpensesDetailDomain = new DatMiscellaneousExpensesDetailDomain(); DI()->logger->info("uploadDataV2", "customerBasicFee: ".json_encode($customerBasicFee)); if ($orderInfo['service'] == ServiceStatus::VEHICLE_INSPECTION) { $miscellaneousExpensesData = [ [ "item" => "重量税", "months" => null, "amount" => null ], [ "item" => "自賠責", "months" => null, "amount" => null ], [ "item" => "印紙", "months" => null, "amount" => null ] ]; } elseif ($orderInfo['service'] == ServiceStatus::INLAW_CHECK) { $miscellaneousExpensesData = [ [ "item" => "重量税", "months" => null, "amount" => null ], [ "item" => "自賠責", "months" => null, "amount" => null ], [ "item" => "印紙", "months" => null, "amount" => null ] ]; } $datMiscellaneousExpensesDetailDomain->saveMiscellaneousExpenses($orderId,$miscellaneousExpensesData); //同时生成维修记录 $orderDomain->addRepairEstimates($orderId,$orderInfo['service'],$vehicleInspectionQuoteInfo,$generalMaintenanceRequestsInfo, $customerBasicFee, $katashiki); //更新订单state状态,如果service是查定把state从1更新成2,如果service是其他把state从4更新到5 $state = State::WAITING_REPLY; //查定情况下,state是査定前 if ($orderInfo['service'] == ServiceStatus::CHECK) { $state = State::ASSESSED; } $orderDomain->updateOrderInfoByOrderId($orderId, ['state' => $state, 'Car_ID' => $carId,'reply_date' => date('Y-m-d H:i', time())]); return array("msg" => "正常に保存"); } /** * @brief 車検画像生成 * 注文Idを元に車両情報、連絡先情報、膜厚情報、OBD情報、顧客情報を取得し、対応する情報を画像の指定位置に記入し、新たな車検画像を生成します。 * イメージ名の生成規則orderId_inspect.png * * @param orderId 注文ID * @return string|void */ public function doSaveInspect() { //注文ID $orderId = $this->orderId; //根据orderId获取订单信息 $orderDomain = new DatSyakenOrderListDomain(); $orderInfo = $orderDomain->get($orderId); if (empty($orderId)) { return "注文は存在しません"; } //连络id $contactId = $orderInfo['contact_id']; //车辆id $carId = $orderInfo['Car_ID']; //客户id $customerId = $orderInfo['Customer_ID']; //店铺id $shopId = $orderInfo['Shop_ID']; //创建图片操作类 $image = new \PhalApi\Image\Lite(); //解析点位 $jsonFilePath = realpath(self::POSITION_JSON); $jsonData = file_get_contents($jsonFilePath); // 使用 json_decode 将 JSON 数据解码为 PHP 数组 $positionData = json_decode($jsonData, true); // 检查是否成功解码 if ($positionData === null && json_last_error() !== JSON_ERROR_NONE) { // 解码失败,处理错误 echo 'Error decoding JSON: ' . json_last_error_msg(); } if ($carId) {//車のIDが空ではありません //Car_IDにより、膜厚情報を取得 $filmThicknessDomain = new DatVcFilmThickness(); $filmThicknessInfo = $filmThicknessDomain->get($carId); //Car_IDにより、車情報を取得する $carsDomain = new DatCarsDomain(); $carInfo = $carsDomain->getCarInfo($carId); //obd故障信息 $datVcObdDomain = new DatVcObdDomain(); $datVcObdInfo = $datVcObdDomain->getObdErrorListByCarId($carId); //obd价格信息 $mtObdUnitPriceDomain = new MtObdUnitPriceDomain(); $obdUnitPrices = $mtObdUnitPriceDomain->getObdUnitPriceByKatashiki($carInfo['katashiki']); } //連絡先IDが空ではありません if ($contactId) { //連絡先IDに基づいて連絡先情報を取得する $contactDomain = new DatVcContact(); $contactInfo = $contactDomain->get($contactId); } if ($customerId) { //顧客IDに基づいて顧客情報を照会する $customerDomain = new DatCustomerDomain(); $customerInfo = $customerDomain->get($customerId); } if ($shopId) { $mtSsDomain = new MtssDomain(); $mtSsInfo = $mtSsDomain->get($shopId); } //打开图片 $image->open(self::IMAGE_PATH); //获取字体文件的绝对路径 $fontpath = realpath(self::FONT); //给图片自定义文字 foreach ($positionData as $value) { $key = $value['key']; $x = $value['x']; $y = $value['y']; //订单号 if ($key == "Order_ID") { //往图片对应位置写入orderId $image->text($orderId, $fontpath, self::FONT_SIZE, self::COLOR, array($x, $y)); //每个key只会对应一种数据,满足条件之后,后面的代码就不需要执行了,直接跳出本次循环进行下一次循环。 continue; } //日期 if ($key == "date") { //根据当前系统时间生成 $image->text($carInfo['Inspection_Date'], $fontpath, self::FONT_SIZE, self::COLOR, array($x, $y)); continue; } //客户名字 if ($key == "customer") { //判断不为空 if (!empty($customerInfo)) { if ($customerInfo['name']) { //客户名字只显示前两个字后面用**表示 $image->text(mb_substr($customerInfo['name'], 0, 2) . '**', $fontpath, self::FONT_SIZE, self::COLOR, array($x, $y)); } } continue; } //管理员名称 if ($key == "admin") { //在对应位置写入管理员名称 if (!empty($mtSsInfo['ss_name'])) { $image->text($mtSsInfo['ss_name'], $fontpath, self::FONT_SIZE, self::COLOR, array($x, $y)); } continue; } //膜厚数据 if (!empty($filmThicknessInfo)) { //判断不为空 if (!empty($filmThicknessInfo[$key])) { //在图片对应位置填入值需要加上符号μ $image->text($filmThicknessInfo[$key] . "μ", $fontpath, self::FONT_SIZE, self::COLOR, array($x, $y)); continue; } } //车辆信息 if (!empty($carInfo)) { //判断不为空 if (!empty($carInfo[$key])) { //根据key获取对应的值并填入图片对应的位置 $image->text($carInfo[$key], $fontpath, self::FONT_SIZE, self::COLOR, array($x, $y)); continue; } } //状态 if (!empty($contactInfo)) { $damageLevel = ""; if (!empty($contactInfo[$key])) { //根据level等级判断 switch ($contactInfo[$key]) { case 0: $damageLevel = "傷なし"; break; case 1: $damageLevel = "傷少々"; break; case 2: $damageLevel = "傷多い"; break; } $image->text($damageLevel, $fontpath, self::FONT_SIZE, self::COLOR, array($x, $y)); } } } //OBDData $obdX = self::OBD_X; $obdY = self::OBD_Y; $pdfString = new PdfString(); //判断不为空 if (!empty($datVcObdInfo)) { //循环处理obd数据 foreach ($datVcObdInfo as $key => $item) { $errorNo = $item["error_no"]; $price = null; foreach($obdUnitPrices as $price) { if ($price['error_no'] == $errorNo) { $price = $price['price']; } } $displayError = $errorNo; if ($price != null) { $displayError = $displayError."(¥".$pdfString->getDividedNumber($price).")"; } //判断一列是否超过5个 if ($key % 5 === 0) { //新开一列显示 //增加x偏移量 $obdX += self::OBD_X_OFFSET; //增加y偏移量 $obdY = self::OBD_Y + self::OBD_Y_OFFSET; } else { //没有超过5个在一列显示 $obdY += self::OBD_Y_OFFSET; } //在图片对应位置写入obdcode $image->text($displayError, $fontpath, self::FONT_SIZE, self::COLOR, array($obdX, $obdY)); } } else { //没有obd故障显示对应提示语 $image->text("エラー無し", $fontpath, self::FONT_SIZE, self::COLOR, array(($obdX + self::OBD_X_OFFSET), $obdY)); } //contactData if (!empty($contactInfo)) { $ctX = self::CT_X; $cty = self::CT_Y; //判断不为空 if (!empty($contactInfo['contact_comment'])) { //行数记录 $count = 0; //按换行符分割联络情报 $commentStrList = explode("\n", $contactInfo['contact_comment']); //循环处理每一行联络情报 foreach ($commentStrList as $value) { //根据每行联络情报的长度,算出需要换行几次 $num = intdiv(mb_strlen($value), self::TEXT_SPLIT_LENGTH); for ($a = 0; $a <= $num; $a++) { $count++; //按固定长度截取,进行换行操作 $contactComment = mb_substr($value, $a * self::TEXT_SPLIT_LENGTH, self::TEXT_SPLIT_LENGTH); //判断是否已经是7行 if ($count == 7) { //超过七行直接显示省略号 $cty += 20;//为了显示好看一点y增加一点偏移量 $image->text('…', $fontpath, self::FONT_SIZE, self::COLOR, array($ctX, $cty)); //结束,跳出最外层循环 break 2; } else { //7行之内正常显示 $image->text($contactComment, $fontpath, self::FONT_SIZE, self::COLOR, array($ctX, $cty)); //下一行的显示位置,增加y的偏移量 $cty += self::CT_Y_OFFSET; } } } } } //設定ファイル内の画像のアップロードアドレスを取得します。 $uploadFolder = DI()->config->get('app.imageUploadDir'); //目录/订单号_inspect.png $uploadImagePath = $uploadFolder . $orderId . "_inspect.jpg"; DI()->logger->info("doSaveInspect", "uploadImagePath:" . $uploadImagePath); //将图片保存到指定位置 $image->save($uploadImagePath); return array("msg" => "正常に保存"); } /** * @brief 支払い証明書の PDF 画像を生成する * * @param paymentProofData 支払い証明データ * * @return 更新結果、フォーマットはJSON * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - data: データ配列 * - msg 正常に保存 * - msg: プロンプトメッセージ */ public function doSavePaymentProof() { $paymentProofData = $this->paymentProofData; //订单id $orderId = $paymentProofData['orderId']; //解析点位 $jsonFilePath = realpath(self::PAYMENT_PROOF_POSITION_JSON); $jsonData = file_get_contents($jsonFilePath); // 使用 json_decode 将 JSON 数据解码为 PHP 数组 $positionData = json_decode($jsonData, true); // 检查是否成功解码 if ($positionData === null && json_last_error() !== JSON_ERROR_NONE) { // 解码失败,处理错误 echo 'Error decoding JSON: ' . json_last_error_msg(); } $customerImage = new \PhalApi\Image\Lite(); $storeImage = new \PhalApi\Image\Lite(); //打开图片 $customerImage->open(self::PAYMENT_PROOF_CUSTOMER); $storeImage->open(self::PAYMENT_PROOF_STORE); //获取字体文件的绝对路径 $fontpath = realpath(self::FONT); //给图片自定义文字 foreach ($positionData as $value) { $key = $value['key']; $x = $value['x']; $y = $value['y']; if ($paymentProofData[$key]) { $storeImage->text($paymentProofData[$key], $fontpath, self::PAYMENT_PROOF_FONT_SIZE, self::COLOR, array($x, $y)); $customerImage->text($paymentProofData[$key], $fontpath, self::PAYMENT_PROOF_FONT_SIZE, self::COLOR, array($x, $y)); } } //将图片保存到指定位置 // $storeImage->save("./payment_proof_sr_20231228.jpg"); // $customerImage->save("./payment_proof_cs_20231228.jpg"); //設定ファイル内の画像のアップロードアドレスを取得します。 $uploadFolder = DI()->config->get('app.imageUploadDir'); //目录/订单号_payment_proof_.jpg $storeImagePath = $uploadFolder . $orderId . "_payment_proof_store.jpg"; $customerImagePath = $uploadFolder . $orderId . "_payment_proof_customer.jpg"; DI()->logger->info("doSavePaymentProof", "storeImagePath:" . $storeImagePath); DI()->logger->info("doSavePaymentProof", "customerImagePath:" . $customerImagePath); //将图片保存到指定位置 $storeImage->save($storeImagePath); $customerImage->save($customerImagePath); return array("msg" => "正常に保存"); } /** * @brief オーダーコピー * * @param orderId コピー元コーダーID * * @return 更新結果、フォーマットはJSON * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - data: データ配列 * - msg 正常に保存 * - msg: プロンプトメッセージ */ public function doCopyOrder() { $orderId = $this->orderId; $orderDomain = new DatSyakenOrderListDomain(); $decoder = new JWTDecoder(); $jwt = $decoder->decode(); DI()->logger->info("doCopyOrder", "jwt:" . json_encode($jwt)); $shopId = null; if ($jwt != null) { $jwtData = $jwt["data"]; $shopId = $jwtData->ssid; } if ($orderDomain->copyOrder($orderId, $shopId)) { return array("msg" => "正常に保存"); } else { throw new BadRequestException("オーダーコピー失敗"); } } /** * @brief オーダーをキャンセルする * * @param orderId オーダーID * * @return 更新結果、フォーマットはJSON * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - data: データ配列 * - msg 正常に保存 * - msg: プロンプトメッセージ */ public function cancelOrder() { $orderId = $this->orderId; $orderDomain = new DatSyakenOrderListDomain(); $orderInfo = $orderDomain->get($orderId); //見積情報 $datRepairEstimateDetail = new DatRepairEstimateDetailDomain(); if($orderInfo['repair_estimate_id'] != null){ $repairEstimateDetailList = $datRepairEstimateDetail->listByRepairEstimateId($orderInfo['repair_estimate_id']); $where = array(); foreach ($repairEstimateDetailList as $repairEstimate) { if ($repairEstimate['judge_type'] == 1) { $where[] = $repairEstimate['id']; } } if(!empty($where)){ $datRepairEstimateDetail->updateRepairEstimateDetail('id in ('.implode(',', $where).')',array('judge_type' => 2)); } } //関連する車両予約情報を削除 $datCarsStorageReservationDomain = new DatCarsStorageReservationDomain(); $count = $datCarsStorageReservationDomain->deleteCarStorageReservationByOrderId($orderId); DI()->logger->info("cancelOrder", "deleteCarStorageReservationCount:" . $count); if ($orderDomain->cancelOrder($orderId)) { //重新计算入出金 $orderDomain->updateDepositWithdrawalTotal($orderId); return array("msg" => "キャンセルしました"); } else { throw new BadRequestException("オーダーキャンセル失敗"); } } /** * @brief 値引きリスト保存 * * @param orderId オーダーID * @param discounts 値引きリスト * * @return 更新結果、フォーマットはJSON * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - data: データ配列 * - msg 正常に保存 * - msg: プロンプトメッセージ */ public function doSaveDicounts() { $orderId = $this->orderId; $discounts = $this->discounts; $orderDomain = new DatSyakenOrderListDomain(); $order = $orderDomain->get($orderId); $discountDomain = new DatDiscountRecordDomain(); if ($order['discount_record_id'] == null || $order['discount_record_id'] == 0) { $recordId = $discountDomain->saveDiscounts($discounts, null); } else { $recordId = $discountDomain->saveDiscounts($discounts, $order['discount_record_id']); } $orderDomain->updateOrderInfoByOrderId($orderId, array( 'discount_record_id' => $recordId )); //重新计算入出金 $orderDomain->updateDepositWithdrawalTotal($orderId); return array("msg" => "正常に保存"); } /** * @brief 手入力値引き保存 * * @param orderId オーダーID * @param discount 値引き * * @return 更新結果、フォーマットはJSON * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - data: データ配列 * - msg 正常に保存 * - msg: プロンプトメッセージ */ public function doSaveExtraDiscount() { $orderId = $this->orderId; $discount = $this->discount; $orderDomain = new DatSyakenOrderListDomain(); $orderDomain->updateOrderInfoByOrderId($orderId, array( 'extra_discount' => $discount )); //重新计算入出金 $orderDomain->updateDepositWithdrawalTotal($orderId); return array("msg" => "正常に保存"); } public function getBudgetData(){ //订单id $orderId = $this->orderId; $budgetData = array(); $orderDomain = new DatSyakenOrderListDomain(); $orderInfo = $orderDomain->get($orderId); $carId = $orderInfo['Car_ID']; $carDomain = new DatCarsDomain(); $carInfo = $carDomain->get($carId); $mtssDomain = new MtssDomain(); $mtssInfo = $mtssDomain->get($orderInfo['Shop_ID']); $customerDomain = new DatCustomerDomain(); $customerInfo = $customerDomain->get($orderInfo['Customer_ID']); //诸费用信息 $datMiscellaneousExpensesDetail = new DatMiscellaneousExpensesDetailDomain(); $miscellaneousExpensesDetailList = $datMiscellaneousExpensesDetail->listByMiscellaneousExpensesId($orderInfo['miscellaneous_expenses_id']); $mtMiscellaneousExpensesItem = new MtMiscellaneousExpensesItemDomain(); $miscellaneousExpensesItemList = $mtMiscellaneousExpensesItem->getItemList(); $otherPrices = 0; $lawTotal = 0; $noTaxTotal = 0; $budgetData['cost1'] = 0; $budgetData['cost2'] = 0; $budgetData['cost3'] = 0; $budgetData['cost4'] = 0; $needOss = false; $weightPrice = 0; $carTaxPrice = 0; $insurancePrice = 0; $paperPrice = 0; if( $orderInfo['service'] == 2){ $needOss = true; } DI()->logger->info("doSaveBudget", "Start handler miscellaneousExpensesDetailList"); foreach ($miscellaneousExpensesDetailList as $miscellaneousExpensesDetail) { if ($miscellaneousExpensesDetail['item'] == '重量税') { $weightPrice += $miscellaneousExpensesDetail['amount'] != null ? $miscellaneousExpensesDetail['amount'] : 0; } elseif ($miscellaneousExpensesDetail['item'] == '種別割(自動車税)' || $miscellaneousExpensesDetail['item'] == '環境性能割(自動車税)') { $carTaxPrice += $miscellaneousExpensesDetail['amount'] != null ? $miscellaneousExpensesDetail['amount'] : 0; } elseif ($miscellaneousExpensesDetail['item'] == '自賠責') { $insurancePrice += $miscellaneousExpensesDetail['amount'] != null ? $miscellaneousExpensesDetail['amount'] : 0; } elseif ($miscellaneousExpensesDetail['item'] == '印紙') { $paperPrice += $miscellaneousExpensesDetail['amount'] != null ? $miscellaneousExpensesDetail['amount'] : 0; // if ($miscellaneousExpensesDetail['months'] == 1) { // $needOss = true; // } } elseif ($miscellaneousExpensesDetail['item'] == '普通自動車ナンバープレート') { $paperPrice += $miscellaneousExpensesDetail['amount'] ? $miscellaneousExpensesDetail['amount'] : 0; } else { //$otherPrices += $miscellaneousExpensesDetail['amount']; //他の部分は計算しない continue; } $lawTotal += $miscellaneousExpensesDetail['amount']; $noTaxTotal += $miscellaneousExpensesDetail['amount']; } DI()->logger->info("doSaveBudget", "End handler miscellaneousExpensesDetailList"); //見積情報 $datRepairEstimateDetail = new DatRepairEstimateDetailDomain(); $repairEstimateDetailList = $datRepairEstimateDetail->listByRepairEstimateId($orderInfo['repair_estimate_id']); $datDiscountRecordDetailDomain = new DatDiscountRecordDetailDomain(); $discounts = $datDiscountRecordDetailDomain->getList($orderInfo['discount_record_id']); $mtDiscountDomain = new MtDiscountDomain(); $discountInfos = $mtDiscountDomain->list(); $datDepositWithdrawalRecordDomain = new DatDepositWithdrawalRecordDomain(); $depositWithdrawalRecords = $datDepositWithdrawalRecordDomain->getDepositWithdrawalRecords($orderId); $servicePrice = 0; $checkPrice = 0; $maintenancePrice = 0; $repairPrice = 0; $partsPrice = 0; $securityPrice = 0; $mtRepairUnitPrice = new MtRepairUnitPriceDomain(); $masterRepairUnits = $mtRepairUnitPrice->searchByItems($repairEstimateDetailList); DI()->logger->info("doSaveBudget", "Start handler repairEstimateDetailList"); foreach ($repairEstimateDetailList as $repairEstimate) { if ($repairEstimate['is_hidden'] == 1) { continue; } if ($repairEstimate['judge_type'] == 2 && $repairEstimate['repair_item'] !== 'メモ') { // $notDone[] = $repairEstimate; } else { if ($repairEstimate['classification'] == '点検') { $checkPrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '測定') { $servicePrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '交換') { $maintenancePrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '補修') { $repairPrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '補充') { $maintenancePrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '清掃') { $maintenancePrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '鈑金') { $repairPrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '塗装') { $repairPrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '給油') { $otherPrices += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '部品') { $partsPrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '外注') { $otherPrices += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == 'その他') { $otherPrices += $repairEstimate['request_total_price']; } elseif ($repairEstimate['repair_item'] !== 'メモ' && $repairEstimate['repair_item'] !== 'お客様要望') { $otherPrices += $repairEstimate['request_total_price']; } if ($repairEstimate['repair_item'] !== 'メモ') { $noTaxTotal += $repairEstimate['request_price']; } } } DI()->logger->info("doSaveBudget", "End handler repairEstimateDetailList"); $discountPrice = 0; DI()->logger->info("doSaveBudget", "Start handler discounts"); foreach ($discounts as $discount) { $discountPrice += $discount['price']; } $discountPrice += $orderInfo['extra_discount']; DI()->logger->info("doSaveBudget", "End handler discounts"); $payed = 0; DI()->logger->info("doSaveBudget", "Start handler depositWithdrawalRecords"); foreach ($depositWithdrawalRecords as $depositWithdrawalRecord) { if ($depositWithdrawalRecord["type"] == 1 || $depositWithdrawalRecord["type"] == 3) { $payed += $depositWithdrawalRecord["amount"]; } elseif ($depositWithdrawalRecord["type"] == 2) { $payed -= $depositWithdrawalRecord["amount"]; } } DI()->logger->info("doSaveBudget", "End handler depositWithdrawalRecords"); $budgetData['weightPrice'] = $weightPrice; $budgetData['carTaxPrice'] = $carTaxPrice; $budgetData['insurancePrice'] = $insurancePrice; $budgetData['paperPrice'] = $paperPrice; $budgetData['servicePrice'] = $servicePrice; $budgetData['checkPrice'] = $checkPrice; $budgetData['maintenancePrice'] = $maintenancePrice; $budgetData['partsPrice'] = $partsPrice; $budgetData['repairPrice'] = $repairPrice; $budgetData['securityPrice'] = $securityPrice; $budgetData['otherPrices'] = $otherPrices; $budgetData['discountPrice'] = $discountPrice; $budgetData['payed'] = $payed; $budgetData['priceTotal'] = $lawTotal + $servicePrice + $checkPrice + $maintenancePrice + $partsPrice + $repairPrice + $otherPrices; $priceTotal = $lawTotal + $servicePrice + $checkPrice + $maintenancePrice + $partsPrice + $repairPrice + $otherPrices - $discountPrice; $toPayTotal = $payed - $priceTotal; $taxTotal = $lawTotal + $servicePrice + $checkPrice + $maintenancePrice + $partsPrice + $repairPrice + $otherPrices - $noTaxTotal; $budgetData['total'] = $priceTotal; $budgetData['toPayTotal'] = $toPayTotal; $budgetData['tax'] = $taxTotal; DI()->logger->info("doSaveBudget", "final data: " . json_encode($budgetData)); return $budgetData; } public function getYearJpn($year){ $yearStr = ""; if ($year > 2018) { $offset = $year - 2018; $yearStr = "令和".$offset."年"; } elseif ($year > 1988) { $offset = $year - 1988; $yearStr = "平成".$offset."年"; } elseif ($year > 1925) { $offset = $year - 1925; $yearStr = "昭和".$offset."年"; } elseif ($year > 1911) { $offset = $year - 1911; $yearStr = "大正".$offset."年"; } elseif ($year > 1867) { $offset = $year - 1867; $yearStr = "明治".$offset."年"; } return $yearStr; } private function fetchBudgetData() { $budgetData = $this->budgetData; // pdfType:1見積書 2請求書 3作業指示書 $pdfType = $this->pdfType; if ($pdfType == null) { $pdfType = 1; } //订单id $orderId = $budgetData['orderId']; $orderDomain = new DatSyakenOrderListDomain(); $orderInfo = $orderDomain->get($orderId); $carId = $orderInfo['Car_ID']; $carDomain = new DatCarsDomain(); $carInfo = $carDomain->get($carId); $mtssDomain = new MtssDomain(); $mtssInfo = $mtssDomain->get($orderInfo['Shop_ID']); $customerDomain = new DatCustomerDomain(); $customerInfo = $customerDomain->get($orderInfo['Customer_ID']); $customerBasicFee = $customerDomain->getCustomerBasicFee($orderInfo['basic_fee_id']); $urikake = $customerBasicFee['urikake'] ?? 0; $budgetData['urikake'] = $urikake; $orderDetailDomain = new OrderDetailDomain(); $tax = $orderDetailDomain->getTax()["tax"]; $pdfString = new PdfString(); //诸费用信息 $datMiscellaneousExpensesDetail = new DatMiscellaneousExpensesDetailDomain(); $miscellaneousExpensesDetailList = $datMiscellaneousExpensesDetail->listByMiscellaneousExpensesId($orderInfo['miscellaneous_expenses_id']); $mtMiscellaneousExpensesItem = new MtMiscellaneousExpensesItemDomain(); $miscellaneousExpensesItemList = $mtMiscellaneousExpensesItem->getItemList(); // $details = $pdfString->getDetailLine("項目", "数量", "単価", "税込計"); $details = $pdfString->getDetailLineGaityuu("項目", "数量", "合計"); if($urikake == 1 && $pdfType == 1){ $details = $pdfString->getDetailLine("項目", "数量", "単価", "合計"); } if($pdfType == 3){ $details2 = $pdfString->getDetail3Line("項目", "コード", "数量"); }else{ $details2 = $pdfString->getDetail2Line("項目", "コード", "数量", "単価", "税込計"); } $detail2Lines = 1; $otherPrices = 0; $lawTotal = 0; $noTaxTotal = 0; $budgetData['cost1'] = 0; $budgetData['cost2'] = 0; $budgetData['cost3'] = 0; $budgetData['cost4'] = 0; $needOss = false; $weightPrice = 0; $carTaxPrice = 0; $insurancePrice = 0; $paperPrice = 0; if( $orderInfo['service'] == 2){ $needOss = true; } DI()->logger->info("fetchBudgetData", "Start handler miscellaneousExpensesDetailList"); foreach ($miscellaneousExpensesDetailList as $miscellaneousExpensesDetail) { if ($miscellaneousExpensesDetail['item'] == '重量税') { $weightPrice += $miscellaneousExpensesDetail['amount'] != null ? $miscellaneousExpensesDetail['amount'] : 0; } elseif ($miscellaneousExpensesDetail['item'] == '種別割(自動車税)' || $miscellaneousExpensesDetail['item'] == '環境性能割(自動車税)') { $carTaxPrice += $miscellaneousExpensesDetail['amount'] != null ? $miscellaneousExpensesDetail['amount'] : 0; } elseif ($miscellaneousExpensesDetail['item'] == '自賠責') { $insurancePrice += $miscellaneousExpensesDetail['amount'] != null ? $miscellaneousExpensesDetail['amount'] : 0; } elseif ($miscellaneousExpensesDetail['item'] == '印紙') { $paperPrice += $miscellaneousExpensesDetail['amount'] != null ? $miscellaneousExpensesDetail['amount'] : 0; // if ($miscellaneousExpensesDetail['months'] == 1) { // $needOss = true; // } } elseif ($miscellaneousExpensesDetail['item'] == '普通自動車ナンバープレート') { $paperPrice += $miscellaneousExpensesDetail['amount'] ? $miscellaneousExpensesDetail['amount'] : 0; } else { //$otherPrices += $miscellaneousExpensesDetail['amount']; //他の部分は計算しない continue; } $lawTotal += $miscellaneousExpensesDetail['amount']; $noTaxTotal += $miscellaneousExpensesDetail['amount']; if ($miscellaneousExpensesDetail['amount'] != null && $miscellaneousExpensesDetail['amount'] > 0) { $code = null; foreach ($miscellaneousExpensesItemList as $item) { if ($item['item'] == $miscellaneousExpensesDetail['item']) { $code = $item['code']; break; } } if($pdfType == 3){ $details2 = $details2 . "\n" . $pdfString->getDetail3Line( $miscellaneousExpensesDetail['item'], $code, null ); }else{ if($urikake == 1 && $pdfType == 1){ $details2 = $details2 . "\n" .$pdfString->getDetail2Line( $miscellaneousExpensesDetail['item'], $code, null, null, $pdfString->getDividedNumber($miscellaneousExpensesDetail['amount']) ); }else{ $details2 = $details2 . "\n" .$pdfString->getDetail2Line( $miscellaneousExpensesDetail['item'], $code, null, null, $pdfString->getDividedNumber($miscellaneousExpensesDetail['amount']) ); } } $detail2Lines += 1; } } DI()->logger->info("fetchBudgetData", "End handler miscellaneousExpensesDetailList"); //見積情報 $datRepairEstimateDetail = new DatRepairEstimateDetailDomain(); $repairEstimateDetailList = $datRepairEstimateDetail->listByRepairEstimateId($orderInfo['repair_estimate_id']); $datDiscountRecordDetailDomain = new DatDiscountRecordDetailDomain(); $discounts = $datDiscountRecordDetailDomain->getList($orderInfo['discount_record_id']); $mtDiscountDomain = new MtDiscountDomain(); $discountInfos = $mtDiscountDomain->list(); $datDepositWithdrawalRecordDomain = new DatDepositWithdrawalRecordDomain(); $depositWithdrawalRecords = $datDepositWithdrawalRecordDomain->getDepositWithdrawalRecords($orderId); $servicePrice = 0; $checkPrice = 0; $maintenancePrice = 0; $repairPrice = 0; $partsPrice = 0; $securityPrice = 0; $mtRepairUnitPrice = new MtRepairUnitPriceDomain(); $masterRepairUnits = $mtRepairUnitPrice->searchByItems($repairEstimateDetailList); DI()->logger->info("fetchBudgetData", "Start handler repairEstimateDetailList"); foreach ($repairEstimateDetailList as $repairEstimate) { if ($repairEstimate['is_hidden'] == 1) { continue; } if ($repairEstimate['judge_type'] == 2 && $repairEstimate['repair_item'] !== 'メモ') { } else { if ($repairEstimate['classification'] == '点検') { $checkPrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '測定') { $servicePrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '交換') { $maintenancePrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '補修') { // $repairPrice += $repairEstimate['request_total_price']; $maintenancePrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '補充') { $maintenancePrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '清掃') { $maintenancePrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '調整') { $maintenancePrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '修正') { $maintenancePrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '鈑金') { $repairPrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '塗装') { $repairPrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '給油') { $otherPrices += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '部品') { $partsPrice += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == '外注') { $otherPrices += $repairEstimate['request_total_price']; } elseif ($repairEstimate['classification'] == 'その他') { $otherPrices += $repairEstimate['request_total_price']; } elseif ($repairEstimate['repair_item'] !== 'メモ' && $repairEstimate['repair_item'] !== 'お客様要望') { $otherPrices += $repairEstimate['request_total_price']; } if ($repairEstimate['repair_item'] !== 'メモ') { $noTaxTotal += $repairEstimate['request_price']; } } if ($repairEstimate['repair_item'] == 'メモ') { $details = $details . "\n" . $pdfString->getDetailLine( $repairEstimate['category_detail'],null,null,null ); } else { if($urikake == 1 ){ if($pdfType == 1){ $details = $details . "\n" . $pdfString->getDetailLine( trim($repairEstimate['category_detail']), $repairEstimate['pieces'], null, $pdfString->getDividedNumber($repairEstimate['request_price']) ); }elseif($pdfType == 2){ $details = $details . "\n" . $pdfString->getDetailLine( trim($repairEstimate['category_detail']), $repairEstimate['pieces'], $pdfString->getDividedNumber($repairEstimate['request_unit_price']), $pdfString->getDividedNumber($repairEstimate['request_price']) ); } }else{ $details = $details . "\n" . $pdfString->getDetailLine( trim($repairEstimate['category_detail']), $repairEstimate['pieces'], null, $pdfString->getDividedNumber($repairEstimate['request_total_price']) ); } // if($repairEstimate['request_unit_price'] == 0){ // $details = $details . "\n" // . $pdfString->getDetailLine( // trim($repairEstimate['category_detail']), // $repairEstimate['pieces'], // '-', // $repairEstimate['request_price'] // ); // }else{ // $details = $details . "\n" // . $pdfString->getDetailLine( // trim($repairEstimate['category_detail']), // $repairEstimate['pieces'], // $pdfString->getDividedNumber($repairEstimate['request_unit_price']), // $pdfString->getDividedNumber($repairEstimate['request_total_price']) // ); // } if ($repairEstimate['judge_type'] == 1) { $code = null; foreach ($masterRepairUnits as $master) { if ($master['repair_item'] == $repairEstimate['repair_item'] && $master['classification'] == $repairEstimate['classification'] && $master['category'] == $repairEstimate['category'] && $master['category_detail'] == $repairEstimate['category_detail']) { $code = $master['repair_item_code']."-".$master['classification_code']."-".$master['category_code']."-".$master['category_detail_code']; break; } } if($pdfType == 3){ $details2 = $details2 . "\n" . $pdfString->getDetail3Line( ($repairEstimate['remark'] == 'SS作業'?"[SS作業]":'').trim($repairEstimate['category_detail']), $code, $repairEstimate['pieces'] ); }else{ if($urikake == 1 ){ if($pdfType == 1){ $details2 = $details2 . "\n" . $pdfString->getDetail2LineGaityuu( ($repairEstimate['remark'] == 'SS作業'?"[SS作業]":'').trim($repairEstimate['category_detail']), $code, $repairEstimate['pieces'], $pdfString->getDividedNumber($repairEstimate['request_price']) ); }elseif($pdfType == 2){ $details2 = $details2 . "\n" .$pdfString->getDetail2Line( ($repairEstimate['remark'] == 'SS作業'?"[SS作業]":'').trim($repairEstimate['category_detail']), $code, $repairEstimate['pieces'], $pdfString->getDividedNumber($repairEstimate['pieces'] == 0 ? 0:$repairEstimate['request_total_price']/$repairEstimate['pieces']), $pdfString->getDividedNumber($repairEstimate['request_price']) ); } }else{ $details = $details . "\n" . $pdfString->getDetailLine( trim($repairEstimate['category_detail']), $repairEstimate['pieces'], null, $pdfString->getDividedNumber($repairEstimate['request_total_price']) ); $details2 = $details2 . "\n" . $pdfString->getDetail2LineGaityuu( ($repairEstimate['remark'] == 'SS作業'?"[SS作業]":'').trim($repairEstimate['category_detail']), $code, $repairEstimate['pieces'], $pdfString->getDividedNumber($repairEstimate['request_total_price']) ); } // if($repairEstimate['request_unit_price'] == 0){ // $details2 = $details2 . "\n" // . $pdfString->getDetail2Line( // ($repairEstimate['remark'] == 'SS作業'?"[SS作業]":'').trim($repairEstimate['category_detail']), // $code, // $repairEstimate['pieces'], // '-', // $repairEstimate['request_price'] // ); // }else{ // $details2 = $details2 . "\n" // . $pdfString->getDetail2Line( // ($repairEstimate['remark'] == 'SS作業'?"[SS作業]":'').trim($repairEstimate['category_detail']), // $code, // $repairEstimate['pieces'], // $pdfString->getDividedNumber($repairEstimate['pieces'] == 0 ? 0:$repairEstimate['request_total_price']/$repairEstimate['pieces']), // $pdfString->getDividedNumber($repairEstimate['request_total_price']) // ); // } } $detail2Lines += 1; } } } DI()->logger->info("fetchBudgetData", "End handler repairEstimateDetailList"); $discountPrice = 0; $discountIcons = []; DI()->logger->info("fetchBudgetData", "Start handler discounts"); foreach ($discounts as $discount) { $discountPrice += $discount['price']; foreach ($discountInfos as $discountInfo) { if ($discountInfo['id'] == $discount['discount_id']) { $discountIcons[] = "./icons/" . $discountInfo['icon_name']; break; } } } $discountPrice += $orderInfo['extra_discount']; DI()->logger->info("fetchBudgetData", "discountIcons: " . json_encode($discountIcons)); if($pdfType == 3){ $details2 = $details2 . "\n" . $pdfString->getDetail3Line( "値引き", null, null ); }else{ $details2 = $details2 . "\n" . $pdfString->getDetail2Line( "値引き", null, null, null, $pdfString->getDividedNumber($discountPrice) ); } $detail2Lines += 1; DI()->logger->info("fetchBudgetData", "End handler discounts"); $payed = 0; DI()->logger->info("fetchBudgetData", "Start handler depositWithdrawalRecords"); foreach ($depositWithdrawalRecords as $depositWithdrawalRecord) { if ($depositWithdrawalRecord["type"] == 1 || $depositWithdrawalRecord["type"] == 3) { $payed += $depositWithdrawalRecord["amount"]; } elseif ($depositWithdrawalRecord["type"] == 2) { $payed -= $depositWithdrawalRecord["amount"]; } } DI()->logger->info("fetchBudgetData", "End handler depositWithdrawalRecords"); // $details = preg_replace('/ /', ' ', $details); // $details = preg_replace('/ /', ' ', $details); DI()->logger->info("fetchBudgetData", "All Details: "); foreach(explode("\n", $details) as $detailLine) { DI()->logger->info("fetchBudgetData", "\"".$detailLine."\""); } $detailLines = substr_count($details, "\n") + 1; $emptyLines = 39 - ($detailLines % 39); DI()->logger->info("fetchBudgetData", "empty Lines: $emptyLines"); $skipLine = 1; if ($emptyLines < 2) { if ($emptyLines < 1) { $emptyLines += 39; } else { $skipLine = 0; } } $toEmpty = $emptyLines - (2-$skipLine); for ($i = 0;$i<$toEmpty;$i++) { $details .= "\n"; } $details .= "\n"; $details .= $carInfo['Number'].'|'.$carInfo['VIN'].'|'.$carInfo['Car_Name'].'|'.$mtssInfo['ss_name']; $budgetData['orderId'] = $orderId; $budgetData['pdfType'] = $pdfType; $budgetData['carName'] = $carInfo['Car_Name']; $budgetData['carNumber'] = $carInfo['Number']; $monthStr = "xx"; if ($carInfo['syodo_date'] != null && strlen($carInfo['syodo_date'] >= 10)) { $monthStr = substr($carInfo['syodo_date'], 5, 2); } $budgetData['carYear'] = $carInfo['Year'].'年'.$monthStr.'月'.'('.$pdfString->getDividedNumber($carInfo['Millage']).'Km)'; $budgetData['number'] = $carInfo['Number']; $budgetData['quotationDate'] = date('Y-m-d'); $budgetData['orginName'] = "株式会社SHIMARS"; if($mtssInfo['display_name'] != null){ $budgetData['ss'] = $mtssInfo['display_name']; }else{ $budgetData['ss'] = $mtssInfo['ss_name']; } $budgetData['ssAddress'] = $mtssInfo['address']." 担当:"; $budgetData['ssTelnumber'] = "Tel: ".$mtssInfo['telno']; $budgetData['needOss'] = $needOss; $budgetData['customerName'] = $customerInfo['name'] . $customerInfo['customer_name']; $budgetData['customerAddress'] = $customerInfo['customer_address'] . $customerInfo['Customer_address_2']; $budgetData['customerTelnumber'] = $customerInfo['customer_telnumber']; if(!isset($budgetData['customerTitle'])){ $budgetData['customerTitle'] = '様'; } $budgetData['detail'] = $details; $budgetData['detail2'] = $details2; $budgetData['cost1'] = $pdfString->getDividedNumber($weightPrice); $budgetData['cost2'] = $pdfString->getDividedNumber($carTaxPrice); $budgetData['cost3'] = $pdfString->getDividedNumber($insurancePrice); $budgetData['cost4'] = $pdfString->getDividedNumber($paperPrice); $budgetData['cost5'] = $pdfString->getDividedNumber($servicePrice); $budgetData['cost6'] = $pdfString->getDividedNumber($checkPrice); $budgetData['cost7'] = $pdfString->getDividedNumber($maintenancePrice); $budgetData['cost8'] = $pdfString->getDividedNumber($partsPrice); $budgetData['cost9'] = $pdfString->getDividedNumber($repairPrice); $budgetData['cost10'] = $pdfString->getDividedNumber($securityPrice); $budgetData['cost11'] = $pdfString->getDividedNumber($otherPrices); $budgetData['cost12'] = $pdfString->getDividedNumber(-$discountPrice); $budgetData['cost13'] = $pdfString->getDividedNumber($payed); $budgetData['lawAll'] = "¥".($pdfString->getDividedNumber($weightPrice+$carTaxPrice+$insurancePrice+$paperPrice)); $priceTotal = $lawTotal + $servicePrice + $checkPrice + $maintenancePrice + $partsPrice + $repairPrice + $otherPrices - $discountPrice; $toPayTotal = $priceTotal - $payed; $taxTotal = $lawTotal + $servicePrice + $checkPrice + $maintenancePrice + $partsPrice + $repairPrice + $otherPrices - $noTaxTotal; // $taxTotal = ($noTaxTotal - $lawTotal - $discountPrice) * $tax; $budgetData['total'] = '¥'.$pdfString->getDividedNumber($priceTotal)."(¥".$pdfString->getDividedNumber($toPayTotal).")"; $budgetData['tax'] = '¥'.$pdfString->getDividedNumber($taxTotal); $budgetData['orderTotal'] = '¥'.$pdfString->getDividedNumber($priceTotal); //見積書と請求書の説明文 $mtInvoiceDescDomain = new MtInvoiceDescDomain(); $invoiceDesc = $mtInvoiceDescDomain->getInvoiceDescByType($pdfType); if($invoiceDesc){ $budgetData['contactComment'] =$invoiceDesc['description']; } // $budgetData['contactComment'] = "このお見積もりはあくまでも概算で算出されたものとなります。当社所有の国土交通省認可、指定工場において分解点検等を行うことで、以下のことが発生する場合があります。予めご了承をお願いいたします。1.追加で部品や油脂類の量が必要となる場合があります。2.この内容の整備の必要性がなくなる場合があります。3.故障が新たに発見されたり、ここに記載されている内容であっても、改めて故障ではないと判断される可能性があります。4.部品や作業の価格が変更となる場合がございます。"; $budgetData['discountIcons'] = $discountIcons; $budgetData['carInfo'] = $carInfo; $budgetData['mtssInfo'] = $mtssInfo; $budgetData['orderInfo'] = $orderInfo; $budgetData['customerInfo'] = $customerInfo; $budgetData['ssHint'] = '車台番号:'.$carInfo['VIN'].'|'.$mtssInfo['ss_name']; DI()->logger->info("fetchBudgetData", "final data: " . json_encode($budgetData)); return $budgetData; } private function getBudgetPage1($budgetData) { //解析点位 $jsonFilePath = realpath(self::BUDGET_POSITION_JSON); $jsonData = file_get_contents($jsonFilePath); // 使用 json_decode 将 JSON 数据解码为 PHP 数组 $positionData = json_decode($jsonData, true); // 检查是否成功解码 if ($positionData === null && json_last_error() !== JSON_ERROR_NONE) { // 解码失败,处理错误 echo 'Error decoding JSON: ' . json_last_error_msg(); } $pdfType = $budgetData['pdfType']; $orderId = $budgetData['orderId']; $urikake = $budgetData['urikake'] ?? 0; $Image = new \PhalApi\Image\Lite(); //打开图片 if ($pdfType == 1) { if($urikake == 1){ $Image->open(self::BUDGET_GAITYUU); }else{ $Image->open(self::BUDGET_IPPAN); } // $Image->open(self::BUDGET); } else { if($urikake == 1){ $Image->open(self::BUDGET2_GAITYUU); }else{ $Image->open(self::BUDGET2_IPPAN); } // $Image->open(self::BUDGET2); } $pdfString = new PdfString(); //設定ファイル内の画像のアップロードアドレスを取得します。 $uploadFolder = DI()->config->get('app.imageUploadDir'); //目录/订单号_payment_proof_.jpg $ImagePath = $uploadFolder . $orderId . "_budget.jpg"; $imageList = [$ImagePath]; //获取字体文件的绝对路径 $fontpath = realpath(self::FONT); //给图片自定义文字 foreach ($positionData as $value) { $key = $value['key']; $x = $value['x']; $y = $value['y']; if ($key == "detail") { continue; } elseif ($key == "ssHint") { if ($pdfType == 1) { continue; } } elseif ($key == "discountIcons") { if ($budgetData[$key] !== null) { foreach ($budgetData[$key] as $icon) { $iconImage = new \PhalApi\Image\Lite(); $widthAdd = $iconImage->open($icon)->width(); $Image->water($icon, array($x, $y), 100); $x += $widthAdd + 10; } } } elseif ($key == "contactComment") { continue; } elseif ($budgetData[$key] !== null) { if(str_starts_with($key, "cost")) { $Image->text($pdfString->getPaddingLeftString($budgetData[$key], 22), $fontpath, self::BUDGET_FONT_SIZE, self::COLOR, array($x, $y)); } elseif ($key == "total") { $Image->text($pdfString->getPaddingLeftString($budgetData[$key], 22), $fontpath, self::BUDGET_FONT_SIZE, self::COLOR, array($x, $y)); } elseif ($key == "customerAddress" ) { //计算文字长度 $addrNum = intdiv(round($pdfString->advanceStrLen($budgetData[$key])/2.0), 17); for ($a = 0; $a <= $addrNum; $a++) { $addrComment = $pdfString->advanceSubstring($budgetData[$key], $a * 17 *2, $a * 17*2+17*2); $y = $y + 30*$a; $Image->text($addrComment, $fontpath, 22, self::COLOR, array($x, $y)); } }elseif ($key == "customerName" ) { //计算文字长度 $nameLength = $pdfString->advanceStrLen($budgetData[$key]); if($nameLength<=24){ $Image->text($budgetData[$key], $fontpath, self::BUDGET_FONT_SIZE, self::COLOR, array($x, $y)); }elseif($nameLength<=30){ $Image->text($budgetData[$key], $fontpath, 22, self::COLOR, array($x, $y)); }else{ //超过2行的部分不显示 for ($a = 0; $a <= 1; $a++) { $addrComment = $pdfString->advanceSubstring($budgetData[$key], $a * 15 *2, $a * 15*2+15*2); $y = $y-20 + 50*$a; $Image->text($addrComment, $fontpath, 22, self::COLOR, array($x, $y)); } } } elseif ($key == "customerTelnumber" || $key == "ssTelnumber" || $key == "ssAddress") { $Image->text($budgetData[$key], $fontpath, 22, self::COLOR, array($x, $y)); }elseif ($key == "carName") { //计算文字长度 $nameLength = $pdfString->advanceStrLen($budgetData[$key].$budgetData["carNumber"]); if($nameLength<=30){ $Image->text($budgetData[$key].$budgetData["carNumber"], $fontpath,self::BUDGET_FONT_SIZE, self::COLOR, array($x, $y)); }else{ $nameLength = $pdfString->advanceStrLen($budgetData[$key]); if($nameLength<=40){ $Image->text($budgetData[$key], $fontpath, 22, self::COLOR, array($x, $y-5)); $Image->text($budgetData["carNumber"], $fontpath, 22, self::COLOR, array($x, $y+25)); }elseif($nameLength<=50){ $Image->text($budgetData[$key], $fontpath, 16, self::COLOR, array($x, $y)); $Image->text($budgetData["carNumber"], $fontpath, 22, self::COLOR, array($x, $y+25)); }else{ //超过2行的部分不显示 for ($a = 0; $a <= 1; $a++) { $addrComment = $pdfString->advanceSubstring($budgetData[$key], $a * 25 *2, $a * 25*2+25*2); $y = $y-8 + 28*$a; $Image->text($addrComment, $fontpath, 16, self::COLOR, array($x, $y)); } $Image->text($budgetData["carNumber"], $fontpath, 16, self::COLOR, array($x, $y+20)); } } }elseif ($key == "carYear") { //计算文字长度 $nameLength = $pdfString->advanceStrLen($budgetData["carName"].$budgetData["carNumber"]); if($nameLength<=30){ $Image->text($budgetData[$key], $fontpath,self::BUDGET_FONT_SIZE, self::COLOR, array($x, $y)); }else{ $nameLength = $pdfString->advanceStrLen($budgetData["carName"]); if($nameLength<=50){ $Image->text($budgetData[$key], $fontpath, 22, self::COLOR, array($x, $y+12)); }else{ $Image->text($budgetData[$key], $fontpath, 16, self::COLOR, array($x, $y+ 15)); } } } else { $Image->text($budgetData[$key], $fontpath, self::BUDGET_FONT_SIZE, self::COLOR, array($x, $y)); } } } DI()->logger->info("getBudgetPage1", "ImagePath:" . $ImagePath); //将图片保存到指定位置 $Image->save($ImagePath, "jpg"); return $imageList; } private function getBudgetPageDetails($budgetData) { $urikake = $budgetData['urikake'] ?? 0; $pdfType = $budgetData['pdfType']; //订单id $orderId = $budgetData['orderId']; //解析点位 $jsonFilePath = realpath(self::BUDGET_POSITION_JSON); $jsonData = file_get_contents($jsonFilePath); // 使用 json_decode 将 JSON 数据解码为 PHP 数组 $positionData = json_decode($jsonData, true); //設定ファイル内の画像のアップロードアドレスを取得します。 $uploadFolder = DI()->config->get('app.imageUploadDir'); //目录/订单号_payment_proof_.jpg $imageList = []; // $detailImage = new \PhalApi\Image\Lite(\PhalApi\Image\Lite::IMAGE_IMAGICK); $detailImage = new ImageEditor(); //打开图片 if ($pdfType == 1) { if($urikake == 1){ $detailImage->loadImage(realpath(self::BUDGET_GAITYUU_DETAIL)); }else{ $detailImage->loadImage(realpath(self::BUDGET_IPPAN_DETAIL)); } // $detailImage->loadImage(realpath(self::BUDGET_DETAIL)); } else { if($urikake == 1){ $detailImage->loadImage(realpath(self::BUDGET2_GAITYUU_DETAIL)); }else{ $detailImage->loadImage(realpath(self::BUDGET2_IPPAN_DETAIL)); } // $detailImage->loadImage(realpath(self::BUDGET2_DETAIL)); } // DI()->logger->info("getBudgetPageDetails", "detailimage info: ".$detailImage->width().'x'.$detailImage->height()); $pageCnt = 0; $pdfString = new PdfString(); //获取字体文件的绝对路径 $fontpath = realpath(self::FONT); //给图片自定义文字 foreach ($positionData as $value) { $key = $value['key']; $x = $value['x']; $y = $value['y']; if ($key == "detail") { $dtlX = $x; $dtlY = $y; //行数记录 $count = 0; //按换行符分割联络情报 $detailStrList = explode("\n", $budgetData[$key]); //循环处理每一行联络情报 for ($dline = 0;$dline < count($detailStrList); $dline++) { $value = $detailStrList[$dline]; //根据每行联络情报的长度,算出需要换行几次 $num = intdiv(round($pdfString->advanceStrLen($value)/2.0), PdfString::BUDGET_DETAIL_SPLIT_LENGTH); if($value && $dline > 0 && $dline < count($detailStrList)-1){ $detailImage->drawText('___________________________________________________________________________________________________________________________________________________________________________________________________________________',$fontpath,10, [9,9,9], array($dtlX, $dtlY+24)); } for ($a = 0; $a <= $num; $a++) { $count++; //按固定长度截取,进行换行操作 $detailComment = $pdfString->advanceSubstring($value, $a * PdfString::BUDGET_DETAIL_SPLIT_LENGTH*2, $a * PdfString::BUDGET_DETAIL_SPLIT_LENGTH*2+PdfString::BUDGET_DETAIL_SPLIT_LENGTH*2); //40行之内正常显示 DI()->logger->info("getBudgetPageDetails", "draw detail: ".$detailComment); DI()->logger->info("getBudgetPageDetails", "x y: ".$dtlX. " " .$dtlY); $detailImage->drawText($detailComment, $fontpath, self::BUDGET_FONT_SIZE, [0,0,0], array($dtlX, $dtlY)); // $this->drawText($detailImage, $detailComment, $fontpath, self::BUDGET_FONT_SIZE, self::COLOR, array($dtlX, $dtlY)); //下一行的显示位置,增加y的偏移量 $dtlY += self::DTL_Y_OFFSET; DI()->logger->info("check new page: count: $count, a: $a, num: $num, dline: $dline, total: ".count($detailStrList)); if ($count == 39 && ($a != $num || $dline != count($detailStrList) - 1)) { //超过40行保存文件 $detailImagePath = $uploadFolder . $orderId . "_budget_detail_".$pageCnt.".jpg"; DI()->logger->info("getBudgetPageDetails", "detailImagePath:" . $detailImagePath); $detailImage->saveImage($detailImagePath); $detailImage->destroy(); $pageCnt += 1; $imageList[] = $detailImagePath; if ($a != $num || $dline != count($detailStrList) - 1) { //重新创建一个新的detailImage // $detailImage = new \PhalApi\Image\Lite(); $detailImage = new ImageEditor(); //打开图片 if ($pdfType == 1) { if($urikake == 1){ $detailImage->loadImage(self::BUDGET_GAITYUU_DETAIL); }else{ $detailImage->loadImage(self::BUDGET_IPPAN_DETAIL); } // $detailImage->loadImage(self::BUDGET_DETAIL); } else { if($urikake == 1){ $detailImage->loadImage(self::BUDGET2_GAITYUU_DETAIL); }else{ $detailImage->loadImage(self::BUDGET2_IPPAN_DETAIL); } // $detailImage->loadImage(self::BUDGET2_DETAIL); } // 重置dtlY $dtlY = $y; $count = 0; } } } } } elseif ($key == "contactComment") { $ctX = $x; $ctY = $y; //行数记录 $count = 0; //按换行符分割联络情报 $detailStrList = explode("\n", $budgetData[$key]); $pdfString = new PdfString(); //循环处理每一行联络情报 foreach ($detailStrList as $value) { //根据每行联络情报的长度,算出需要换行几次 $num = intdiv(round($pdfString->advanceStrLen($value)/2.0), self::BUDGET_CONTRCT_SPLIT_LENGTH); for ($a = 0; $a <= $num; $a++) { $count++; //按固定长度截取,进行换行操作 $detailComment = $pdfString->advanceSubstring($value, $a * self::BUDGET_CONTRCT_SPLIT_LENGTH*2, $a * self::BUDGET_CONTRCT_SPLIT_LENGTH*2+self::BUDGET_CONTRCT_SPLIT_LENGTH*2); //判断是否已经是4行 if ($count == 9) { //超过20行直接显示省略号 $ctY += 10;//为了显示好看一点y增加一点偏移量 $detailImage->drawText('…', $fontpath, self::BUDGET_CONTRACT_FONT_SIZE, [0,0,0], array($ctX, $ctY)); //结束,跳出最外层循环 break 2; } else { //4行之内正常显示 $detailImage->drawText($detailComment, $fontpath, self::BUDGET_CONTRACT_FONT_SIZE, [0,0,0], array($ctX, $ctY)); //下一行的显示位置,增加y的偏移量 $ctY += self::DTL_CONTRACT_Y_OFFSET; } } } } } $detailImagePath = $uploadFolder . $orderId . "_budget_detail_".$pageCnt.".jpg"; DI()->logger->info("getBudgetPageDetails", "detailImagePath:" . $detailImagePath); $detailImage->saveImage($detailImagePath); $detailImage->destroy(); $imageList[] = $detailImagePath; return $imageList; } private function getBudgetOssPage($budgetData) { $pdfType = $budgetData['pdfType']; $needOss = $budgetData['needOss']; $orderId = $budgetData['orderId']; $carInfo = $budgetData['carInfo']; $mtssInfo = $budgetData['mtssInfo']; $imageList = []; if ($pdfType == 1) { if ($needOss) { $jsonFilePath3 = realpath(self::BUDGET_OSS_POSITION_JSON); $jsonData3 = file_get_contents($jsonFilePath3); $positionData3 = json_decode($jsonData3, true); //获取字体文件的绝对路径 $fontpath = realpath(self::FONT); //設定ファイル内の画像のアップロードアドレスを取得します。 $uploadFolder = DI()->config->get('app.imageUploadDir'); $detailImage2Path = $uploadFolder . $orderId . "_budget_detail2.jpg"; DI()->logger->info("getBudgetOssPage", "detailImage2Path:" . $detailImage2Path); $detail2Image = new \PhalApi\Image\Lite(); $detail2Image->open(self::BUDGET_OSS); $printData = array('number' => $carInfo['Number'], 'ssHint' => $carInfo['Number'].'|'.$carInfo['VIN'].'|'.$carInfo['Car_Name'].'|'.$mtssInfo['ss_name']); //给图片自定义文字 foreach ($positionData3 as $value) { $key = $value['key']; $x = $value['x']; $y = $value['y']; $fontSize = 40; if (isset($value['fontSize'])) { $fontSize = $value['fontSize']; } if ($printData[$key] !== null) { // OSS中的文字大小不同 $detail2Image->text($budgetData[$key], $fontpath, $fontSize, self::COLOR, array($x, $y)); } } $detail2Image->save($detailImage2Path, "jpg"); $imageList[] = $detailImage2Path; } } return $imageList; } function hexToRgb($hexColor) { // 去掉前导的 # $hexColor = ltrim($hexColor, '#'); // 如果是6位色号 if (strlen($hexColor) === 6) { list($r, $g, $b) = sscanf($hexColor, "%02x%02x%02x"); } // 如果是8位色号(忽略Alpha通道) elseif (strlen($hexColor) === 8) { list($r, $g, $b) = sscanf(substr($hexColor, 0, 6), "%02x%02x%02x"); } // 如果格式不合法 else { throw new RuntimeException("Invalid hex color format"); } return [$r, $g, $b]; } private function getBudgetReceiptPages($budgetData) { $details2 = $budgetData['detail2']; $carInfo = $budgetData['carInfo']; $orderInfo = $budgetData['orderInfo']; $customerInfo = $budgetData['customerInfo']; $mtssInfo = $budgetData['mtssInfo']; $orderId = $budgetData['orderId']; $jsonFilePath2 = realpath(self::BUDGET_RECIPT_POSITION_JSON); $jsonData2 = file_get_contents($jsonFilePath2); $positionData2 = json_decode($jsonData2, true); //获取字体文件的绝对路径 $fontpath = realpath(self::FONT); //設定ファイル内の画像のアップロードアドレスを取得します。 $uploadFolder = DI()->config->get('app.imageUploadDir'); $imageList = []; // $detail2Image = new \PhalApi\Image\Lite(); $detail2Image = new ImageEditor(); $imgReciptPath = ''; if($budgetData['pdfType'] == 2){ $imgReciptPath = realpath(self::BUDGET_SALE_RECIPT); }else{ $imgReciptPath = realpath(self::BUDGET_SAGYO_RECIPT); } $detail2Image->loadImage($imgReciptPath); $detail2Lines = substr_count($details2, "\n") + 1; DI()->logger->info("getBudgetReceiptPages", "detail2Lines: $detail2Lines"); $emptyLines = 49 - ($detail2Lines % 49); DI()->logger->info("getBudgetReceiptPages", "emptyLines: $emptyLines"); $toSkip = 1; if ($emptyLines < 3) { $emptyLines += 49; } elseif ($emptyLines < 4) { $toSkip = 0; } $toEmpty = $emptyLines - (4-$toSkip); DI()->logger->info("getBudgetReceiptPages", "toEmpty: $toEmpty"); for ($i = 0;$i<$toEmpty;$i++) { $details2 .= "\n"; } $details2 .= "\n".$customerInfo['name'] . $customerInfo['customer_name'].'様|型式:'.$carInfo['katashiki'].'|型式指定:'.$carInfo['Katashiki_Shitei'].'|類別区分:'.$carInfo['ruibetsu']; $yearJpn = ""; if ($carInfo['syodo_date'] != null && strlen($carInfo['syodo_date'] >= 4)) { $yearStr = substr($carInfo['syodo_date'], 0, 4); $yearInt = intval($yearStr); $yearJpn = $this->getYearJpn($yearInt); if (!empty($yearJpn)) { $yearJpn = "(".$yearJpn.")"; } } $Arrival_Date = ''; if($orderInfo['Arrival_Date']){ // $Arrival_Date = date('Y-m-d',$orderInfo['Arrival_Date']); $date2 = new DateTime($orderInfo['Arrival_Date']); $Arrival_Date = $date2->format('Y-m-d'); } $Complete_Date = ''; if($orderInfo['Complete_Date']){ // $Complete_Date = date('Y-m-d',$orderInfo['Complete_Date']); $date3 = new DateTime($orderInfo['Complete_Date']); $Complete_Date = $date3->format('Y-m-d'); } $syodo_date = ''; if($carInfo['syodo_date']){ $date1 = new DateTime($carInfo['syodo_date']); $syodo_date = $date1->format('Y年m月'); } $details2 .= "\n".'初年度登録:'.$syodo_date.$yearJpn.'|車台番号:'.$carInfo['VIN']; $details2 .= "\n".'入庫日:'.$Arrival_Date.'|作業完了日:'.$Complete_Date.'|走行距離:'.$carInfo['Millage'].'Km'; $budgetData = array('detail' => $details2, 'carinfo' => '車両情報:'.$carInfo['Number'].' | '.$carInfo['VIN'].' | '.$carInfo['Car_Name'].' | '.$mtssInfo['ss_name'] ); $pageCnt = 0; //给图片自定义文字 foreach ($positionData2 as $value) { $key = $value['key']; $x = $value['x']; $y = $value['y']; $color = $this->hexToRgb(self::COLOR); if (isset($value['color'])) { $color = $this->hexToRgb($value['color']); } $fontSize = self::BUDGET_FONT_SIZE; if (isset($value['fontSize'])) { $fontSize = $value['fontSize']; } if ($key == "detail") { $dtlX = $x; $dtlY = $y; //行数记录 $count = 0; //按换行符分割联络情报 $detailStrList = explode("\n", $budgetData[$key]); //循环处理每一行联络情报 for ($dline = 0;$dline < count($detailStrList); $dline++) { $value = $detailStrList[$dline]; //根据每行联络情报的长度,算出需要换行几次 $mblen = mb_strlen($value); $num = intdiv($mblen, PdfString::BUDGET_DETAIL2_SPLIT_LENGTH); if ($mblen % PdfString::BUDGET_DETAIL2_SPLIT_LENGTH == 0) { $num -= 1; } if ($num < 0) { $num = 0; } if($value && $dline > 0 && $dline < count($detailStrList)-3){ $detail2Image->drawText('___________________________________________________________________________________________________________________________________________________________________________________________________________________',$fontpath,10, [9,9,9], array($dtlX, $dtlY+24)); } for ($a = 0; $a <= $num; $a++) { $count++; //按固定长度截取,进行换行操作 $detailComment = mb_substr($value, $a * PdfString::BUDGET_DETAIL2_SPLIT_LENGTH, PdfString::BUDGET_DETAIL2_SPLIT_LENGTH); DI()->logger->info("getBudgetReceiptPages", "draw detail2: \"".$detailComment."\""); DI()->logger->info("getBudgetReceiptPages", "x y: ".$dtlX. " " .$dtlY); $detail2Image->drawText($detailComment, $fontpath, self::BUDGET_FONT_SIZE, $color, array($dtlX, $dtlY)); //下一行的显示位置,增加y的偏移量 $dtlY += self::DTL_Y_OFFSET; //判断是否已经是40行 if ($count == 49 && ($a != $num || $dline != count($detailStrList) - 1)) { //超过40行保存文件 $detailImage2Path = $uploadFolder . $orderId . "_budget_detail2_".$pageCnt.".jpg"; // $detailImagePath = $uploadFolder . $orderId . "_budget_detail_".$pageCnt.".jpg"; DI()->logger->info("getBudgetReceiptPages", "detailImagePath2:" . $detailImage2Path); $detail2Image->saveImage($detailImage2Path); $detail2Image->destroy(); $pageCnt += 1; $imageList[] = $detailImage2Path; if (!($a == $num && $dline == count($detailStrList) - 1)) { //重新创建一个新的detailImage $detail2Image = new ImageEditor(); $detail2Image->loadImage($imgReciptPath); // 重置dtlY $dtlY = $y; $count = 0; } } } } continue; } elseif ($budgetData[$key] !== null) { $detail2Image->drawText($budgetData[$key], $fontpath, $fontSize, $color, array($x, $y)); } } //超过40行保存文件 $detailImage2Path = $uploadFolder . $orderId . "_budget_detail2_".$pageCnt.".jpg"; // $detailImagePath = $uploadFolder . $orderId . "_budget_detail_".$pageCnt.".jpg"; DI()->logger->info("getBudgetReceiptPages", "detailImagePath2:" . $detailImage2Path); $detail2Image->saveImage($detailImage2Path); $detail2Image->destroy(); $pageCnt += 1; $imageList[] = $detailImage2Path; return $imageList; } private function getBudgetReceiptPages2($budgetData) { $carInfo = $budgetData['carInfo']; $orderInfo = $budgetData['orderInfo']; $customerInfo = $budgetData['customerInfo']; $mtssInfo = $budgetData['mtssInfo']; $orderId = $budgetData['orderId']; $jsonFilePath2 = realpath(self::BUDGET_RECIPT_POSITION_JSON); $jsonData2 = file_get_contents($jsonFilePath2); $positionData2 = json_decode($jsonData2, true); //获取字体文件的绝对路径 $fontpath = realpath(self::FONT); //設定ファイル内の画像のアップロードアドレスを取得します。 $uploadFolder = DI()->config->get('app.imageUploadDir'); $imageList = []; // $detail2Image = new \PhalApi\Image\Lite(); $detail2Image = new ImageEditor(); $imgReciptPath = ''; if($budgetData['pdfType'] == 2){ $imgReciptPath = realpath(self::BUDGET_SALE_RECIPT); }else{ $imgReciptPath = realpath(self::BUDGET_SAGYO_RECIPT); } $detail2Image->loadImage($imgReciptPath); $details2 = $customerInfo['name'] . $customerInfo['customer_name'].'様|型式:'.$carInfo['katashiki'].'|型式指定:'.$carInfo['Katashiki_Shitei'].'|類別区分:'.$carInfo['ruibetsu']; $yearJpn = ""; if ($carInfo['syodo_date'] != null && strlen($carInfo['syodo_date'] >= 4)) { $yearStr = substr($carInfo['syodo_date'], 0, 4); $yearInt = intval($yearStr); $yearJpn = $this->getYearJpn($yearInt); if (!empty($yearJpn)) { $yearJpn = "(".$yearJpn.")"; } } $Arrival_Date = ''; if($orderInfo['Arrival_Date']){ // $Arrival_Date = date('Y-m-d',$orderInfo['Arrival_Date']); $date2 = new DateTime($orderInfo['Arrival_Date']); $Arrival_Date = $date2->format('Y-m-d'); } $Complete_Date = ''; if($orderInfo['Complete_Date']){ // $Complete_Date = date('Y-m-d',$orderInfo['Complete_Date']); $date3 = new DateTime($orderInfo['Complete_Date']); $Complete_Date = $date3->format('Y-m-d'); } $syodo_date = ''; if($carInfo['syodo_date']){ $date1 = new DateTime($carInfo['syodo_date']); $syodo_date = $date1->format('Y年m月'); } $details2 .= "\n".'初年度登録:'.$syodo_date.$yearJpn.'|車台番号:'.$carInfo['VIN']; $details2 .= "\n".'入庫日:'.$Arrival_Date.'|作業完了日:'.$Complete_Date.'|走行距離:'.$carInfo['Millage'].'Km'; $details2 .= "\n\n".$budgetData['detail2']; //【社内資料】預り金と合計金額を追加 $pdfString = new PdfString(); $details2 = $details2 . "\n" .$pdfString->getDetail3Line("預り金",null,$budgetData['cost13']); $details2 = $details2 . "\n" .$pdfString->getDetail3Line("合計金額",null,$budgetData['orderTotal']); $detail2Lines = substr_count($details2, "\n") + 1; DI()->logger->info("getBudgetReceiptPages", "detail2Lines: $detail2Lines"); $emptyLines = 49 - ($detail2Lines % 49); DI()->logger->info("getBudgetReceiptPages", "emptyLines: $emptyLines"); $toSkip = 1; if ($emptyLines < 3) { $emptyLines += 49; } elseif ($emptyLines < 4) { $toSkip = 0; } $toEmpty = $emptyLines - (4-$toSkip); DI()->logger->info("getBudgetReceiptPages", "toEmpty: $toEmpty"); for ($i = 0;$i<$toEmpty;$i++) { $details2 .= "\n"; } $budgetData = array('detail' => $details2 ); $pageCnt = 0; //给图片自定义文字 foreach ($positionData2 as $value) { $key = $value['key']; $x = $value['x']; $y = $value['y']; $color = $this->hexToRgb(self::COLOR); if (isset($value['color'])) { $color = $this->hexToRgb($value['color']); } $fontSize = self::BUDGET_FONT_SIZE; if (isset($value['fontSize'])) { $fontSize = $value['fontSize']; } if ($key == "detail") { $dtlX = $x; $dtlY = $y; //行数记录 $count = 0; //按换行符分割联络情报 $detailStrList = explode("\n", $budgetData[$key]); //循环处理每一行联络情报 for ($dline = 0;$dline < count($detailStrList); $dline++) { $value = $detailStrList[$dline]; //根据每行联络情报的长度,算出需要换行几次 $mblen = mb_strlen($value); $num = intdiv($mblen, PdfString::BUDGET_DETAIL2_SPLIT_LENGTH); if ($mblen % PdfString::BUDGET_DETAIL2_SPLIT_LENGTH == 0) { $num -= 1; } if ($num < 0) { $num = 0; } if($value && $dline > 3 && $dline < count($detailStrList)-3){ $detail2Image->drawText('___________________________________________________________________________________________________________________________________________________________________________________________________________________',$fontpath,10, [9,9,9], array($dtlX, $dtlY+24)); } for ($a = 0; $a <= $num; $a++) { $count++; //按固定长度截取,进行换行操作 $detailComment = mb_substr($value, $a * PdfString::BUDGET_DETAIL2_SPLIT_LENGTH, PdfString::BUDGET_DETAIL2_SPLIT_LENGTH); DI()->logger->info("getBudgetReceiptPages", "draw detail2: \"".$detailComment."\""); DI()->logger->info("getBudgetReceiptPages", "x y: ".$dtlX. " " .$dtlY); $detail2Image->drawText($detailComment, $fontpath, self::BUDGET_FONT_SIZE, $color, array($dtlX, $dtlY)); //下一行的显示位置,增加y的偏移量 $dtlY += self::DTL_Y_OFFSET; //判断是否已经是40行 if ($count == 49 && ($a != $num || $dline != count($detailStrList) - 1)) { //超过40行保存文件 $detailImage2Path = $uploadFolder . $orderId . "_budget_detail2_".$pageCnt.".jpg"; // $detailImagePath = $uploadFolder . $orderId . "_budget_detail_".$pageCnt.".jpg"; DI()->logger->info("getBudgetReceiptPages", "detailImagePath2:" . $detailImage2Path); $detail2Image->saveImage($detailImage2Path); $detail2Image->destroy(); $pageCnt += 1; $imageList[] = $detailImage2Path; if (!($a == $num && $dline == count($detailStrList) - 1)) { //重新创建一个新的detailImage $detail2Image = new ImageEditor(); $detail2Image->loadImage($imgReciptPath); // 重置dtlY $dtlY = $y; $count = 0; } } } } continue; } elseif ($budgetData[$key] !== null) { $detail2Image->drawText($budgetData[$key], $fontpath, $fontSize, $color, array($x, $y)); } } //超过40行保存文件 $detailImage2Path = $uploadFolder . $orderId . "_budget_detail2_".$pageCnt.".jpg"; // $detailImagePath = $uploadFolder . $orderId . "_budget_detail_".$pageCnt.".jpg"; DI()->logger->info("getBudgetReceiptPages", "detailImagePath2:" . $detailImage2Path); $detail2Image->saveImage($detailImage2Path); $detail2Image->destroy(); $pageCnt += 1; $imageList[] = $detailImage2Path; return $imageList; } /** * @brief 車検見積予算PDF画像の生成 * * @param budgetData 車検見積予算データ * * @return 更新結果、フォーマットはJSON * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - data: データ配列 * - msg 正常に保存 * - msg: プロンプトメッセージ */ public function doSaveBudget(){ $budgetData = $this->fetchBudgetData(); $imageList = $this->getBudgetPage1($budgetData); $imageList = array_merge($imageList, $this->getBudgetPageDetails($budgetData)); if($budgetData['pdfType'] == 2){ $imageList = array_merge($imageList,$this->getBudgetReceiptPages2($budgetData)); } $imageList = array_merge($imageList, $this->getBudgetOssPage($budgetData)); DI()->logger->info("doSaveBudget", "imageList:" . json_encode($imageList)); $pdfType = $budgetData['pdfType']; $orderId = $budgetData['orderId']; $mtssDomain = new MtssDomain(); $pdfUploadFolder = DI()->config->get('app.pdfUploadDir'); $decoder = new JWTDecoder(); $jwt = $decoder->decode(); $userType = 'SS'; if ($jwt != null) { $jwtData = $jwt["data"]; $shopId = $jwtData->ssid; $mtss = $mtssDomain->get($shopId); if ($mtss != null && $mtss['category'] == 2) { $userType = 'MC'; } } $pdfTypeStr = "見積書"; if ($pdfType == 2) { $pdfTypeStr = "請求書"; } $pdfPath = $pdfUploadFolder . $orderId . "_" . date('Y-m-d') . "_" . $userType . "_" . $pdfTypeStr . ".pdf"; if (file_exists($pdfPath)) { $stop = false; $pdfNo = 2; while (!$stop) { $pdfPath = $pdfUploadFolder . $orderId . "_" . date('Y-m-d') . "_" . $userType . "_" . $pdfTypeStr . $pdfNo . ".pdf"; if (file_exists($pdfPath)) { $pdfNo++; } else { $stop = true; } } } $pdf = new Pdf(); $pdf->savePdf($pdfPath, $imageList); return array("msg" => "正常に保存"); } /** * @brief 作業指示書PDF画像の生成 * * @param budgetData 車検見積予算データ * * @return 更新結果、フォーマットはJSON * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - data: データ配列 * - msg 正常に保存 * - msg: プロンプトメッセージ */ public function doSaveSagyo(){ $budgetData = $this->fetchBudgetData(); $imageList = $this->getBudgetReceiptPages($budgetData); $orderId = $budgetData['orderId']; $mtssDomain = new MtssDomain(); $pdfUploadFolder = DI()->config->get('app.pdfUploadDir'); $decoder = new JWTDecoder(); $jwt = $decoder->decode(); $userType = 'SS'; if ($jwt != null) { $jwtData = $jwt["data"]; $shopId = $jwtData->ssid; $mtss = $mtssDomain->get($shopId); if ($mtss != null && $mtss['category'] == 2) { $userType = 'MC'; } } $pdfTypeStr = "作業指示書"; $pdfPath = $pdfUploadFolder . $orderId . "_" . date('Y-m-d') . "_" . $userType . "_" . $pdfTypeStr . ".pdf"; if (file_exists($pdfPath)) { $stop = false; $pdfNo = 2; while (!$stop) { $pdfPath = $pdfUploadFolder . $orderId . "_" . date('Y-m-d') . "_" . $userType . "_" . $pdfTypeStr . $pdfNo . ".pdf"; if (file_exists($pdfPath)) { $pdfNo++; } else { $stop = true; } } } $pdf = new Pdf(); $pdf->savePdf($pdfPath, $imageList); return array("msg" => "正常に保存"); } /** * @brief 車検見積予算PDF画像のpreview * * @param budgetData 車検見積予算データ * * @return 更新結果、フォーマットはJSON * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - data: データ配列 * - msg 正常に保存 * - msg: プロンプトメッセージ */ public function previewBudget(){ $budgetData = $this->fetchBudgetData(); $imageList = $this->getBudgetPage1($budgetData); $imageList = array_merge($imageList, $this->getBudgetPageDetails($budgetData)); $imageList = array_merge($imageList, $this->getBudgetOssPage($budgetData)); $pdf = new Pdf(); $pdf->savePdfI("", $imageList); exit(); } public function doNotifyOrderCanceled() { $orderId = $this->orderId; $datSyakenOrderList = new DatSyakenOrderListDomain(); //orderId による注文データのクエリ $orderInfo = $datSyakenOrderList->get($orderId); if (empty($orderInfo)) { throw new BadRequestException("order is invalid"); } // $openIds = null; //Car_IDにより、車情報を取得する $carsDomain = new DatCarsDomain(); $carInfo = $carsDomain->getCarInfo($orderInfo['Car_ID']); $mtssDomain = new MtssDomain(); $mtssInfo = $mtssDomain->get($orderInfo['Shop_ID']); // $openIds = $mtssInfo['line_openid']; $mcInfo = $mtssDomain->getUserByLoginId('mecha'); // $mcId = $mcInfo['line_openid']; // if ($mcId != null) { // $openIds = $openIds.",".$mcId; // } $toUserIDs = null; if(LineMessagingApiConfig::newApi == 1){ $ssid = $orderInfo['Shop_ID']; $mcSsid = $mcInfo['ID']; $datLineUserDomain = new DatLineUserDomain(); $lineUserIds = $datLineUserDomain->getLineUserIdBySsid($ssid,$mcSsid); $toUserIDs = implode(',',array_map(function($item) { return $item['userId']; }, $lineUserIds)); }else{ $toUserIDs = $mtssInfo['line_openid']; $mcId = $mcInfo['line_openid']; if ($mcId != null) { $toUserIDs = $toUserIDs.",".$mcId; } } //顧客IDに基づいて顧客情報を照会する $customerId = $orderInfo['Customer_ID']; $customerDomain = new DatCustomerDomain(); $customerInfo = $customerDomain->get($customerId); $lineDomain = new DatLineMsgDomain(); $lineDomain->saveMsg( sprintf("🚗オーダーがキャンセルされました。(%s、%s、%s、%s)", $customerInfo['name'].$customerInfo['customer_name'],$carInfo['carName'], $carInfo['number'],$mtssInfo['ss_name'] ), $toUserIDs,$orderId); } public function clearNewFlag() { $orderId = $this->orderId; $datSyakenOrderList = new DatSyakenOrderListDomain(); //orderId による注文データのクエリ $orderInfo = $datSyakenOrderList->get($orderId); if (empty($orderInfo)) { throw new BadRequestException("order is invalid"); } $datSyakenOrderList->updateOrderInfoByOrderId($orderId, array('new_flag' => 0)); return array('msg' => 'NEWフラグクリア成功'); } public function checkReserveState() { $orderId = $this->orderId; $datSyakenOrderList = new DatSyakenOrderListDomain(); //orderId による注文データのクエリ $orderInfo = $datSyakenOrderList->get($orderId); if (empty($orderInfo)) { throw new BadRequestException("order is invalid"); } $datCarsStorageReservationDomain = new DatCarsStorageReservationDomain(); $mcStorageDate = $datCarsStorageReservationDomain->getStorageDateByOrderId($orderId); if($mcStorageDate){ return array('msg' => '成功'); }else{ throw new BadRequestException("この注文には予約記録がありません。ご確認してください"); } } /** * @brief 連携用QR PDF画像の生成 * * @param orderId オーダーID * * @return 更新結果、フォーマットはJSON * - ret: ステータス コード、200 は成功を意味し、4xx は失敗を意味します * - data: データ配列 * - msg 正常に保存 * - msg: プロンプトメッセージ */ public function doSaveMcQrPage() { $orderId = $this->orderId; $budgetData = []; //解析点位 $jsonFilePath = realpath(self::MC_QR_POSITION_JSON); $jsonData = file_get_contents($jsonFilePath); // 使用 json_decode 将 JSON 数据解码为 PHP 数组 $positionData = json_decode($jsonData, true); // 检查是否成功解码 if ($positionData === null && json_last_error() !== JSON_ERROR_NONE) { // 解码失败,处理错误 echo 'Error decoding JSON: ' . json_last_error_msg(); } $orderDomain = new DatSyakenOrderListDomain(); $orderInfo = $orderDomain->get($orderId); $carId = $orderInfo['Car_ID']; $carDomain = new DatCarsDomain(); $carInfo = $carDomain->get($carId); $mtssDomain = new MtssDomain(); $mtssInfo = $mtssDomain->get($orderInfo['Shop_ID']); $datCarsStorageReservationDomain = new DatCarsStorageReservationDomain(); $carStorageReservation = $datCarsStorageReservationDomain->getCarLastStorageInfo($carId); $budgetData['carName'] = $carInfo['Car_Name']; $budgetData['number'] = $carInfo['Number']; $budgetData['ss'] = $mtssInfo['ss_name']; if ($carStorageReservation != null) { $budgetData['mcEnterDate'] = $carStorageReservation['station_date'] . '-' . str_pad($carStorageReservation['station_days'], 2, "0", STR_PAD_LEFT); $budgetData['pCarName'] = $carStorageReservation['p_car_name']; } $qrUrlServer = DI()->config->get('app.mcqrUrl'); //設定ファイル内の画像のアップロードアドレスを取得します。 $uploadFolder = DI()->config->get('app.imageUploadDir'); $pdfUploadFolder = DI()->config->get('app.pdfUploadDir'); //目录/订单号_payment_proof_.jpg $ImagePath = $uploadFolder . $orderId . "_mcqr.jpg"; $qr1ImgPath = $uploadFolder . $orderId . "_mcqr1.jpg"; $qr2ImgPath = $uploadFolder . $orderId . "_mcqr2.jpg"; $qrStr1 = "1/" . $orderId; $qrStr2 = "2/" . $orderId; $base641 = base64_encode($qrStr1); $base642 = base64_encode($qrStr2); $qrMsg1 = $qrUrlServer . $base641; $qrMsg2 = $qrUrlServer . $base642; //QRコードを生成するサービスクラスを取得する $qrcode = \PhalApi\DI()->get('qrcode', new \PhalApi\QrCode\Lite()); //QRコード画像を出力 $qrcode->png($qrMsg1, $qr1ImgPath); $qrcode->png($qrMsg2, $qr2ImgPath); $budgetData['qr1'] = $qr1ImgPath; $budgetData['qr2'] = $qr2ImgPath; $budgetData['qr1cover'] = self::MC_QR_1_COVER; $budgetData['qr2cover'] = self::MC_QR_2_COVER; DI()->logger->info("doSaveMcQrPage", "final data: " . json_encode($budgetData)); $Image = new \PhalApi\Image\Lite(); //打开图片 $Image->open(self::MC_QR); //获取字体文件的绝对路径 $fontpath = realpath(self::FONT); //给图片自定义文字 foreach ($positionData as $value) { $key = $value['key']; $x = $value['x']; $y = $value['y']; if ($key == 'type1' || $key == 'type2' || $key == 'type3') { if ($budgetData[$key] !== null) { $Image->water(self::MC_QR_SEL, array($x, $y), 100); } } elseif ($key == 'qr1' || $key == 'qr2' || $key == 'qr1cover' || $key == 'qr2cover') { if ($budgetData[$key] !== null) { $Image->water($budgetData[$key], array($x, $y), 100); } } elseif ($budgetData[$key] !== null) { $Image->text($budgetData[$key], $fontpath, self::BUDGET_FONT_SIZE, self::COLOR, array($x, $y)); } } $pdfPath = $pdfUploadFolder . $orderId . "_" . date('Y-m-d') . "_MCQR.pdf"; if (file_exists($pdfPath)) { $stop = false; $pdfNo = 2; while (!$stop) { $pdfPath = $pdfUploadFolder . $orderId . "_" . date('Y-m-d') . "_MCQR_" . $pdfNo . ".pdf"; if (file_exists($pdfPath)) { $pdfNo++; } else { $stop = true; } } } DI()->logger->info("doSaveMcQrPage", "ImagePath:" . $ImagePath); //将图片保存到指定位置 // $Image->save("./20_budget_20231228.jpg"); // $detailImage->save("./20_budget_detail_20231228.jpg"); $Image->save($ImagePath, "jpg"); DI()->logger->info("doSaveMcQrPage", "pdfPath:" . $pdfPath); $pdf = new Pdf(); $pdf->savePdf($pdfPath, [$ImagePath]); return array("msg" => "正常に保存"); } public function getOrderPdfs() { //注文ID $orderId = $this->orderId; DI()->logger->info("getOrderPdfs", "params:" . json_encode(array("orderId" => $orderId))); //サーバー上に保存されている画像のファイル名 $name = $orderId . '_'; //設定ファイル内の画像のアップロードアドレスを取得します。 $pdfUploadFolder = DI()->config->get('app.pdfUploadDir'); //判断目录是否存在 if (is_dir($pdfUploadFolder)) { if ($dh = opendir($pdfUploadFolder)) { $i = 0; while (($file = readdir($dh)) !== false) { if (str_starts_with($file, $name)) { $files[$i]['name'] = $file;//获取文件名 $files[$i]["time"] = date("Y-m-d H:i:s", filemtime($pdfUploadFolder.$file));//获取文件最近修改日期 $i++; } } } closedir($dh); foreach ($files as $k => $v) { $time[$k] = $v['time']; } array_multisort($time, SORT_ASC, SORT_STRING, $files);//按时间排序 foreach ($files as $k => $v) { $carPhotos[$k]['name'] = $v['name']; $carPhotos[$k]['path'] = $pdfUploadFolder; } return $carPhotos; } } public function getSalesList() { $startDate = $this->startDate; $endDate = $this->endDate; $datSyakenOrderListDomain = new DatSyakenOrderListDomain(); $salesList = $datSyakenOrderListDomain->getSalesList($startDate, $endDate); return $salesList; } public function getSalesByYear() { $year = $this->year; $datSyakenOrderListDomain = new DatSyakenOrderListDomain(); $salesList = $datSyakenOrderListDomain->getSalesByYear($year); $mtMcBudgetDomain = new MtMcBudgetDomain(); $budgetList = $mtMcBudgetDomain->getBudgetByYear($year); foreach($budgetList as $key => $budgetInfo){ if($budgetInfo['budget_num'] == 0){ $budgetList[$key]['budget_avg'] = 0; } else { $budgetList[$key]['budget_avg'] = round($budgetInfo['budget_val'] / $budgetInfo['budget_num'], 0); } $budgetList[$key]['sales_num'] = 0; $budgetList[$key]['sales_total'] = 0; $budgetList[$key]['sales_avg'] = 0; foreach($salesList as $salesInfo){ if($budgetInfo['month'] == $salesInfo['months'] && $budgetInfo['year'] == $salesInfo['years']){ $budgetList[$key]['sales_num'] = $salesInfo['sales_num']; $budgetList[$key]['sales_total'] = $salesInfo['sales_total']; $budgetList[$key]['deposit_total'] = $salesInfo['deposit_total']; if($salesInfo['sales_num'] == 0) { $budgetList[$key]['sales_avg'] = 0; } else { $budgetList[$key]['sales_avg'] = round($salesInfo['sales_total'] / $salesInfo['sales_num'], 0); } break; } } } return $budgetList; } public function updateCollectionFlag(){ $orderId = $this->orderId; $collectionFlag = $this->collectionFlag; $datSyakenOrderListDomain = new DatSyakenOrderListDomain(); $datSyakenOrderListDomain->updateOrderInfoByOrderId($orderId, array('collection_flag' => $collectionFlag)); return array('msg' => '入金フラグ更新成功'); } public function doSaveWholeBudget() { $customerId = $this->customerId; $month = $this->month; $this->budgetData = []; $this->pdfType = null; // $datSyakenOrderListDomain = new DatSyakenOrderListDomain(); // $datSyakenOrderListDomain->getWholeBudgetByOrderIds($orderIds); $budgetData2 = $this->getWholeBudgetData($customerId, $month); $imageList = $this->getWholeBudgetbyMonth($budgetData2, $customerId, $month); if(isset($budgetData2['ids']) && count($budgetData2['ids']) > 0){ foreach($budgetData2['ids'] as $id){ $this->budgetData['orderId'] = $id; $budgetData = $this->fetchBudgetData(); $imageList = array_merge($imageList, $this->getBudgetPageDetails($budgetData)); } } $pdfUploadFolder = DI()->config->get('app.pdfUploadDir'); $userType = 'MC'; $pdfTypeStr = "合計請求書"; $pdfPath = $pdfUploadFolder . $customerId . "_" . $month . "_" . $userType . "_" . $pdfTypeStr . ".pdf"; if (file_exists($pdfPath)) { $stop = false; $pdfNo = 2; while (!$stop) { $pdfPath = $pdfUploadFolder . $customerId . "_" . $month . "_" . $userType . "_" . $pdfTypeStr . $pdfNo . ".pdf"; if (file_exists($pdfPath)) { $pdfNo++; } else { $stop = true; } } } $pdf = new Pdf(); $pdf->savePdf($pdfPath, $imageList); return array('pdfPath' => $pdfPath); } private function getWholeBudgetData($customerId, $month, $force = false) { $budgetData = []; $datCustomerDomain = new DatCustomerDomain(); $customerInfo = $datCustomerDomain->get($customerId); if (isset($customerInfo)) { $budgetData['category'] = $customerInfo['category']; $budgetData['customerName'] = $customerInfo['name']." ".$customerInfo['customer_name'].'様'; if (strlen($customerInfo['ZIP_Code']) == 7) { $budgetData['zipCode'] = '〒'.substr($customerInfo['ZIP_Code'], 0, 3) . '-' . substr($customerInfo['ZIP_Code'], 3); } $budgetData['customerAddress'] = $customerInfo['customer_address'].$customerInfo['Customer_address_2']; } $datSyakenOrderListDomain = new DatSyakenOrderListDomain(); $detailData = []; if ($force) { $detailData = $datSyakenOrderListDomain->listNoPayedBudgetByOrderIds($customerId, $month); }else{ $detailData = $datSyakenOrderListDomain->getWholeBudgetByOrderIds($customerId, $month); } $detail = []; $totalWithTax = 0; $noTaxMoney = 0; $orderDetailDomain = new OrderDetailDomain(); $tax = $orderDetailDomain->getTax()["tax"]; $ids = []; foreach($detailData as $value){ if($budgetData['category'] == 1){ $detail[] = [ 'ss_return_date' => date('Y年m月d日', strtotime($value['ss_return_date'])), 'Order_ID' => $value['Car_Name'], 'ssName' => isset($value['Number']) ? trim($value['Number']) : '', 'total' => (int)$value['total'], 'miscellaneous_total' => (int)$value['miscellaneous_total'] ]; }else{ $detail[] = [ 'ss_return_date' => date('Y年m月d日', strtotime($value['ss_return_date'])), 'Order_ID' => $value['Order_ID'], 'ssName' => $value['ss_name'], 'total' => (int)$value['total'], 'miscellaneous_total' => (int)$value['miscellaneous_total'] ]; } $noTaxMoney += (int)$value['miscellaneous_total']; $totalWithTax += (int)$value['total']; $ids[] = $value['Order_ID']; } $datSyakenOrderListDomain->updateOrderInfoByOrderId($ids, array('print_flag' => 1)); $taxMoney = round(($totalWithTax-$noTaxMoney)* $tax/(1+$tax)); $budgetData['totalWithTax'] = number_format($totalWithTax-$noTaxMoney).'円(消費税'.number_format($taxMoney).'円)'; $budgetData['noTaxMoney'] = number_format($noTaxMoney).'円'; $budgetData['taxchosei'] = '0円'; $budgetData['thisMonthOrderMoney'] = $totalWithTax; $budgetData['totalAmount'] = number_format($budgetData['thisMonthOrderMoney']).'円(消費税'.number_format($taxMoney).'円)'; $budgetData['detail'] = $detail; $budgetData['ids'] = $ids; $budgetData['printDate'] = date('Y年m月d日'); $budgetData['orderMonth'] = date('Y年m月', strtotime($month . '-01')); $budgetData['payExpireDate'] = date('Y年m月d日', strtotime($month . '-01 +2 month -1 day')); $budgetData['lastMonthOrderMoney'] = 0; $budgetData['lastMonthPayedMoney'] = 0; $lastMonthOrderInfo = $datSyakenOrderListDomain->getLastMonthOrderMoney($customerId, $month); foreach($lastMonthOrderInfo as $value){ $budgetData['lastMonthOrderMoney'] = $value['sales_total']; $budgetData['lastMonthPayedMoney'] = $value['payed_total']; } $budgetData['balance'] = $budgetData['lastMonthOrderMoney'] - $budgetData['lastMonthPayedMoney']; // $budgetData['thisMonthOrderMoney'] = 1713783; $budgetData['totalMoney'] = $budgetData['balance'] + $budgetData['thisMonthOrderMoney']; DI()->logger->info("getWholeBudgetData", "budgetData:" . json_encode($budgetData)); return $budgetData; } private function getWholeBudgetbyMonth($budgetData, $customerId, $month) { $jsonFilePath = realpath(self::WHOLE_BUDGET_POSITION_JSON); $jsonData = file_get_contents($jsonFilePath); $positionData = json_decode($jsonData, true); //获取字体文件的绝对路径 $fontpath = realpath(self::FONT); //設定ファイル内の画像のアップロードアドレスを取得します。 $uploadFolder = DI()->config->get('app.imageUploadDir'); $imageList = []; // $detail2Image = new \PhalApi\Image\Lite(); $detailImage = new ImageEditor(); $imgReciptPath = realpath(self::WHOLE_BUDGET0); $detailImage->loadImage($imgReciptPath); $detail2Image = new ImageEditor(); if($budgetData['category'] == 1){ $detail2Path = realpath(self::WHOLE_BUDGET4); } else { $detail2Path = realpath(self::WHOLE_BUDGET2); } $detail2Image->loadImage($detail2Path); $pdfString = new PdfString(); //给图片自定义文字 foreach ($positionData as $value) { $key = $value['key']; $x = $value['x']*1.5; $y = $value['y']*1.5; $color = $this->hexToRgb(self::COLOR); if (isset($value['fontColor'])) { $color = $this->hexToRgb($value['fontColor']); } $fontSize = self::WHOLE_BUDGET_FONT_SIZE; if (isset($value['fontSize'])) { $fontSize = $value['fontSize']*1.5; } if ($key == "detail") { $dtlX = $x; $dtlY = $y; $detailList = $budgetData[$key]; if (empty($detailList)) { continue; } //行数记录 $count = count($detailList); $index = 1; $pageCnt = ceil($count/30); if($pageCnt > 1){ $detail3Image = new ImageEditor(); if($budgetData['category'] == 1){ $detail3Path = realpath(self::WHOLE_BUDGET3); } else { $detail3Path = realpath(self::WHOLE_BUDGET1); } $detail3Image->loadImage($detail3Path); } foreach($detailList as $value){ if($pageCnt == 1){ $detail2Image->drawText($pdfString->getPaddingLeftString($index, 8), $fontpath, self::WHOLE_BUDGET_DTL_FONT_SIZE, $color, array($dtlX , $dtlY)); if(isset($value["ss_return_date"])){ $detail2Image->drawText($value["ss_return_date"], $fontpath, self::WHOLE_BUDGET_DTL_FONT_SIZE, $color, array($dtlX + 310, $dtlY)); } if(isset($value["Order_ID"])){ $detail2Image->drawText($value["Order_ID"], $fontpath, self::WHOLE_BUDGET_FONT_SIZE, $color, array($dtlX + 680, $dtlY)); } if(isset($value["ssName"])){ $nameLength = $pdfString->advanceStrLen($value["ssName"]); if($nameLength > 16){ $detail2Image->drawText($value["ssName"], $fontpath, 32, $color, array($dtlX + 1055, $dtlY)); }else{ $detail2Image->drawText($pdfString->getPaddingLeftString($value["ssName"], 7 + ceil($nameLength/2)), $fontpath, self::WHOLE_BUDGET_FONT_SIZE, $color, array($dtlX + 1055, $dtlY)); } } if(isset($value["total"])){ $detail2Image->drawText($pdfString->getPaddingLeftString($pdfString->getDividedNumber($value["total"]), 25), $fontpath, self::WHOLE_BUDGET_FONT_SIZE, $color, array($dtlX + 1370, $dtlY)); } }else{ $detail3Image->drawText($pdfString->getPaddingLeftString($index, 8), $fontpath, self::WHOLE_BUDGET_DTL_FONT_SIZE, $color, array($dtlX, $dtlY)); if(isset($value["ss_return_date"])){ $detail3Image->drawText($value["ss_return_date"], $fontpath, self::WHOLE_BUDGET_DTL_FONT_SIZE, $color, array($dtlX + 310, $dtlY)); } if(isset($value["Order_ID"])){ $detail3Image->drawText($value["Order_ID"], $fontpath, self::WHOLE_BUDGET_FONT_SIZE, $color, array($dtlX + 680, $dtlY)); } if(isset($value["ssName"])){ $nameLength = $pdfString->advanceStrLen($value["ssName"]); if($nameLength > 16){ $detail3Image->drawText($value["ssName"], $fontpath, 32, $color, array($dtlX + 1055, $dtlY)); }else{ $detail3Image->drawText($pdfString->getPaddingLeftString($value["ssName"], 7 + ceil($nameLength/2)), $fontpath, self::WHOLE_BUDGET_FONT_SIZE, $color, array($dtlX + 1055, $dtlY)); } } if(isset($value["total"])){ $detail3Image->drawText($pdfString->getPaddingLeftString($pdfString->getDividedNumber($value["total"]), 25), $fontpath, self::WHOLE_BUDGET_FONT_SIZE, $color, array($dtlX + 1370, $dtlY)); } } //下一行的显示位置,增加y的偏移量 $dtlY += self::DTL_WHOLE_BUDGET_Y_OFFSET; //判断是否已经是30行 if($index % 30 == 0 && $pageCnt > 1){ $detail3ImagePath = $uploadFolder . $customerId. "_".$month."_whole_budget_middle_".$pageCnt.".jpg"; $detail3Image->saveImage($detail3ImagePath); $detail3Image->destroy(); $imageList[] = $detail3ImagePath; //重新初始化图片和位置 $pageCnt --; if($pageCnt > 1){ $detail3Image = new ImageEditor(); if($budgetData['category'] == 1){ $detail3Path = realpath(self::WHOLE_BUDGET3); } else { $detail3Path = realpath(self::WHOLE_BUDGET1); } $detail3Image->loadImage($detail3Path); } $dtlY = $y; } $index++; } continue; } elseif ($budgetData[$key] !== null) { if($key == 'customerName'){ $detailImage->drawText($budgetData[$key], $fontpath, $fontSize, $color, array($x, $y)); $nameLength = $pdfString->advanceStrLen($budgetData[$key]); $lineStr = ''; for($i=0;$i<$nameLength/2;$i++){ $lineStr .= '_'; } $detailImage->drawText($lineStr,$fontpath, $fontSize, $color, array($x, $y+6)); }elseif($key == 'lastMonthOrderMoney' || $key == 'lastMonthPayedMoney' || $key == 'balance' || $key == 'thisMonthOrderMoney' || $key == 'totalMoney'){ $priceStr = $pdfString->getDividedNumber($budgetData[$key]); $nameLength = $pdfString->advanceStrLen($priceStr); if($nameLength > 16){ $detailImage->drawText($priceStr, $fontpath, self::WHOLE_BUDGET_FONT_SIZE, $color, array($x, $y)); }else{ $detailImage->drawText($pdfString->getPaddingLeftString($priceStr, 7 + floor($nameLength/2)), $fontpath, $fontSize, $color, array($x, $y)); } // $detailImage->drawText($pdfString->getPaddingLeftString($pdfString->getDividedNumber($budgetData[$key]), 15), $fontpath, $fontSize, $color, array($x, $y)); }elseif($key == 'totalWithTax' || $key == 'noTaxMoney' || $key == 'totalAmount' || $key == 'taxchosei'){ $detail2Image->drawText($pdfString->getPaddingLeftString($budgetData[$key], 30), $fontpath, $fontSize, $color, array($x, $y)); }else{ $detailImage->drawText($budgetData[$key], $fontpath, $fontSize, $color, array($x, $y)); } } } $detailImagePath = $uploadFolder . $customerId. "_".$month."_whole_budget_first.jpg"; DI()->logger->info("getWholeBudgetbyMonth", "detailImagePath:" . $detailImagePath); $detailImage->saveImage($detailImagePath); $detailImage->destroy(); array_splice($imageList, 0, 0, $detailImagePath); $detail2ImagePath = $uploadFolder . $customerId. "_".$month."_whole_budget_last.jpg"; DI()->logger->info("getWholeBudgetbyMonth", "detail2ImagePath:" . $detail2ImagePath); $detail2Image->saveImage($detail2ImagePath); $detail2Image->destroy(); $imageList[] = $detail2ImagePath; return $imageList; } public function doSaveNoPayedBudgetByMonth(){ $month = $this->month; $datSyakenOrderListDomain = new DatSyakenOrderListDomain(); $noPayedArr = $datSyakenOrderListDomain->listNoPayedBudgetByMonths($month); $pathArr = []; if (empty($noPayedArr)) { throw new BadRequestException("再発行する合計請求書がありません。ご確認してください"); } $pdfUploadFolder = DI()->config->get('app.pdfUploadDir'); $userType = 'MC'; $pdfTypeStr = "合計請求書"; $this->budgetData = []; $this->pdfType = null; foreach($noPayedArr as $key => $value){ $customerId = $value['Customer_ID']; $budgetData2 = $this->getWholeBudgetData($customerId, $month, true); $imageList = $this->getWholeBudgetbyMonth($budgetData2, $customerId, $month); if(isset($budgetData2['ids']) && count($budgetData2['ids']) > 0){ foreach($budgetData2['ids'] as $id){ $this->budgetData['orderId'] = $id; $budgetData = $this->fetchBudgetData(); $imageList = array_merge($imageList, $this->getBudgetPageDetails($budgetData)); } } $pdfPath = $pdfUploadFolder . $customerId . "_" . $month . "_" . $userType . "_" . $pdfTypeStr . ".pdf"; if (file_exists($pdfPath)) { $stop = false; $pdfNo = 2; while (!$stop) { $pdfPath = $pdfUploadFolder . $customerId . "_" . $month . "_" . $userType . "_" . $pdfTypeStr . $pdfNo . ".pdf"; if (file_exists($pdfPath)) { $pdfNo++; } else { $stop = true; } } } $pdf = new Pdf(); $pdf->savePdf($pdfPath, $imageList); $pathArr[] = $pdfPath; } $zip = new ZipArchive(); $output = $pdfUploadFolder . $month . "_" . $userType . "_" . $pdfTypeStr . ".zip"; if (file_exists($output)) { $stop = false; $pdfNo = 2; while (!$stop) { $output = $pdfUploadFolder . $month . "_" . $userType . "_" . $pdfTypeStr . $pdfNo . ".zip"; if (file_exists($output)) { $pdfNo++; } else { $stop = true; } } } if ($zip->open($output, ZipArchive::CREATE) === TRUE) { foreach ($pathArr as $file) { $zip->addFile($file, basename($file)); } $zip->close(); } else { throw new BadRequestException("zipファイルの生成に失敗しました。システム管理者にお問い合わせください。"); } return array('zipPath' => $output); } }