|
|
@@ -36,7 +36,7 @@ class Deli extends ResourceController
|
|
|
// 배송정보가 등록되지 않은 주문만 (배송관리 페이지용)
|
|
|
// 배송업체와 송장번호가 모두 비어있는 경우만 포함 (AND 조건)
|
|
|
$subQuery->where('(DELI_COMP IS NULL OR DELI_COMP = "")')
|
|
|
- ->where('(DELI_NUMB IS NULL OR DELI_NUMB = "")');
|
|
|
+ ->where('(DELI_NUMB IS NULL OR DELI_NUMB = "")');
|
|
|
|
|
|
$subQuery->groupBy('ITEM_SEQ');
|
|
|
|
|
|
@@ -69,6 +69,191 @@ class Deli extends ResourceController
|
|
|
return $this->respond($lists, 200);
|
|
|
}
|
|
|
|
|
|
+ //아이템 검색
|
|
|
+ public function deliSearch()
|
|
|
+ {
|
|
|
+ $db = \Config\Database::connect();
|
|
|
+
|
|
|
+ // 요청 바디에서 filter와 keyword 추출
|
|
|
+ $request = $this->request->getJSON(true);
|
|
|
+ $filter = isset($request['filter']) ? $request['filter'] : null;
|
|
|
+ $keyword = isset($request['keyword']) ? $request['keyword'] : null;
|
|
|
+ $startDate = $request['startDate'] ?? null;
|
|
|
+ $endDate = $request['endDate'] ?? null;
|
|
|
+ $showYN = $request['showYN'] ?? null;
|
|
|
+ $itemType = isset($request['TYPE']) ? $request['TYPE'] : null;
|
|
|
+ $memberType = isset($request['MEMBER_TYPE']) ? $request['MEMBER_TYPE'] : null;
|
|
|
+ $companyNumber = isset($request['COMPANY_NUMBER']) ? $request['COMPANY_NUMBER'] : null;
|
|
|
+ $memberSeq = isset($request['MEMBER_SEQ']) ? $request['MEMBER_SEQ'] : null;
|
|
|
+ $infSeq = isset($request['INF_SEQ']) ? $request['INF_SEQ'] : null;
|
|
|
+
|
|
|
+ $filterMap = [
|
|
|
+ 'name' => 'I.NAME',
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 서브쿼리: 사용자 타입에 따른 주문 집계
|
|
|
+ $subQuery = $db->table('ITEM_ORDER_LIST')
|
|
|
+ ->select('ITEM_SEQ, SUM(QTY) AS sum_qty, SUM(TOTAL) AS sum_total, MAX(REG_DATE) AS latest_reg_date');
|
|
|
+
|
|
|
+ // 인플루언서: 본인이 받은 주문만
|
|
|
+ if ($memberType === 'INFLUENCER') {
|
|
|
+ if (is_null($infSeq)) {
|
|
|
+ // INF_SEQ가 없으면 빈 결과 반환
|
|
|
+ return $this->respond([], 200);
|
|
|
+ }
|
|
|
+ $subQuery->where('INF_SEQ', $infSeq);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 배송정보가 등록되지 않은 주문만 (배송관리 페이지용)
|
|
|
+ $subQuery->where('(DELI_COMP IS NULL OR DELI_COMP = "")')
|
|
|
+ ->where('(DELI_NUMB IS NULL OR DELI_NUMB = "")');
|
|
|
+
|
|
|
+ $subQuery->groupBy('ITEM_SEQ');
|
|
|
+
|
|
|
+ // 메인 쿼리: ITEM_LIST와 위 서브쿼리 조인 (실제 주문이 있는 제품만)
|
|
|
+ $builder = $db->table('ITEM_LIST I')
|
|
|
+ ->select('I.*, O.sum_qty, O.sum_total, O.latest_reg_date')
|
|
|
+ ->join("(" . $subQuery->getCompiledSelect() . ") O", 'I.SEQ = O.ITEM_SEQ', 'inner')
|
|
|
+ ->where('I.DEL_YN', 'N');
|
|
|
+
|
|
|
+ // 사용자 타입별 필터링
|
|
|
+ if ($memberType === 'VENDOR' && !empty($companyNumber)) {
|
|
|
+ // 벤더사의 경우: 자사 제품만 검색
|
|
|
+ $builder->where('I.COMPANY_NUMBER', $companyNumber);
|
|
|
+ } elseif ($memberType === 'INFLUENCER' && !empty($memberSeq)) {
|
|
|
+ // 인플루언서의 경우: 파트너십이 체결된 벤더사의 제품만 검색
|
|
|
+ $builder->select('I.*, O.sum_qty, O.sum_total, O.latest_reg_date, VIP.STATUS as PARTNERSHIP_STATUS');
|
|
|
+ $builder->join('VENDOR_LIST VL', 'I.COMPANY_NUMBER = VL.COMPANY_NUMBER', 'inner');
|
|
|
+ $builder->join('VENDOR_INFLUENCER_PARTNERSHIP VIP', 'VL.SEQ = VIP.VENDOR_SEQ', 'inner');
|
|
|
+ $builder->where('VIP.INFLUENCER_SEQ', $memberSeq);
|
|
|
+ $builder->where('VIP.STATUS', 'APPROVED');
|
|
|
+ $builder->where('VIP.IS_ACTIVE', 'Y');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 키워드 검색
|
|
|
+ if (!empty($keyword)) {
|
|
|
+ if (empty($filter)) {
|
|
|
+ // 필터를 선택 안했으면 전체 검색
|
|
|
+ $first = true;
|
|
|
+ foreach ($filterMap as $column) {
|
|
|
+ if ($first) {
|
|
|
+ $builder->like($column, $keyword);
|
|
|
+ $first = false;
|
|
|
+ } else {
|
|
|
+ $builder->orLike($column, $keyword);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } elseif (isset($filterMap[$filter])) {
|
|
|
+ // 특정 필터 검색
|
|
|
+ $builder->like($filterMap[$filter], $keyword);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 노출중, 비노출 여부 확인
|
|
|
+ if (!empty($showYN)) {
|
|
|
+ $builder->where('I.SHOW_YN', $showYN);
|
|
|
+ }
|
|
|
+ if (!empty($itemType)) {
|
|
|
+ $builder->where('I.TYPE', $itemType);
|
|
|
+ }
|
|
|
+
|
|
|
+ // INF_SEQ 조건 추가 (값이 있을 때만)
|
|
|
+ if (!empty($infSeq)) {
|
|
|
+ $builder->where('I.CONTACT_INF', $infSeq);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 날짜 범위 검색 (latest_reg_date 기준)
|
|
|
+ if (!empty($startDate)) {
|
|
|
+ $builder->where('O.latest_reg_date >=', $startDate . ' 00:00:00');
|
|
|
+ }
|
|
|
+ if (!empty($endDate)) {
|
|
|
+ $builder->where('O.latest_reg_date <=', $endDate . ' 23:59:59');
|
|
|
+ }
|
|
|
+
|
|
|
+ $builder->orderBy('I.UDPDATE', 'DESC');
|
|
|
+
|
|
|
+ // 조회
|
|
|
+ $lists = $builder->get()->getResultArray();
|
|
|
+
|
|
|
+ return $this->respond($lists, 200);
|
|
|
+ }
|
|
|
+
|
|
|
+ //배송중 검색
|
|
|
+ public function shippingSearch()
|
|
|
+ {
|
|
|
+ $db = \Config\Database::connect();
|
|
|
+ $request = $this->request->getJSON(true);
|
|
|
+
|
|
|
+ $memberType = isset($request['MEMBER_TYPE']) ? $request['MEMBER_TYPE'] : null;
|
|
|
+ $companyNumber = isset($request['COMPANY_NUMBER']) ? $request['COMPANY_NUMBER'] : null;
|
|
|
+ $infSeq = isset($request['INF_SEQ']) ? $request['INF_SEQ'] : null;
|
|
|
+ $itemType = isset($request['TYPE']) ? $request['TYPE'] : null;
|
|
|
+ $filter = isset($request['filter']) ? $request['filter'] : null;
|
|
|
+ $keyword = isset($request['keyword']) ? $request['keyword'] : null;
|
|
|
+ $startDate = isset($request['startDate']) ? $request['startDate'] : null;
|
|
|
+ $endDate = isset($request['endDate']) ? $request['endDate'] : null;
|
|
|
+
|
|
|
+ $builder = $db->table('ITEM_ORDER_LIST IOL')
|
|
|
+ ->select('IOL.*, IL.NAME as ITEM_NAME, IL.PRICE1, IL.PRICE2')
|
|
|
+ ->join('ITEM_LIST IL', 'IOL.ITEM_SEQ = IL.SEQ', 'inner')
|
|
|
+ ->where('IOL.DELI_COMP !=', '')
|
|
|
+ ->where('IOL.DELI_NUMB !=', '')
|
|
|
+ ->where('IOL.DELI_COMP IS NOT NULL')
|
|
|
+ ->where('IOL.DELI_NUMB IS NOT NULL');
|
|
|
+
|
|
|
+ // DELIVERY_STATUS 컬럼이 존재하는지 확인하고 조건 추가
|
|
|
+ $columns = $db->getFieldNames('ITEM_ORDER_LIST');
|
|
|
+ if (in_array('DELIVERY_STATUS', $columns)) {
|
|
|
+ $builder->where('IOL.DELIVERY_STATUS', 'SHIPPING');
|
|
|
+ } else {
|
|
|
+ // DELIVERY_STATUS 컬럼이 없으면 배송업체와 송장번호가 있는 것을 배송중으로 간주
|
|
|
+ // 단, 배송완료된 것은 제외 (DELIVERED_DATE가 없는 것만)
|
|
|
+ if (in_array('DELIVERED_DATE', $columns)) {
|
|
|
+ $builder->where('IOL.DELIVERED_DATE IS NULL');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 아이템 타입 필터링
|
|
|
+ if (!empty($itemType)) {
|
|
|
+ $builder->where('IL.TYPE', $itemType);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 검색 조건 추가
|
|
|
+ if (!empty($keyword)) {
|
|
|
+ if ($filter === 'name') {
|
|
|
+ $builder->like('IL.NAME', $keyword);
|
|
|
+ } elseif ($filter === 'buyer') {
|
|
|
+ $builder->like('IOL.BUYER_NAME', $keyword);
|
|
|
+ } else {
|
|
|
+ // 전체 검색
|
|
|
+ $builder->groupStart()
|
|
|
+ ->like('IL.NAME', $keyword)
|
|
|
+ ->orLike('IOL.BUYER_NAME', $keyword)
|
|
|
+ ->groupEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 날짜 범위 검색
|
|
|
+ if (!empty($startDate)) {
|
|
|
+ $builder->where('DATE(IOL.SHIPPING_DATE) >=', $startDate);
|
|
|
+ }
|
|
|
+ if (!empty($endDate)) {
|
|
|
+ $builder->where('DATE(IOL.SHIPPING_DATE) <=', $endDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 사용자 타입에 따른 필터링
|
|
|
+ if ($memberType === 'VENDOR' && !empty($companyNumber)) {
|
|
|
+ $builder->where('IL.COMPANY_NUMBER', $companyNumber);
|
|
|
+ } elseif ($memberType === 'INFLUENCER' && !empty($infSeq)) {
|
|
|
+ $builder->where('IOL.INF_SEQ', $infSeq);
|
|
|
+ }
|
|
|
+
|
|
|
+ $builder->orderBy('IOL.REG_DATE', 'DESC');
|
|
|
+ $lists = $builder->get()->getResultArray();
|
|
|
+
|
|
|
+ return $this->respond($lists, 200);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//구매자 리스트
|
|
|
public function delilist()
|
|
|
@@ -91,7 +276,7 @@ class Deli extends ResourceController
|
|
|
// 배송정보가 등록되지 않은 주문만 표시 (송장번호 등록용)
|
|
|
// 배송업체와 송장번호가 모두 비어있는 경우만 포함
|
|
|
$builder->where('(I.DELI_COMP IS NULL OR I.DELI_COMP = "")')
|
|
|
- ->where('(I.DELI_NUMB IS NULL OR I.DELI_NUMB = "")');
|
|
|
+ ->where('(I.DELI_NUMB IS NULL OR I.DELI_NUMB = "")');
|
|
|
|
|
|
// 주문일 기준으로 정렬
|
|
|
$builder->orderBy('I.ORDER_DATE', 'DESC');
|
|
|
@@ -110,7 +295,6 @@ class Deli extends ResourceController
|
|
|
$itemSeq = isset($request['item_seq']) ? $request['item_seq'] : null;
|
|
|
$infSeq = isset($request['inf_seq']) ? $request['inf_seq'] : null;
|
|
|
$deliveryList = $request['deliveryList'] ?? [];
|
|
|
- $useOrderDateMatching = isset($request['useOrderDateMatching']) ? $request['useOrderDateMatching'] : false;
|
|
|
|
|
|
// 🔍 먼저 전체 유효성 검사
|
|
|
foreach ($deliveryList as $index => $delivery) {
|
|
|
@@ -122,125 +306,32 @@ class Deli extends ResourceController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $db->transBegin();
|
|
|
- $insertCount = 0;
|
|
|
- $updateCount = 0;
|
|
|
-
|
|
|
- try {
|
|
|
- if ($useOrderDateMatching) {
|
|
|
- // 주문일 기준 매칭 방식 (신규 로직)
|
|
|
- foreach ($deliveryList as $delivery) {
|
|
|
- $orderDate = date('Y-m-d', strtotime($delivery['orderDate']));
|
|
|
-
|
|
|
- // 기존 데이터 확인 (구매자명, 연락처, 주문일로 매칭)
|
|
|
- $existingOrder = $db->table('ITEM_ORDER_LIST')
|
|
|
- ->where('ITEM_SEQ', $itemSeq)
|
|
|
- ->where('INF_SEQ', $infSeq)
|
|
|
- ->where('BUYER_NAME', $delivery['buyerName'])
|
|
|
- ->where('PHONE', $delivery['phone'])
|
|
|
- ->where('DATE(ORDER_DATE)', $orderDate)
|
|
|
- ->get()
|
|
|
- ->getRowArray();
|
|
|
-
|
|
|
- $data = [
|
|
|
- 'ITEM_SEQ' => $itemSeq,
|
|
|
- 'INF_SEQ' => $infSeq,
|
|
|
- 'BUYER_NAME' => $delivery['buyerName'],
|
|
|
- 'ADDRESS' => $delivery['address'],
|
|
|
- 'PHONE' => $delivery['phone'],
|
|
|
- 'EMAIL' => $delivery['email'],
|
|
|
- 'QTY' => $delivery['qty'],
|
|
|
- 'TOTAL' => $delivery['total'],
|
|
|
- 'DELI_COMP' => $delivery['deliComp'] ?? '',
|
|
|
- 'DELI_NUMB' => $delivery['deliNumb'] ?? '',
|
|
|
- 'ORDER_DATE' => date('Y-m-d H:i:s', strtotime($delivery['orderDate'])),
|
|
|
- 'REG_DATE' => date('Y-m-d'),
|
|
|
- ];
|
|
|
-
|
|
|
- // DELIVERY_STATUS 컬럼이 있으면 상태 설정
|
|
|
- $columns = $db->getFieldNames('ITEM_ORDER_LIST');
|
|
|
- if (in_array('DELIVERY_STATUS', $columns)) {
|
|
|
- // 배송업체와 송장번호가 모두 있으면 SHIPPING, 없으면 PENDING
|
|
|
- if (!empty($delivery['deliComp']) && !empty($delivery['deliNumb'])) {
|
|
|
- $data['DELIVERY_STATUS'] = 'SHIPPING';
|
|
|
- if (in_array('SHIPPING_DATE', $columns)) {
|
|
|
- $data['SHIPPING_DATE'] = date('Y-m-d H:i:s');
|
|
|
- }
|
|
|
- } else {
|
|
|
- $data['DELIVERY_STATUS'] = 'PENDING';
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ($existingOrder) {
|
|
|
- // 기존 주문 업데이트
|
|
|
- $db->table('ITEM_ORDER_LIST')
|
|
|
- ->where('SEQ', $existingOrder['SEQ'])
|
|
|
- ->update($data);
|
|
|
- $updateCount++;
|
|
|
- } else {
|
|
|
- // 신규 주문 삽입
|
|
|
- $db->table('ITEM_ORDER_LIST')->insert($data);
|
|
|
- $insertCount++;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 기존 방식 (전체 삭제 후 재등록)
|
|
|
- $db->table('ITEM_ORDER_LIST')
|
|
|
- ->where('ITEM_SEQ', $itemSeq)
|
|
|
- ->where('INF_SEQ', $infSeq)
|
|
|
- ->delete();
|
|
|
-
|
|
|
- foreach ($deliveryList as $delivery) {
|
|
|
- $data = [
|
|
|
- 'ITEM_SEQ' => $itemSeq,
|
|
|
- 'INF_SEQ' => $infSeq,
|
|
|
- 'BUYER_NAME' => $delivery['buyerName'],
|
|
|
- 'ADDRESS' => $delivery['address'],
|
|
|
- 'PHONE' => $delivery['phone'],
|
|
|
- 'EMAIL' => $delivery['email'],
|
|
|
- 'QTY' => $delivery['qty'],
|
|
|
- 'TOTAL' => $delivery['total'],
|
|
|
- 'DELI_COMP' => $delivery['deliComp'] ?? '',
|
|
|
- 'DELI_NUMB' => $delivery['deliNumb'] ?? '',
|
|
|
- 'ORDER_DATE' => date('Y-m-d H:i:s', strtotime($delivery['orderDate'])),
|
|
|
- 'REG_DATE' => date('Y-m-d'),
|
|
|
- ];
|
|
|
-
|
|
|
- // DELIVERY_STATUS 컬럼이 있으면 상태 설정
|
|
|
- $columns = $db->getFieldNames('ITEM_ORDER_LIST');
|
|
|
- if (in_array('DELIVERY_STATUS', $columns)) {
|
|
|
- // 배송업체와 송장번호가 모두 있으면 SHIPPING, 없으면 PENDING
|
|
|
- if (!empty($delivery['deliComp']) && !empty($delivery['deliNumb'])) {
|
|
|
- $data['DELIVERY_STATUS'] = 'SHIPPING';
|
|
|
- if (in_array('SHIPPING_DATE', $columns)) {
|
|
|
- $data['SHIPPING_DATE'] = date('Y-m-d H:i:s');
|
|
|
- }
|
|
|
- } else {
|
|
|
- $data['DELIVERY_STATUS'] = 'PENDING';
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $db->table('ITEM_ORDER_LIST')->insert($data);
|
|
|
- $insertCount++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $db->transCommit();
|
|
|
-
|
|
|
- if ($useOrderDateMatching) {
|
|
|
- return $this->respond([
|
|
|
- 'message' => '배송 데이터가 성공적으로 저장되었습니다.',
|
|
|
- 'insert_count' => $insertCount,
|
|
|
- 'update_count' => $updateCount
|
|
|
- ], 200);
|
|
|
- } else {
|
|
|
- return $this->respond(['message' => '배송 데이터가 성공적으로 저장되었습니다.'], 200);
|
|
|
- }
|
|
|
-
|
|
|
- } catch (\Exception $e) {
|
|
|
- $db->transRollback();
|
|
|
- return $this->fail('배송 데이터 저장 중 오류가 발생했습니다: ' . $e->getMessage(), 500);
|
|
|
- }
|
|
|
+ // ✅ 유효성 통과 후 삭제 + 삽입
|
|
|
+ $db->table('ITEM_ORDER_LIST')
|
|
|
+ ->where('ITEM_SEQ', $itemSeq)
|
|
|
+ ->where('INF_SEQ', $infSeq)
|
|
|
+ ->delete();
|
|
|
+
|
|
|
+ foreach ($deliveryList as $delivery) {
|
|
|
+ $data = [
|
|
|
+ 'ITEM_SEQ' => $itemSeq,
|
|
|
+ 'INF_SEQ' => $infSeq,
|
|
|
+ 'BUYER_NAME' => $delivery['buyerName'],
|
|
|
+ 'ADDRESS' => $delivery['address'],
|
|
|
+ 'PHONE' => $delivery['phone'],
|
|
|
+ 'EMAIL' => $delivery['email'],
|
|
|
+ 'QTY' => $delivery['qty'],
|
|
|
+ 'TOTAL' => $delivery['total'],
|
|
|
+ 'DELI_COMP' => $delivery['deliComp'] ?? '',
|
|
|
+ 'DELI_NUMB' => $delivery['deliNumb'] ?? '',
|
|
|
+ 'ORDER_DATE' => date('Y-m-d H:i:s', strtotime($delivery['orderDate'])),
|
|
|
+ 'REG_DATE' => date('Y-m-d'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $db->table('ITEM_ORDER_LIST')->insert($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->respond(['message' => '배송 데이터가 성공적으로 저장되었습니다.'], 200);
|
|
|
}
|
|
|
|
|
|
//벤더사용 배송정보 업데이트
|
|
|
@@ -259,22 +350,14 @@ class Deli extends ResourceController
|
|
|
$db->transBegin();
|
|
|
$updatedCount = 0;
|
|
|
$errors = [];
|
|
|
- $debugLogs = []; // 디버깅 로그 수집용
|
|
|
|
|
|
try {
|
|
|
- log_message('info', '벤더 배송정보 업데이트 요청: ' . json_encode($request));
|
|
|
- $debugLogs[] = '벤더 배송정보 업데이트 요청: ' . json_encode($request);
|
|
|
-
|
|
|
foreach ($deliveryUpdates as $update) {
|
|
|
$buyerName = $update['buyerName'] ?? '';
|
|
|
$phone = $update['phone'] ?? '';
|
|
|
$deliComp = $update['deliComp'] ?? '';
|
|
|
$deliNumb = $update['deliNumb'] ?? '';
|
|
|
|
|
|
- $logMessage = "배송정보 업데이트 시도: {$buyerName}({$phone}) - 배송업체: {$deliComp}, 송장번호: {$deliNumb}";
|
|
|
- log_message('info', $logMessage);
|
|
|
- $debugLogs[] = $logMessage;
|
|
|
-
|
|
|
if (!$buyerName || !$phone) {
|
|
|
$errors[] = "구매자명과 연락처는 필수입니다.";
|
|
|
continue;
|
|
|
@@ -286,62 +369,21 @@ class Deli extends ResourceController
|
|
|
'DELI_NUMB' => $deliNumb
|
|
|
];
|
|
|
|
|
|
- // 배송업체와 송장번호가 모두 있을 때만 DELIVERY_STATUS를 SHIPPING으로 변경
|
|
|
+ // DELIVERY_STATUS 컬럼이 존재하는지 확인하고 추가
|
|
|
$columns = $db->getFieldNames('ITEM_ORDER_LIST');
|
|
|
if (in_array('DELIVERY_STATUS', $columns)) {
|
|
|
- if (!empty($deliComp) && !empty($deliNumb)) {
|
|
|
- $updateData['DELIVERY_STATUS'] = 'SHIPPING';
|
|
|
-
|
|
|
- // 배송 시작일도 함께 업데이트
|
|
|
- if (in_array('SHIPPING_DATE', $columns)) {
|
|
|
- $updateData['SHIPPING_DATE'] = date('Y-m-d H:i:s');
|
|
|
- }
|
|
|
- }
|
|
|
+ $updateData['DELIVERY_STATUS'] = 'SHIPPING';
|
|
|
+ }
|
|
|
+ if (in_array('SHIPPING_DATE', $columns)) {
|
|
|
+ $updateData['SHIPPING_DATE'] = date('Y-m-d H:i:s');
|
|
|
}
|
|
|
|
|
|
- // 먼저 해당 조건의 데이터가 존재하는지 확인
|
|
|
- $existingOrder = $db->table('ITEM_ORDER_LIST')
|
|
|
+ // 구매자명과 연락처로 해당 주문 찾기
|
|
|
+ $result = $db->table('ITEM_ORDER_LIST')
|
|
|
->where('ITEM_SEQ', $itemSeq)
|
|
|
->where('BUYER_NAME', $buyerName)
|
|
|
->where('PHONE', $phone)
|
|
|
- ->get()
|
|
|
- ->getRowArray();
|
|
|
-
|
|
|
- $conditionLog = '업데이트 조건: ITEM_SEQ=' . $itemSeq . ', BUYER_NAME=' . $buyerName . ', PHONE=' . $phone;
|
|
|
- log_message('info', $conditionLog);
|
|
|
- $debugLogs[] = $conditionLog;
|
|
|
-
|
|
|
- $existsLog = '기존 주문 존재 여부: ' . ($existingOrder ? 'YES' : 'NO');
|
|
|
- log_message('info', $existsLog);
|
|
|
- $debugLogs[] = $existsLog;
|
|
|
-
|
|
|
- if ($existingOrder) {
|
|
|
- $existingLog = '기존 주문 데이터: ' . json_encode($existingOrder);
|
|
|
- log_message('info', $existingLog);
|
|
|
- $debugLogs[] = $existingLog;
|
|
|
- }
|
|
|
-
|
|
|
- $updateLog = '업데이트 데이터: ' . json_encode($updateData);
|
|
|
- log_message('info', $updateLog);
|
|
|
- $debugLogs[] = $updateLog;
|
|
|
-
|
|
|
- // SQL 쿼리 로깅을 위해 쿼리 빌더 분리
|
|
|
- $builder = $db->table('ITEM_ORDER_LIST')
|
|
|
- ->where('ITEM_SEQ', $itemSeq)
|
|
|
- ->where('BUYER_NAME', $buyerName)
|
|
|
- ->where('PHONE', $phone);
|
|
|
-
|
|
|
- // 실행될 SQL 쿼리 로그
|
|
|
- // $sql = $builder->getCompiledUpdate($updateData);
|
|
|
- // $sqlLog = '실행될 SQL 쿼리: ' . $sql;
|
|
|
- // log_message('info', $sqlLog);
|
|
|
- // $debugLogs[] = $sqlLog;
|
|
|
-
|
|
|
- $result = $builder->update($updateData);
|
|
|
-
|
|
|
- $resultLog = '업데이트 결과: ' . ($result ? 'SUCCESS' : 'FAILED') . ' (affected rows: ' . $result . ')';
|
|
|
- log_message('info', $resultLog);
|
|
|
- $debugLogs[] = $resultLog;
|
|
|
+ ->update($updateData);
|
|
|
|
|
|
if ($result) {
|
|
|
$updatedCount++;
|
|
|
@@ -355,25 +397,16 @@ class Deli extends ResourceController
|
|
|
return $this->respond([
|
|
|
'message' => "배송정보가 성공적으로 업데이트되었습니다.",
|
|
|
'updated_count' => $updatedCount,
|
|
|
- 'errors' => $errors,
|
|
|
- 'debug_logs' => $debugLogs
|
|
|
+ 'errors' => $errors
|
|
|
], 200);
|
|
|
} else {
|
|
|
$db->transRollback();
|
|
|
- return $this->fail([
|
|
|
- 'message' => '업데이트할 수 있는 데이터가 없습니다.',
|
|
|
- 'debug_logs' => $debugLogs,
|
|
|
- 'errors' => $errors
|
|
|
- ], 400);
|
|
|
+ return $this->fail('업데이트할 수 있는 데이터가 없습니다.', 400);
|
|
|
}
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
$db->transRollback();
|
|
|
- $debugLogs[] = 'Exception: ' . $e->getMessage();
|
|
|
- return $this->fail([
|
|
|
- 'message' => '배송정보 업데이트 중 오류가 발생했습니다: ' . $e->getMessage(),
|
|
|
- 'debug_logs' => $debugLogs
|
|
|
- ], 500);
|
|
|
+ return $this->fail('배송정보 업데이트 중 오류가 발생했습니다: ' . $e->getMessage(), 500);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -420,82 +453,47 @@ class Deli extends ResourceController
|
|
|
{
|
|
|
$db = \Config\Database::connect();
|
|
|
$request = $this->request->getJSON(true);
|
|
|
-
|
|
|
+
|
|
|
$memberType = isset($request['MEMBER_TYPE']) ? $request['MEMBER_TYPE'] : null;
|
|
|
$companyNumber = isset($request['COMPANY_NUMBER']) ? $request['COMPANY_NUMBER'] : null;
|
|
|
$infSeq = isset($request['INF_SEQ']) ? $request['INF_SEQ'] : null;
|
|
|
-
|
|
|
- // 디버깅 로그
|
|
|
- log_message('info', '배송중 리스트 조회 파라미터: ' . json_encode($request));
|
|
|
+ $itemType = isset($request['TYPE']) ? $request['TYPE'] : null;
|
|
|
|
|
|
$builder = $db->table('ITEM_ORDER_LIST IOL')
|
|
|
- ->select('IOL.*, IL.NAME as ITEM_NAME, IL.PRICE1, IL.PRICE2, U.NICK_NAME')
|
|
|
+ ->select('IOL.*, IL.NAME as ITEM_NAME, IL.PRICE1, IL.PRICE2')
|
|
|
->join('ITEM_LIST IL', 'IOL.ITEM_SEQ = IL.SEQ', 'inner')
|
|
|
- ->join('USER_LIST U', 'IOL.INF_SEQ = U.SEQ', 'left');
|
|
|
+ ->where('IOL.DELI_COMP !=', '')
|
|
|
+ ->where('IOL.DELI_NUMB !=', '')
|
|
|
+ ->where('IOL.DELI_COMP IS NOT NULL')
|
|
|
+ ->where('IOL.DELI_NUMB IS NOT NULL');
|
|
|
|
|
|
// DELIVERY_STATUS 컬럼이 존재하는지 확인하고 조건 추가
|
|
|
$columns = $db->getFieldNames('ITEM_ORDER_LIST');
|
|
|
- log_message('info', 'ITEM_ORDER_LIST 컬럼: ' . json_encode($columns));
|
|
|
-
|
|
|
if (in_array('DELIVERY_STATUS', $columns)) {
|
|
|
- // DELIVERY_STATUS 컬럼이 있는 경우 - 배송업체와 송장번호가 있으면서 SHIPPING 상태인 것
|
|
|
- $builder->where('IOL.DELI_COMP !=', '')
|
|
|
- ->where('IOL.DELI_NUMB !=', '')
|
|
|
- ->where('IOL.DELI_COMP IS NOT NULL')
|
|
|
- ->where('IOL.DELI_NUMB IS NOT NULL')
|
|
|
- ->where('IOL.DELIVERY_STATUS', 'SHIPPING');
|
|
|
- log_message('info', '배송중 조건: 배송정보 있고 DELIVERY_STATUS = SHIPPING');
|
|
|
+ $builder->where('IOL.DELIVERY_STATUS', 'SHIPPING');
|
|
|
} else {
|
|
|
// DELIVERY_STATUS 컬럼이 없으면 배송업체와 송장번호가 있는 것을 배송중으로 간주
|
|
|
- $builder->where('IOL.DELI_COMP !=', '')
|
|
|
- ->where('IOL.DELI_NUMB !=', '')
|
|
|
- ->where('IOL.DELI_COMP IS NOT NULL')
|
|
|
- ->where('IOL.DELI_NUMB IS NOT NULL');
|
|
|
-
|
|
|
- // 배송완료된 것은 제외 (DELIVERED_DATE가 없는 것만)
|
|
|
+ // 단, 배송완료된 것은 제외 (DELIVERED_DATE가 없는 것만)
|
|
|
if (in_array('DELIVERED_DATE', $columns)) {
|
|
|
$builder->where('IOL.DELIVERED_DATE IS NULL');
|
|
|
}
|
|
|
- log_message('info', '배송중 조건: 배송업체+송장번호 있고 배송완료일 없음');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 아이템 타입 필터링
|
|
|
+ if (!empty($itemType)) {
|
|
|
+ $builder->where('IL.TYPE', $itemType);
|
|
|
}
|
|
|
|
|
|
// 사용자 타입에 따른 필터링
|
|
|
if ($memberType === 'VENDOR' && !empty($companyNumber)) {
|
|
|
$builder->where('IL.COMPANY_NUMBER', $companyNumber);
|
|
|
- log_message('info', '벤더 필터링: COMPANY_NUMBER = ' . $companyNumber);
|
|
|
} elseif ($memberType === 'INFLUENCER' && !empty($infSeq)) {
|
|
|
$builder->where('IOL.INF_SEQ', $infSeq);
|
|
|
- log_message('info', '인플루언서 필터링: INF_SEQ = ' . $infSeq);
|
|
|
}
|
|
|
|
|
|
$builder->orderBy('IOL.REG_DATE', 'DESC');
|
|
|
-
|
|
|
- // 실행된 쿼리 로그
|
|
|
- $query = $builder->getCompiledSelect(false);
|
|
|
- log_message('info', '배송중 리스트 쿼리: ' . $query);
|
|
|
-
|
|
|
$lists = $builder->get()->getResultArray();
|
|
|
- log_message('info', '배송중 리스트 결과 개수: ' . count($lists));
|
|
|
-
|
|
|
- // 첫 번째 결과 로그
|
|
|
- if (!empty($lists)) {
|
|
|
- log_message('info', '첫 번째 배송중 데이터: ' . json_encode($lists[0]));
|
|
|
- }
|
|
|
|
|
|
- // 디버깅을 위해 조건 없이 전체 데이터도 확인
|
|
|
- $allDataBuilder = $db->table('ITEM_ORDER_LIST IOL')
|
|
|
- ->select('IOL.*, IL.NAME as ITEM_NAME')
|
|
|
- ->join('ITEM_LIST IL', 'IOL.ITEM_SEQ = IL.SEQ', 'inner');
|
|
|
-
|
|
|
- if ($memberType === 'VENDOR' && !empty($companyNumber)) {
|
|
|
- $allDataBuilder->where('IL.COMPANY_NUMBER', $companyNumber);
|
|
|
- } elseif ($memberType === 'INFLUENCER' && !empty($infSeq)) {
|
|
|
- $allDataBuilder->where('IOL.INF_SEQ', $infSeq);
|
|
|
- }
|
|
|
-
|
|
|
- $allDataBuilder->orderBy('IOL.REG_DATE', 'DESC')->limit(5);
|
|
|
- $allData = $allDataBuilder->get()->getResultArray();
|
|
|
- log_message('info', '전체 주문 데이터 (최근 5건): ' . json_encode($allData));
|
|
|
|
|
|
return $this->respond($lists, 200);
|
|
|
}
|
|
|
@@ -505,15 +503,15 @@ class Deli extends ResourceController
|
|
|
{
|
|
|
$db = \Config\Database::connect();
|
|
|
$request = $this->request->getJSON(true);
|
|
|
-
|
|
|
+
|
|
|
$memberType = isset($request['MEMBER_TYPE']) ? $request['MEMBER_TYPE'] : null;
|
|
|
$companyNumber = isset($request['COMPANY_NUMBER']) ? $request['COMPANY_NUMBER'] : null;
|
|
|
$infSeq = isset($request['INF_SEQ']) ? $request['INF_SEQ'] : null;
|
|
|
+ $itemType = isset($request['TYPE']) ? $request['TYPE'] : null;
|
|
|
|
|
|
$builder = $db->table('ITEM_ORDER_LIST IOL')
|
|
|
- ->select('IOL.*, IL.NAME as ITEM_NAME, IL.PRICE1, IL.PRICE2, U.NICK_NAME')
|
|
|
- ->join('ITEM_LIST IL', 'IOL.ITEM_SEQ = IL.SEQ', 'inner')
|
|
|
- ->join('USER_LIST U', 'IOL.INF_SEQ = U.SEQ', 'left');
|
|
|
+ ->select('IOL.*, IL.NAME as ITEM_NAME, IL.PRICE1, IL.PRICE2')
|
|
|
+ ->join('ITEM_LIST IL', 'IOL.ITEM_SEQ = IL.SEQ', 'inner');
|
|
|
|
|
|
// DELIVERY_STATUS 컬럼이 존재하는지 확인하고 조건 추가
|
|
|
$columns = $db->getFieldNames('ITEM_ORDER_LIST');
|
|
|
@@ -522,9 +520,14 @@ class Deli extends ResourceController
|
|
|
} else {
|
|
|
// DELIVERY_STATUS 컬럼이 없으면 배송업체와 송장번호가 있는 것을 배송완료로 간주
|
|
|
$builder->where('IOL.DELI_COMP !=', '')
|
|
|
- ->where('IOL.DELI_NUMB !=', '')
|
|
|
- ->where('IOL.DELI_COMP IS NOT NULL')
|
|
|
- ->where('IOL.DELI_NUMB IS NOT NULL');
|
|
|
+ ->where('IOL.DELI_NUMB !=', '')
|
|
|
+ ->where('IOL.DELI_COMP IS NOT NULL')
|
|
|
+ ->where('IOL.DELI_NUMB IS NOT NULL');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 아이템 타입 필터링
|
|
|
+ if (!empty($itemType)) {
|
|
|
+ $builder->where('IL.TYPE', $itemType);
|
|
|
}
|
|
|
|
|
|
// 정산완료되지 않은 주문만 표시 (배송완료 페이지용)
|
|
|
@@ -545,7 +548,7 @@ class Deli extends ResourceController
|
|
|
} else {
|
|
|
$builder->orderBy('IOL.REG_DATE', 'DESC');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$lists = $builder->get()->getResultArray();
|
|
|
|
|
|
|
|
|
@@ -557,15 +560,15 @@ class Deli extends ResourceController
|
|
|
{
|
|
|
$db = \Config\Database::connect();
|
|
|
$request = $this->request->getJSON(true);
|
|
|
-
|
|
|
+
|
|
|
$orderIds = isset($request['order_ids']) ? $request['order_ids'] : [];
|
|
|
-
|
|
|
+
|
|
|
if (empty($orderIds)) {
|
|
|
return $this->fail('처리할 주문이 선택되지 않았습니다.', 400);
|
|
|
}
|
|
|
|
|
|
$db->transBegin();
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
foreach ($orderIds as $orderId) {
|
|
|
$db->table('ITEM_ORDER_LIST')
|
|
|
@@ -575,10 +578,10 @@ class Deli extends ResourceController
|
|
|
'DELIVERED_DATE' => date('Y-m-d H:i:s')
|
|
|
]);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$db->transCommit();
|
|
|
return $this->respond(['message' => '배송완료 처리되었습니다.'], 200);
|
|
|
-
|
|
|
+
|
|
|
} catch (\Exception $e) {
|
|
|
$db->transRollback();
|
|
|
return $this->fail('배송완료 처리 중 오류가 발생했습니다: ' . $e->getMessage(), 500);
|
|
|
@@ -590,15 +593,15 @@ class Deli extends ResourceController
|
|
|
{
|
|
|
$db = \Config\Database::connect();
|
|
|
$request = $this->request->getJSON(true);
|
|
|
-
|
|
|
+
|
|
|
$orderIds = isset($request['order_ids']) ? $request['order_ids'] : [];
|
|
|
-
|
|
|
+
|
|
|
if (empty($orderIds)) {
|
|
|
return $this->fail('처리할 주문이 선택되지 않았습니다.', 400);
|
|
|
}
|
|
|
|
|
|
$db->transBegin();
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
foreach ($orderIds as $orderId) {
|
|
|
$db->table('ITEM_ORDER_LIST')
|
|
|
@@ -608,10 +611,10 @@ class Deli extends ResourceController
|
|
|
'SETTLED_DATE' => date('Y-m-d H:i:s')
|
|
|
]);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$db->transCommit();
|
|
|
return $this->respond(['message' => '정산완료 처리되었습니다.'], 200);
|
|
|
-
|
|
|
+
|
|
|
} catch (\Exception $e) {
|
|
|
$db->transRollback();
|
|
|
return $this->fail('정산완료 처리 중 오류가 발생했습니다: ' . $e->getMessage(), 500);
|
|
|
@@ -623,16 +626,16 @@ class Deli extends ResourceController
|
|
|
{
|
|
|
$db = \Config\Database::connect();
|
|
|
$request = $this->request->getJSON(true);
|
|
|
-
|
|
|
+
|
|
|
$memberType = isset($request['MEMBER_TYPE']) ? $request['MEMBER_TYPE'] : null;
|
|
|
$companyNumber = isset($request['COMPANY_NUMBER']) ? $request['COMPANY_NUMBER'] : null;
|
|
|
$infSeq = isset($request['INF_SEQ']) ? $request['INF_SEQ'] : null;
|
|
|
$settlementStatus = isset($request['SETTLEMENT_STATUS']) ? $request['SETTLEMENT_STATUS'] : null;
|
|
|
|
|
|
$builder = $db->table('ITEM_ORDER_LIST IOL')
|
|
|
- ->select('IOL.*, IL.NAME as ITEM_NAME, IL.PRICE1, IL.PRICE2, U.NICK_NAME')
|
|
|
+ ->select('IOL.*, IL.NAME as ITEM_NAME, IL.PRICE1, IL.PRICE2, IL.TYPE as ITEM_TYPE, UL.NICK_NAME as INF_NICK_NAME')
|
|
|
->join('ITEM_LIST IL', 'IOL.ITEM_SEQ = IL.SEQ', 'inner')
|
|
|
- ->join('USER_LIST U', 'IOL.INF_SEQ = U.SEQ', 'left');
|
|
|
+ ->join('USER_LIST UL', 'IOL.INF_SEQ = UL.SEQ', 'left');
|
|
|
|
|
|
// DELIVERY_STATUS 컬럼이 존재하는지 확인하고 조건 추가
|
|
|
$columns = $db->getFieldNames('ITEM_ORDER_LIST');
|
|
|
@@ -641,9 +644,9 @@ class Deli extends ResourceController
|
|
|
} else {
|
|
|
// DELIVERY_STATUS 컬럼이 없으면 배송업체와 송장번호가 있는 것을 대상으로 함
|
|
|
$builder->where('IOL.DELI_COMP !=', '')
|
|
|
- ->where('IOL.DELI_NUMB !=', '')
|
|
|
- ->where('IOL.DELI_COMP IS NOT NULL')
|
|
|
- ->where('IOL.DELI_NUMB IS NOT NULL');
|
|
|
+ ->where('IOL.DELI_NUMB !=', '')
|
|
|
+ ->where('IOL.DELI_COMP IS NOT NULL')
|
|
|
+ ->where('IOL.DELI_NUMB IS NOT NULL');
|
|
|
}
|
|
|
|
|
|
// 정산 상태 필터링 (SETTLEMENT_STATUS 컬럼이 존재하는 경우만)
|
|
|
@@ -664,216 +667,4 @@ class Deli extends ResourceController
|
|
|
return $this->respond($lists, 200);
|
|
|
}
|
|
|
|
|
|
- // 벤더용 대기중 주문 목록 조회
|
|
|
- public function getPendingOrdersForVendor()
|
|
|
- {
|
|
|
- $db = \Config\Database::connect();
|
|
|
- $request = $this->request->getJSON(true);
|
|
|
-
|
|
|
- $memberType = isset($request['MEMBER_TYPE']) ? $request['MEMBER_TYPE'] : null;
|
|
|
- $companyNumber = isset($request['COMPANY_NUMBER']) ? $request['COMPANY_NUMBER'] : null;
|
|
|
-
|
|
|
- if ($memberType !== 'VENDOR' || empty($companyNumber)) {
|
|
|
- return $this->respond([], 200);
|
|
|
- }
|
|
|
-
|
|
|
- // 벤더의 제품에 대한 대기중 주문만 조회
|
|
|
- $builder = $db->table('ITEM_ORDER_LIST IOL')
|
|
|
- ->select('IOL.*, IL.NAME as ITEM_NAME, IL.COMPANY_NUMBER, U.NICK_NAME')
|
|
|
- ->join('ITEM_LIST IL', 'IOL.ITEM_SEQ = IL.SEQ', 'inner')
|
|
|
- ->join('USER_LIST U', 'IOL.INF_SEQ = U.SEQ', 'left')
|
|
|
- ->where('IL.COMPANY_NUMBER', $companyNumber);
|
|
|
-
|
|
|
- // DELIVERY_STATUS 컬럼이 존재하는지 확인하고 조건 추가
|
|
|
- $columns = $db->getFieldNames('ITEM_ORDER_LIST');
|
|
|
- if (in_array('DELIVERY_STATUS', $columns)) {
|
|
|
- // DELIVERY_STATUS가 PENDING이거나 NULL인 경우 (대기중)
|
|
|
- $builder->where('(IOL.DELIVERY_STATUS = "PENDING" OR IOL.DELIVERY_STATUS IS NULL)');
|
|
|
- } else {
|
|
|
- // DELIVERY_STATUS 컬럼이 없으면 기존 방식으로 배송정보로 판단
|
|
|
- $builder->where('(IOL.DELI_COMP IS NULL OR IOL.DELI_COMP = "")')
|
|
|
- ->where('(IOL.DELI_NUMB IS NULL OR IOL.DELI_NUMB = "")');
|
|
|
- }
|
|
|
-
|
|
|
- $builder->orderBy('IOL.REG_DATE', 'DESC');
|
|
|
-
|
|
|
- $lists = $builder->get()->getResultArray();
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 디버깅용 주문 데이터 조회
|
|
|
- public function debugOrderData()
|
|
|
- {
|
|
|
- $db = \Config\Database::connect();
|
|
|
- $request = $this->request->getJSON(true);
|
|
|
-
|
|
|
- $memberType = isset($request['MEMBER_TYPE']) ? $request['MEMBER_TYPE'] : null;
|
|
|
- $companyNumber = isset($request['COMPANY_NUMBER']) ? $request['COMPANY_NUMBER'] : null;
|
|
|
- $infSeq = isset($request['INF_SEQ']) ? $request['INF_SEQ'] : null;
|
|
|
-
|
|
|
- // 전체 주문 데이터 조회
|
|
|
- $builder = $db->table('ITEM_ORDER_LIST IOL')
|
|
|
- ->select('IOL.*, IL.NAME as ITEM_NAME, IL.COMPANY_NUMBER as ITEM_COMPANY')
|
|
|
- ->join('ITEM_LIST IL', 'IOL.ITEM_SEQ = IL.SEQ', 'inner');
|
|
|
-
|
|
|
- // 사용자 타입에 따른 필터링
|
|
|
- if ($memberType === 'VENDOR' && !empty($companyNumber)) {
|
|
|
- $builder->where('IL.COMPANY_NUMBER', $companyNumber);
|
|
|
- } elseif ($memberType === 'INFLUENCER' && !empty($infSeq)) {
|
|
|
- $builder->where('IOL.INF_SEQ', $infSeq);
|
|
|
- }
|
|
|
-
|
|
|
- $builder->orderBy('IOL.REG_DATE', 'DESC')
|
|
|
- ->limit(10); // 최근 10건만
|
|
|
-
|
|
|
- $orders = $builder->get()->getResultArray();
|
|
|
-
|
|
|
- // 컬럼 정보도 함께 반환
|
|
|
- $columns = $db->getFieldNames('ITEM_ORDER_LIST');
|
|
|
-
|
|
|
- return $this->respond([
|
|
|
- 'columns' => $columns,
|
|
|
- 'orders' => $orders,
|
|
|
- 'count' => count($orders),
|
|
|
- 'filter' => [
|
|
|
- 'memberType' => $memberType,
|
|
|
- 'companyNumber' => $companyNumber,
|
|
|
- 'infSeq' => $infSeq
|
|
|
- ]
|
|
|
- ], 200);
|
|
|
- }
|
|
|
-
|
|
|
- // 배송중 데이터 강제 조회 (디버깅용)
|
|
|
- public function getShippingListDebug()
|
|
|
- {
|
|
|
- $db = \Config\Database::connect();
|
|
|
- $request = $this->request->getJSON(true);
|
|
|
-
|
|
|
- $memberType = isset($request['MEMBER_TYPE']) ? $request['MEMBER_TYPE'] : null;
|
|
|
- $companyNumber = isset($request['COMPANY_NUMBER']) ? $request['COMPANY_NUMBER'] : null;
|
|
|
- $infSeq = isset($request['INF_SEQ']) ? $request['INF_SEQ'] : null;
|
|
|
-
|
|
|
- $builder = $db->table('ITEM_ORDER_LIST IOL')
|
|
|
- ->select('IOL.*, IL.NAME as ITEM_NAME, IL.PRICE1, IL.PRICE2, U.NICK_NAME')
|
|
|
- ->join('ITEM_LIST IL', 'IOL.ITEM_SEQ = IL.SEQ', 'inner')
|
|
|
- ->join('USER_LIST U', 'IOL.INF_SEQ = U.SEQ', 'left');
|
|
|
-
|
|
|
- // 사용자 타입에 따른 필터링만 적용 (배송 조건 제외)
|
|
|
- if ($memberType === 'VENDOR' && !empty($companyNumber)) {
|
|
|
- $builder->where('IL.COMPANY_NUMBER', $companyNumber);
|
|
|
- } elseif ($memberType === 'INFLUENCER' && !empty($infSeq)) {
|
|
|
- $builder->where('IOL.INF_SEQ', $infSeq);
|
|
|
- }
|
|
|
-
|
|
|
- $builder->orderBy('IOL.REG_DATE', 'DESC');
|
|
|
- $allData = $builder->get()->getResultArray();
|
|
|
-
|
|
|
- // 각 조건별로 분류
|
|
|
- $withDeliveryInfo = [];
|
|
|
- $withShippingStatus = [];
|
|
|
- $withBoth = [];
|
|
|
-
|
|
|
- $columns = $db->getFieldNames('ITEM_ORDER_LIST');
|
|
|
-
|
|
|
- foreach ($allData as $item) {
|
|
|
- $hasDeliveryInfo = !empty($item['DELI_COMP']) && !empty($item['DELI_NUMB']);
|
|
|
- $hasShippingStatus = isset($item['DELIVERY_STATUS']) && $item['DELIVERY_STATUS'] === 'SHIPPING';
|
|
|
-
|
|
|
- if ($hasDeliveryInfo) {
|
|
|
- $withDeliveryInfo[] = $item;
|
|
|
- }
|
|
|
-
|
|
|
- if ($hasShippingStatus) {
|
|
|
- $withShippingStatus[] = $item;
|
|
|
- }
|
|
|
-
|
|
|
- if ($hasDeliveryInfo && $hasShippingStatus) {
|
|
|
- $withBoth[] = $item;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return $this->respond([
|
|
|
- 'columns' => $columns,
|
|
|
- 'total_count' => count($allData),
|
|
|
- 'with_delivery_info' => [
|
|
|
- 'count' => count($withDeliveryInfo),
|
|
|
- 'data' => array_slice($withDeliveryInfo, 0, 3)
|
|
|
- ],
|
|
|
- 'with_shipping_status' => [
|
|
|
- 'count' => count($withShippingStatus),
|
|
|
- 'data' => array_slice($withShippingStatus, 0, 3)
|
|
|
- ],
|
|
|
- 'with_both_conditions' => [
|
|
|
- 'count' => count($withBoth),
|
|
|
- 'data' => array_slice($withBoth, 0, 3)
|
|
|
- ],
|
|
|
- 'sample_all_data' => array_slice($allData, 0, 3),
|
|
|
- 'filter' => [
|
|
|
- 'memberType' => $memberType,
|
|
|
- 'companyNumber' => $companyNumber,
|
|
|
- 'infSeq' => $infSeq
|
|
|
- ]
|
|
|
- ], 200);
|
|
|
- }
|
|
|
-
|
|
|
}
|