송용우 4 місяців тому
батько
коміт
0abd58486a

+ 1 - 0
backend/app/Config/Routes2.php

@@ -124,6 +124,7 @@ $routes->post('deli/markDelivered', 'Deli::markAsDelivered');
 $routes->post('deli/markSettled', 'Deli::markAsSettled');
 $routes->post('deli/settlement', 'Deli::getSettlementList');
 $routes->post('deli/pendingOrdersForVendor', 'Deli::getPendingOrdersForVendor');
+$routes->post('deli/updateStatus', 'Deli::updateStatus');
 
 // =============================================================================
 // 파트너십 전용 웹 라우팅 (향후 확장)

+ 59 - 0
backend/app/Controllers/Deli.php

@@ -580,4 +580,63 @@ class Deli extends ResourceController
         return $this->respond($lists, 200);
     }
 
+    // 배송 상태 업데이트
+    public function updateStatus()
+    {
+        $db = \Config\Database::connect();
+        $request = $this->request->getJSON(true);
+        
+        $itemSeq = isset($request['item_seq']) ? $request['item_seq'] : null;
+        $status = isset($request['status']) ? $request['status'] : null;
+        
+        if (!$itemSeq || !$status) {
+            return $this->fail('필수 파라미터가 누락되었습니다.', 400);
+        }
+        
+        // 유효한 상태값인지 확인
+        $validStatuses = ['PENDING', 'SHIPPING', 'DELIVERED', 'COMPLETE'];
+        if (!in_array($status, $validStatuses)) {
+            return $this->fail('유효하지 않은 상태값입니다.', 400);
+        }
+        
+        $db->transBegin();
+        
+        try {
+            // DELIVERY_STATUS 컬럼이 존재하는지 확인
+            $columns = $db->getFieldNames('ITEM_ORDER_LIST');
+            if (in_array('DELIVERY_STATUS', $columns)) {
+                $updateData = ['DELIVERY_STATUS' => $status];
+                
+                // 상태에 따라 추가 필드 업데이트
+                if ($status === 'SHIPPING' && in_array('SHIPPING_DATE', $columns)) {
+                    $updateData['SHIPPING_DATE'] = date('Y-m-d H:i:s');
+                } elseif ($status === 'DELIVERED' && in_array('DELIVERED_DATE', $columns)) {
+                    $updateData['DELIVERED_DATE'] = date('Y-m-d H:i:s');
+                }
+                
+                $result = $db->table('ITEM_ORDER_LIST')
+                    ->where('ITEM_SEQ', $itemSeq)
+                    ->update($updateData);
+                
+                if ($result) {
+                    $db->transCommit();
+                    return $this->respond([
+                        'message' => '상태가 성공적으로 업데이트되었습니다.',
+                        'status' => $status
+                    ], 200);
+                } else {
+                    $db->transRollback();
+                    return $this->fail('상태 업데이트에 실패했습니다.', 500);
+                }
+            } else {
+                $db->transRollback();
+                return $this->fail('DELIVERY_STATUS 컬럼이 존재하지 않습니다.', 500);
+            }
+            
+        } catch (\Exception $e) {
+            $db->transRollback();
+            return $this->fail('상태 업데이트 중 오류가 발생했습니다: ' . $e->getMessage(), 500);
+        }
+    }
+
 }

+ 76 - 7
pages/view/common/deli/detail.vue

@@ -315,6 +315,59 @@
     주문일: "ORDER_DATE",
   };
 
+  // Excel 날짜를 문자열로 변환하는 함수 (시간 포함)
+  const convertExcelDate = (value) => {
+    // Date 객체인 경우 (XLSX 라이브러리가 cellDates: true로 자동 변환한 경우)
+    if (value instanceof Date) {
+      try {
+        const year = value.getFullYear();
+        const month = String(value.getMonth() + 1).padStart(2, '0');
+        const day = String(value.getDate()).padStart(2, '0');
+        const hours = String(value.getHours()).padStart(2, '0');
+        const minutes = String(value.getMinutes()).padStart(2, '0');
+        const seconds = String(value.getSeconds()).padStart(2, '0');
+        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
+      } catch (error) {
+        console.warn('Date 객체 변환 실패:', value, error);
+        return value;
+      }
+    }
+    
+    // 숫자 타입이고 날짜 범위에 있는지 확인 (Excel 시리얼 날짜)
+    if (typeof value === 'number' && value > 1 && value < 100000) {
+      try {
+        // Excel의 시리얼 번호를 Date 객체로 변환
+        const excelStartDate = new Date(1900, 0, 1); // 1900년 1월 1일
+        const convertedDate = new Date(excelStartDate.getTime() + (value - 2) * 24 * 60 * 60 * 1000);
+        
+        const year = convertedDate.getFullYear();
+        const month = String(convertedDate.getMonth() + 1).padStart(2, '0');
+        const day = String(convertedDate.getDate()).padStart(2, '0');
+        
+        return `${year}-${month}-${day} 00:00:00`;
+      } catch (error) {
+        console.warn('Excel 시리얼 날짜 변환 실패:', value, error);
+        return value;
+      }
+    }
+    
+    // 이미 문자열 형태의 날짜인 경우
+    if (typeof value === 'string') {
+      // YYYY.MM.DD 또는 YYYY-MM-DD 형태를 YYYY-MM-DD 00:00:00로 변환
+      let dateStr = value.replace(/\./g, '-').trim();
+      
+      // 시간 부분이 없으면 00:00:00 추가
+      if (!dateStr.includes(' ') && dateStr.match(/^\d{4}-\d{2}-\d{2}$/)) {
+        dateStr += ' 00:00:00';
+      }
+      
+      return dateStr;
+    }
+    
+    console.log('날짜 변환 대상이 아님:', typeof value, value);
+    return value;
+  };
+
   const addEmptyRow = () => {
     const newRow = {
       BUYER_NAME: "",
@@ -438,10 +491,10 @@
     reader.onload = async (e) => {
       try {
         const data = new Uint8Array(e.target.result);
-        const workbook = XLSX.read(data, { type: "array" });
+        const workbook = XLSX.read(data, { type: "array", cellDates: true });
         const sheetName = workbook.SheetNames[0];
         const worksheet = workbook.Sheets[sheetName];
-        const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
+        const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1, raw: false, dateNF: 'yyyy-mm-dd' });
 
         if (jsonData.length < 2) {
           $toast.error(
@@ -472,7 +525,12 @@
             headers.forEach((header, index) => {
               const fieldName = excelColumnMapping[header];
               if (fieldName && row[index] !== undefined && row[index] !== "") {
-                mappedRow[fieldName] = row[index];
+                // 주문일 필드인 경우 날짜 변환 처리
+                if (fieldName === 'ORDER_DATE') {
+                  mappedRow[fieldName] = convertExcelDate(row[index]);
+                } else {
+                  mappedRow[fieldName] = row[index];
+                }
                 hasValidData = true;
               }
             });
@@ -586,10 +644,10 @@
     reader.onload = async (e) => {
       try {
         const data = new Uint8Array(e.target.result);
-        const workbook = XLSX.read(data, { type: "array" });
+        const workbook = XLSX.read(data, { type: "array", cellDates: true });
         const sheetName = workbook.SheetNames[0];
         const worksheet = workbook.Sheets[sheetName];
-        const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
+        const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1, raw: false, dateNF: 'yyyy-mm-dd' });
 
         if (jsonData.length < 2) {
           $toast.error("엑셀 파일에 데이터가 없습니다. 헤더와 최소 1개 이상의 데이터 행이 필요합니다.");
@@ -806,8 +864,19 @@
 
   const formatDateForComparison = (dateStr) => {
     if (!dateStr) return '';
-    // YYYY.MM.DD 또는 YYYY-MM-DD 형태를 YYYY-MM-DD로 통일
-    return dateStr.toString().replace(/\./g, '-').trim();
+    
+    // 문자열로 변환하고 공백 제거
+    let formattedDate = dateStr.toString().trim();
+    
+    // YYYY.MM.DD 형태를 YYYY-MM-DD로 변환
+    formattedDate = formattedDate.replace(/\./g, '-');
+    
+    // 시간 부분이 있으면 제거하고 날짜 부분만 추출
+    if (formattedDate.includes(' ')) {
+      formattedDate = formattedDate.split(' ')[0];
+    }
+    
+    return formattedDate;
   };
 
   const validateAndMatchOrders = async (uploadData) => {