commit
This commit is contained in:
209
kngil/bbs/adm_service.php
Normal file
209
kngil/bbs/adm_service.php
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
require_once __DIR__ . '/db_conn.php';
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
$action = $input['action'] ?? '';
|
||||
$member_id = $input['member_id'] ?? '';
|
||||
|
||||
if (!$action || !$member_id) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => '필수값 누락'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
/* =========================
|
||||
조회 (R)
|
||||
========================= */
|
||||
if ($action === 'list') {
|
||||
|
||||
$buy_date = $input['buy_date'] ?? '';
|
||||
if (!$buy_date) {
|
||||
throw new Exception('구매일 누락');
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT *
|
||||
FROM kngil.sp_buy_item_r(:member_id, :buy_date)
|
||||
");
|
||||
$stmt->execute([
|
||||
'member_id' => $member_id,
|
||||
'buy_date' => $buy_date
|
||||
]);
|
||||
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$i = 1;
|
||||
foreach ($rows as &$r) {
|
||||
$r['recid'] = $i++;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'records' => $rows
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
즉시 삭제 (D)
|
||||
========================= */
|
||||
if ($action === 'delete') {
|
||||
|
||||
$sq_no = $input['sq_no'] ?? null;
|
||||
if (!$sq_no) {
|
||||
throw new Exception('삭제 대상 누락');
|
||||
}
|
||||
|
||||
$pdo->prepare("
|
||||
SELECT kngil.sp_buy_item_d(
|
||||
:member_id,
|
||||
:sq_no
|
||||
)
|
||||
")->execute([
|
||||
'member_id' => $member_id,
|
||||
'sq_no' => $sq_no
|
||||
]);
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
저장 (C / U)
|
||||
========================= */
|
||||
if ($action === 'save') {
|
||||
|
||||
$buy_date = $input['buy_date'] ?? '';
|
||||
$items = $input['items'] ?? [];
|
||||
|
||||
if (!$buy_date) {
|
||||
throw new Exception('구매일 누락');
|
||||
}
|
||||
|
||||
$pdo->beginTransaction();
|
||||
|
||||
foreach ($items as $row) {
|
||||
|
||||
$end_dt = empty($row['end_dt']) ? null : $row['end_dt'];
|
||||
|
||||
// INSERT
|
||||
if (!empty($row['_new'])) {
|
||||
|
||||
$pdo->prepare("
|
||||
SELECT kngil.sp_buy_item_i(
|
||||
:member_id::character varying,
|
||||
:buy_dt::date,
|
||||
:itm_cd::character varying,
|
||||
:itm_qty::numeric,
|
||||
:itm_area::numeric,
|
||||
:add_area::numeric,
|
||||
(:itm_area + :add_area)::numeric,
|
||||
:itm_amt::numeric,
|
||||
:dis_rt::numeric,
|
||||
:buy_amt::numeric,
|
||||
:vat_amt::numeric,
|
||||
:sum_amt::numeric,
|
||||
:end_dt::date,
|
||||
:ok_yn::character varying,
|
||||
:rmks::character varying,
|
||||
:cid::character varying
|
||||
)
|
||||
")->execute([
|
||||
'member_id' => $member_id,
|
||||
'buy_dt' => $buy_date,
|
||||
'itm_cd' => $row['itm_cd'],
|
||||
'itm_qty' => $row['itm_qty'],
|
||||
'itm_area' => $row['itm_area'],
|
||||
'add_area' => $row['add_area'] ?? 0,
|
||||
'itm_amt' => $row['itm_amt'],
|
||||
'dis_rt' => $row['dis_rt'],
|
||||
'buy_amt' => $row['buy_amt'],
|
||||
'vat_amt' => $row['vat_amt'],
|
||||
'sum_amt' => $row['sum_amt'],
|
||||
'end_dt' => $end_dt,
|
||||
'ok_yn' => $row['ok_yn'],
|
||||
'rmks' => $row['rmks'] ?? '',
|
||||
'cid' => 'ADMIN'
|
||||
]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// UPDATE
|
||||
if (!empty($row['_existing']) && !empty($row['sq_no'])) {
|
||||
|
||||
$pdo->prepare("
|
||||
SELECT kngil.sp_buy_item_u(
|
||||
:member_id::character varying,
|
||||
:sq_no::integer,
|
||||
:buy_dt::date,
|
||||
:itm_cd::character varying,
|
||||
:itm_qty::numeric,
|
||||
:itm_area::numeric,
|
||||
:add_area::numeric,
|
||||
(:itm_area + :add_area)::numeric,
|
||||
:itm_amt::numeric,
|
||||
:dis_rt::numeric,
|
||||
:buy_amt::numeric,
|
||||
:vat_amt::numeric,
|
||||
:sum_amt::numeric,
|
||||
:end_dt::date,
|
||||
:ok_yn::character varying,
|
||||
:rmks::character varying,
|
||||
:mid::character varying
|
||||
)
|
||||
")->execute([
|
||||
'member_id' => $member_id,
|
||||
'sq_no' => $row['sq_no'],
|
||||
'buy_dt' => $buy_date,
|
||||
'itm_cd' => $row['itm_cd'],
|
||||
'itm_qty' => $row['itm_qty'],
|
||||
'itm_area' => $row['itm_area'],
|
||||
'add_area' => $row['add_area'] ?? 0,
|
||||
'itm_amt' => $row['itm_amt'],
|
||||
'dis_rt' => $row['dis_rt'],
|
||||
'buy_amt' => $row['buy_amt'],
|
||||
'vat_amt' => $row['vat_amt'],
|
||||
'sum_amt' => $row['sum_amt'],
|
||||
'end_dt' => $end_dt,
|
||||
'ok_yn' => $row['ok_yn'],
|
||||
'rmks' => $row['rmks'] ?? '',
|
||||
'mid' => 'ADMIN'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
throw new Exception('Invalid action');
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->rollBack();
|
||||
}
|
||||
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user