부대 코드 변경

This commit is contained in:
2020-04-15 02:13:16 +09:00
parent dfbc837371
commit 1e029ee517
2 changed files with 25 additions and 29 deletions
-7
View File
@@ -95,10 +95,6 @@ uasort($troops, function($lhs, $rhs){
<?=WebUtil::printCSS('css/troops.css')?>
<script>
jQuery(function($){
$('#form1').submit(function(){
return false;
});
$('#leaveTroop').click(function(e){
return confirm("정말 부대를 탈퇴하시겠습니까?");
})
@@ -106,7 +102,6 @@ $('.submitBtn').click(function(event){
if(event.isPropagationStopped()){
return false;
}
console.log('b');
var $this=$(this);
$.post({
@@ -142,7 +137,6 @@ $('.submitBtn').click(function(event){
<table width=1000 class='tb_layout bg0'>
<tr><td>부 대 편 성<br><?=backButton()?></td></tr>
</table>
<form id=form1 name=form1 method=post>
<table id="troop_list" class='tb_layout bg0'>
<thead>
<tr>
@@ -248,7 +242,6 @@ foreach ($troops as $troopNo=>$troop) {
<tr><td><?=backButton()?></td></tr>
<tr><td><?=banner()?> </td></tr>
</table>
</form>
</div>
</body>
</html>
+25 -22
View File
@@ -16,8 +16,8 @@ $userID = $session::getUserID();
$db = DB::db();
$me = $db->queryFirstRow('SELECT `no`, name, nation, troop FROM general WHERE `owner`=%i', $userID);
$generalID = $me['no'];
$nationID = $me['nation'];
if($action == '부대창설'){
$name = trim($name);
@@ -34,15 +34,14 @@ if($action == '부대창설'){
]);
}
$db->insert('troop',[
'troop_leader'=>$generalID,
'name'=>$name,
'nation'=>$me['nation'],
'no'=>$me['no']
'nation'=>$nationID,
]);
$troopID = $db->insertId();
$db->update('general', [
'troop'=>$troopID
], 'no=%i',$me['no']);
'troop'=>$generalID,
], 'no=%i',$generalID);
Json::die([
'result'=>true,
@@ -61,7 +60,7 @@ if($action == '부대변경'){
$db->update('troop', [
'name'=>$name
], 'no=%i',$me['no']);
], 'troop_leader=%i',$generalID);
if($db->affectedRows() == 0){
Json::die([
@@ -86,7 +85,7 @@ if($action == '부대추방'){
$db->update('general', [
'troop'=>0
], 'no=%i AND troop=(SELECT troop FROM troop WHERE no = %i)', $gen, $me['no']);
], 'no=%i AND troop=(SELECT troop FROM troop WHERE troop_leader = %i)', $gen, $generalID);
if($db->affectedRows() == 0){
Json::die([
@@ -109,10 +108,16 @@ if ($action == '부대가입') {
]);
}
$troopLeader = $db->queryFirstField('SELECT `no` FROM troop WHERE troop=%i', $troop)?:0;
$troopLeaderNation = $db->queryFirstField('SELECT `nation` FROM `general` WHERE `no`=%i AND `nation`=%i', $troopLeader, $me['nation']);
if($me['troop'] != 0){
Json::die([
'result'=>false,
'reason'=>'이미 부대에 가입해있습니다.'
]);
}
if (!$troopLeaderNation) {
$troopExists = $db->queryFirstField('SELECT `troop_leader` FROM `troop` WHERE `troop_leader` = %i AND `nation` = %i', $troop, $nationID);
if (!$troopExists) {
Json::die([
'result'=>false,
'reason'=>'올바른 부대장이 아닙니다.'
@@ -121,7 +126,7 @@ if ($action == '부대가입') {
$db->update('general', [
'troop'=>$troop
], 'no=%i', $me['no']);
], 'no=%i', $generalID);
Json::die([
'result'=>true,
@@ -137,20 +142,18 @@ if($action == "부대탈퇴") {
'reason'=>'부대에 속해있지 않습니다.'
]);
}
$troopLeader = $db->queryFirstField('SELECT `no` FROM troop WHERE troop=%i', $me['troop']);
//부대장일 경우
if($troopLeader == $me['no']) {
// 모두 탈퇴
if($me['troop'] === $generalID){
$db->update('general', [
'troop'=>0
], 'troop=%i',$me['troop']);
// 부대 삭제
$db->delete('troop', 'troop=%i', $me['troop']);
} else {
], 'troop=%i',$generalID);
$db->delete('troop', 'troop_leader=%i', $generalID);
}
else{
$db->update('general', [
'troop'=>0
], 'no=%i', $me['no']);
], 'no=%i', $generalID);
}
Json::die([