File: /www/wwwroot//www.linghdl.com/admin_user_edit.php
<?PHP
set_time_limit(0);
header('Content-Type: text/html; charset=UTF-8');
#加载系统配置文件 该文件只包含各种系统配置项
require "./include/config.h";
#加载公共函数 主要是一些工具函数
require "./include/functions.php";
#开启数据库连接
$db = tools::get_db();
$db_ = clone $db;
//获取活动ID
$nGameId = (int)$_REQUEST["game_id"];
$sAction = trim($_REQUEST["action"]);
if ( $sAction == "save" ) {
$aInfo = $_REQUEST["info"];
#判断活动ID
if ( (int)$aInfo["game_id"] <= 0 ) {
exit("failed:game_id");
}
#判断是否特定用户
if ( (int)$aInfo["type"] <= 0 ) {
$aInfo["item_id"] = 0;
$aInfo["item_name"] = "";
} else {
#获取指定奖品信息
$sSql = "SELECT * FROM gift_items WHERE game_id = ".$aInfo["game_id"]." AND item_id = ".$aInfo["item_id"];
$db->query( $sSql );
$row = $db->next_row();
$aInfo["item_name"] = $row["item_name"];
}
#判断是否新增
if ( $aInfo["auto_id"] <= 0 ) {
#判断手机号或抽奖码是否重复
//$sSql = "SELECT * FROM gift_draw_log WHERE game_id = ".$aInfo["game_id"]." AND ( mobile = '".$aInfo["mobile"]."' OR usercode = '".$aInfo["usercode"]."' ) ";
$sSql = "SELECT * FROM gift_draw_log WHERE game_id = ".$aInfo["game_id"]." AND usercode = '".$aInfo["usercode"]."' ";
$db->query( $sSql );
$row = $db->next_row();
if ( $row["auto_id"] > 0 ) {
exit("手機號或抽獎碼已存在。");
}
#新增用户信息
$sSql = "INSERT INTO gift_draw_log(game_id,mobile,usercode,item_id,item_name,type) VALUES('".$aInfo["game_id"]."','".$aInfo["mobile"]."','".$aInfo["usercode"]."','".$aInfo["item_id"]."','".$aInfo["item_name"]."','".$aInfo["type"]."')";
if ( $db->query($sSql) ) {
exit("success");
}
#修改用户信息
} else {
#判断用户是否已抽,已抽则不能修改
$sSql = "SELECT * FROM gift_draw_log WHERE game_id = ".$aInfo["game_id"]." AND auto_id = ".$aInfo["auto_id"];
$db->query( $sSql );
$row = $db->next_row();
if ( isset($row["draw_time"]) && $row["draw_time"] != "0000-00-00 00:00:00" ) {
exit("該用戶已參與抽獎,無法修改。");
}
$sSql = "UPDATE gift_draw_log SET mobile = '".$aInfo["mobile"]."',
usercode = '".$aInfo["usercode"]."',
item_id = '".$aInfo["item_id"]."',
item_name = '".$aInfo["item_name"]."',
type = '".$aInfo["type"]."'
WHERE game_id = ".$aInfo["game_id"]." AND auto_id = ".$aInfo["auto_id"];
if ( $db->query($sSql) ) {
exit("success");
}
}
exit("failed");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>獎品內容</title>
<style>
body {
margin:0px;text-align:center;
font-family:微软雅黑;font-size:25px;color:#000000;
}
input,select {
font-size:25px;
}
table, td{ border:1px solid #CCC; padding-top:4px; padding-bottom:4px;}
table{
border-collapse:collapse;
}
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 26px;
cursor: pointer;
}
.btn1 {
margin:5px;
padding: 10px 10px;
font-size: 25px;
font-weight:bold;
}
.btn2 {
margin:2px;
padding: 5px 10px 5px 10px;
font-size: 23px;
}
h2{line-height:30px; font-size:30px;}
a,a:hover{ text-decoration:none;}
pre{font-family:'微软雅黑'}
.box{width:100px; padding:10px 20px; background-color:#fff; margin:10px auto;}
.box a{padding-right:20px;}
</style>
<script src="js/jquery-3.5.1.min.js"></script>
<script type='text/javascript'>
$(document).ready(function(){
$("button#admin_user_save").click(function(data){
//console.log($("#admin_user_edit").serialize());
$.ajax({
type: "post",
url: "admin_user_edit.php?action=save",
data: $("#admin_user_edit").serialize(),
//dataType: "json",
success: function(data) {
if (data != "success")
{
alert(data);
} else {
alert("保存成功");
}
},
error: function(err) {
alert("保存失敗");
}
});
});
$("#user_type").change(function(data){
var user_type = $("#user_type option:selected").val();
if ( user_type == '1' )
{
$("#user_type_select").show();
} else {
$("#user_type_select").hide();
}
});
$("button#admin_game_add").click(function(data){
window.location.href = "./admin_game_edit.php";
});
$("button#admin_game_edit").click(function(data){
window.location.href = "./admin_game_edit.php?game_id=" + data.currentTarget.name;
});
$("button#admin_items").click(function(data){
window.location.href = "./admin_items.php?game_id=" + data.currentTarget.name;
});
$("button#admin_user").click(function(data){
window.location.href = "./admin_user.php?game_id=" + data.currentTarget.name;
});
$("button#back").click(function(data){
//history.go(-1);
//history.back(-1);
window.location.href = "./admin_user.php?game_id=" + data.currentTarget.name;;
});
});
</script>
</head>
<body>
<?PHP
//获取抽奖用户流水ID
$nAutoId = (int)$_REQUEST["auto_id"];
#获取 抽奖用户信息
$sSql = "SELECT * FROM gift_draw_log WHERE auto_id = ".$nAutoId;
$db->query( $sSql );
$aItemInfo = $db->next_row();
if ( $nGameId <= 0 ) {
$nGameId = $aItemInfo["game_id"];
}
#判断是否已抽,已抽则不能修改
if ( isset($aItemInfo["draw_time"]) && $aItemInfo["draw_time"]!="0000-00-00 00:00:00" ) {
exit("用戶已參與抽獎,無法修改。");
}
$sHtml = "<form id=admin_user_edit>";
$sHtml .= "<table align=center><tr><td colspan=6 style='font-size:30px;color:white;font-weight:bold;padding:10px;background-color:#4CAF50;'>抽獎用戶信息</td></tr>";
$sHtml .= "<tr style='font-size:25px;font-weight:bold;'><td width=120>手機號碼</td><td align=left> <input type=text name=info[mobile] value='".$aItemInfo[mobile]."'></td></tr>";
$sHtml .= "<tr style='font-size:25px;font-weight:bold;'><td width=100>抽獎碼</td><td align=left> <input type=text name=info[usercode] value='".$aItemInfo[usercode]."'></td></tr>";
$sHtml .= "<tr style='font-size:25px;font-weight:bold;'><td>特定用戶</td><td align=left> <select name=info[type] id=user_type><option value=1 ".($aItemInfo[type]?"selected":"").">是</option><option value=0 ".(!$aItemInfo[type]?"selected":"").">否</option></select></td></tr>";
#获取 奖品列表
$sItemSelect = "<select name=info[item_id]>";
$sSql = "SELECT * FROM gift_items WHERE game_id = ".$nGameId." AND orderby > 0 ORDER BY orderby ASC";
$db->query( $sSql );
while( $row = $db->next_row() ) {
$sItemSelect .= "<option value=".$row["item_id"]." ".($row["item_id"]==$aItemInfo[item_id]?"selected":"").">".$row["item_desc"]."</option>";
}
$sItemSelect .= "</select>";
$sHtml .= "<tr style='font-size:25px;font-weight:bold;display:".($aItemInfo[type]?"normal":"none").";' id=user_type_select><td>指定獎品</td><td align=left> ".$sItemSelect."</td></tr>";
$sHtml .= "<tr style='font-size:25px;font-weight:bold;'><td> </td><td><button type=button class='button btn2' id=admin_user_save>保存</button> <button type=button class='button btn2' id=back name=".$nGameId.">返回</button></td></tr>";
$sHtml .= "</table><input type=hidden name=info[game_id] value='".$nGameId."'><input type=hidden name=info[auto_id] value=".$nAutoId."></form>";
echo $sHtml;
?>
</body>
</html>