You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

111 lines
4.4 KiB

<?php
require_once("../../contract/conn.php");
if (!empty($_POST['id']) && !empty($_POST['postType']) && $_POST['postType'] == 'a') {
try {
$id = empty($_POST['id']) ? '' : $_POST['id'];
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
$amount = empty($_POST['amount']) ? '' : $_POST['amount'];
$pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day'];
$review_at = date("Y-m-d H:i:s");
$sql = "UPDATE bonus SET status = 2 ,bonus_actual='$amount',review_hr = '$user_id' ,review_at = '$review_at',pay_day ='$pay_day',update_id='$user_id',update_at='$review_at' WHERE id = $id";
$stmt = $conn->prepare($sql);
$stmt->execute();
header("HTTP/1.1 200 success!");
echo 'Success';
} catch (PDOException $e) {
header("HTTP/1.1 404 failed!");
echo $e->getMessage();
die('Error!:' . $e->getMessage());
}
}
// 獎金確認發放,並更新獎金 OR 實際發放時間
if (!empty($_POST['postType']) && $_POST['postType'] == 'b') {
try {
$id = empty($_POST['id']) ? '' : $_POST['id'];
$pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day'];
$bonus_actual = empty($_POST['bonus_actual']) ? '' : $_POST['bonus_actual'];
$note = empty($_POST['note']) ? '' : $_POST['note'];
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
$review_at = date("Y-m-d H:i:s");
if ($pay_day != '' && $bonus_actual != '') {
$sql = "UPDATE bonus SET status = 2,review_hr='$user_id',review_at='$review_at',bonus_actual='$bonus_actual',pay_day='$pay_day',note='$note' WHERE id = $id";
$stmt = $conn->prepare($sql);
$stmt->execute();
header("HTTP/1.1 200 success!");
} else {
header("HTTP/1.1 400");
echo '請填寫發放時間和實發獎金';
}
} catch (PDOException $e) {
header("HTTP/1.1 404 failed!");
echo $e->getMessage();
die('Error!:' . $e->getMessage());
}
}
// 獎金暫不發放
if (!empty($_POST['postType']) && $_POST['postType'] == 'c') {
// echo 'cccccc';
try {
$id = empty($_POST['id']) ? '' : $_POST['id'];
$pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day'];
$bonus_actual = empty($_POST['bonus_issue']) ? '' : $_POST['bonus_issue'];
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
$note = empty($_POST['note']) ? '' : $_POST['note'];
$review_at = date("Y-m-d H:i:s");
if ($note != '') {
$sql = "UPDATE bonus SET status = 4,review_hr='$user_id',review_at='$review_at',pay_day='$pay_day',note='$note' WHERE id = $id";
echo $sql;
$stmt = $conn->prepare($sql);
$stmt->execute();
header("HTTP/1.1 200 success!");
} else {
echo '請填寫備註!!';
header("HTTP/1.1 400!");
}
} catch (PDOException $e) {
header("HTTP/1.1 404 failed!");
echo $e->getMessage();
die('Error!:' . $e->getMessage());
}
}
if (!empty($_POST['postType']) && $_POST['postType'] == 'd') {
try {
$id = empty($_POST['id']) ? '' : $_POST['id'];
$review_at = date("Y-m-d H:i:s");
$user_id = empty($_POST['user_id']) ? '' : $_POST['user_id'];
$sql = "SELECT * FROM bonus WHERE id IN ($id)";
$stmt = $conn->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$conn->beginTransaction();
foreach ($results as $result) {
// echo '<pre>';
// print_r($result);
// echo '</pre>';
// exit();
$amount = $result['amount'];
$id = $result['id'];
$pay_day = $result['pay_day_due'];
$sql = "UPDATE bonus SET status = 5 ,bonus_actual='$amount',review_hr = '$user_id' ,review_at = '$review_at',pay_day ='$pay_day' WHERE id = $id";
$stmt = $conn->prepare($sql);
$stmt->execute();
}
$conn->commit();
header("HTTP/1.1 200 success!");
} catch (PDOException $e) {
$conn->rollBack();
header("HTTP/1.1 404 failed!");
echo $e->getMessage();
die('Error!:' . $e->getMessage());
}
// echo 'ddddd';
}