|
|
@@ -0,0 +1,113 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Controllers;
|
|
|
+
|
|
|
+use CodeIgniter\RESTful\ResourceController;
|
|
|
+
|
|
|
+class Deli extends ResourceController
|
|
|
+{
|
|
|
+ //구매자 리스트
|
|
|
+ public function delilist()
|
|
|
+ {
|
|
|
+ $db = \Config\Database::connect();
|
|
|
+ $request = $this->request->getJSON(true);
|
|
|
+ $itemSeq = isset($request['item_seq']) ? $request['item_seq'] : null;
|
|
|
+ $infSeq = isset($request['inf_seq']) ? $request['inf_seq'] : null;
|
|
|
+ // 쿼리 빌더
|
|
|
+ // 인플루언서 시퀀스가 들어올 경우 해당 정보만 노출, 들어오지 않으면 전체 노출
|
|
|
+ if($infSeq){
|
|
|
+ $builder = $db->table('ITEM_ORDER_LIST')->where('ITEM_SEQ', $itemSeq )->where('INF_SEQ', $infSeq);
|
|
|
+ } else {
|
|
|
+ $builder = $db->table('ITEM_ORDER_LIST')->where('ITEM_SEQ', $itemSeq );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 주문일 기준으로 정렬
|
|
|
+ $builder->orderBy('ORDER_DATE', 'DESC');
|
|
|
+ $lists = $builder->get()->getResultArray();
|
|
|
+
|
|
|
+ return $this->respond($lists, 200);
|
|
|
+ }
|
|
|
+
|
|
|
+ //구매자 등록
|
|
|
+ public function deliRegister()
|
|
|
+ {
|
|
|
+ $db = \Config\Database::connect();
|
|
|
+ $request = $this->request->getJSON(true);
|
|
|
+
|
|
|
+ $itemSeq = isset($request['item_seq']) ? $request['item_seq'] : null;
|
|
|
+ $infSeq = isset($request['inf_seq']) ? $request['inf_seq'] : null;
|
|
|
+ $deliveryList = $request['deliveryList'] ?? [];
|
|
|
+
|
|
|
+ $db->table('ITEM_ORDER_LIST')
|
|
|
+ ->where('ITEM_SEQ', $itemSeq)
|
|
|
+ ->where('INF_SEQ', $infSeq)
|
|
|
+ ->delete();
|
|
|
+
|
|
|
+ foreach ($deliveryList as $index => $delivery) {
|
|
|
+ $requiredFields = ['buyerName', 'address', 'phone', 'qty', 'total', 'orderDate'];
|
|
|
+ foreach ($requiredFields as $field) {
|
|
|
+ if (!isset($delivery[$field]) || $delivery[$field] === '') {
|
|
|
+ return $this->fail("deliveryList[$index] 항목의 '{$field}' 값이 누락되었습니다.", 400);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 삽입
|
|
|
+ $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'] ?? null,
|
|
|
+ 'DELI_NUMB' => $delivery['deliNumb'] ?? null,
|
|
|
+ '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);
|
|
|
+ }
|
|
|
+
|
|
|
+ //아이템 상세
|
|
|
+ public function itemDetail($seq)
|
|
|
+ {
|
|
|
+ // DB 객체 얻기
|
|
|
+ $db = \Config\Database::connect();
|
|
|
+
|
|
|
+ $builder = $db->table('ITEM_LIST');
|
|
|
+ $item = $builder->where('seq', $seq)->get()->getRowArray();
|
|
|
+
|
|
|
+ if($item){
|
|
|
+ return $this->respond($item, 200);
|
|
|
+ } else {
|
|
|
+ return $this->respond([
|
|
|
+ 'status' => 'fail',
|
|
|
+ 'message' => '유효하지 않은 seq입니다.'
|
|
|
+ ], 404);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //아이템 삭제
|
|
|
+ public function itemDelete($seq)
|
|
|
+ {
|
|
|
+ $db = \Config\Database::connect();
|
|
|
+ $db->transBegin();
|
|
|
+
|
|
|
+ //아이템 삭제
|
|
|
+ $deleted = $db->table('ITEM_LIST')
|
|
|
+ ->where('SEQ', $seq)
|
|
|
+ ->update(['DEL_YN' => 'Y']);
|
|
|
+
|
|
|
+ if ($db->transStatus() === false || !$deleted) {
|
|
|
+ $db->transRollback();
|
|
|
+ return $this->respond(['status' => 'fail', 'message' => '이벤트 삭제 중 오류가 발생했습니다.']);
|
|
|
+ }
|
|
|
+ $db->transCommit();
|
|
|
+ return $this->respond(['status' => 'success', 'message' => '이벤트가 삭제되었습니다.'], 200);
|
|
|
+ }
|
|
|
+}
|