mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-22 03:08:41 +00:00
feat: hide exact value of negative zan values
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9ad23faefc
commit
5394bbb2f7
@ -23,7 +23,7 @@ class ClickZans {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function query($id, $type, $user) {
|
public static function query($id, $type, $user) {
|
||||||
if ($user == null) {
|
if ($user == null) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -44,13 +44,13 @@ class ClickZans {
|
|||||||
|
|
||||||
public static function click($id, $type, $user, $delta) {
|
public static function click($id, $type, $user, $delta) {
|
||||||
if (!DB::$in_transaction) {
|
if (!DB::$in_transaction) {
|
||||||
return DB::transaction(fn() => ClickZans::click($id, $type, $user, $delta));
|
return DB::transaction(fn () => ClickZans::click($id, $type, $user, $delta));
|
||||||
}
|
}
|
||||||
|
|
||||||
$table_name = ClickZans::getTable($type);
|
$table_name = ClickZans::getTable($type);
|
||||||
|
|
||||||
$cur = ClickZans::query($id, $type, $user);
|
$cur = ClickZans::query($id, $type, $user);
|
||||||
|
|
||||||
$row = DB::selectFirst([
|
$row = DB::selectFirst([
|
||||||
"select zan from", DB::table($table_name),
|
"select zan from", DB::table($table_name),
|
||||||
"where", ['id' => $id], DB::for_update()
|
"where", ['id' => $id], DB::for_update()
|
||||||
@ -58,7 +58,7 @@ class ClickZans {
|
|||||||
if (!$row) {
|
if (!$row) {
|
||||||
return '<div class="text-danger">failed</div>';
|
return '<div class="text-danger">failed</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cur != $delta) {
|
if ($cur != $delta) {
|
||||||
$cur += $delta;
|
$cur += $delta;
|
||||||
if ($cur == 0) {
|
if ($cur == 0) {
|
||||||
@ -68,11 +68,11 @@ class ClickZans {
|
|||||||
'username' => Auth::id(),
|
'username' => Auth::id(),
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'target_id' => $id
|
'target_id' => $id
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
} elseif ($cur != $delta) {
|
} elseif ($cur != $delta) {
|
||||||
DB::update([
|
DB::update([
|
||||||
"update click_zans",
|
"update click_zans",
|
||||||
"set", ['val' => $cur],
|
"set", ['val' => $cur],
|
||||||
"where", [
|
"where", [
|
||||||
'username' => Auth::id(),
|
'username' => Auth::id(),
|
||||||
@ -96,17 +96,17 @@ class ClickZans {
|
|||||||
} else {
|
} else {
|
||||||
$cnt = $row['zan'];
|
$cnt = $row['zan'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return ClickZans::getBlock($type, $id, $cnt, $cur);
|
return ClickZans::getBlock($type, $id, $cnt, $cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getBlock($type, $id, $cnt, $val = null) {
|
public static function getBlock($type, $id, $cnt, $val = null) {
|
||||||
if ($val === null) {
|
if ($val === null) {
|
||||||
$val = ClickZans::query($id, $type, Auth::user());
|
$val = ClickZans::query($id, $type, Auth::user());
|
||||||
}
|
}
|
||||||
return '<div class="uoj-click-zan-block" data-id="'.$id.'" data-type="'.$type.'" data-val="'.$val.'" data-cnt="'.$cnt.'"></div>';
|
return '<div class="uoj-click-zan-block" data-id="' . $id . '" data-type="' . $type . '" data-val="' . $val . '" data-cnt="' . $cnt . '"></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCntBlock($cnt) {
|
public static function getCntBlock($cnt) {
|
||||||
$cls = 'uoj-click-zan-block-';
|
$cls = 'uoj-click-zan-block-';
|
||||||
if ($cnt > 0) {
|
if ($cnt > 0) {
|
||||||
@ -116,6 +116,11 @@ class ClickZans {
|
|||||||
} else {
|
} else {
|
||||||
$cls .= 'neutral';
|
$cls .= 'neutral';
|
||||||
}
|
}
|
||||||
return '<span class="'.$cls.'"><span class="uoj-click-zan-cnt">[<strong>' . ($cnt > 0 ? '+' . $cnt : $cnt) . '</strong>]</span></span>';
|
|
||||||
|
$display_cnt = $cnt > 0 ? '+' . $cnt : $cnt;
|
||||||
|
|
||||||
|
if ($cnt < 0) $display_cnt = '-';
|
||||||
|
|
||||||
|
return '<span class="' . $cls . '"><span class="uoj-click-zan-cnt">[<strong>' . $display_cnt . '</strong>]</span></span>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -326,11 +326,15 @@ $.fn.click_zan_block = function() {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
click_zan(id, type, -1, node);
|
click_zan(id, type, -1, node);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var display_cnt = cnt > 0 ? '+' + cnt : cnt;
|
||||||
|
|
||||||
|
if (cnt < 0) display_cnt = '-';
|
||||||
|
|
||||||
$(this)
|
$(this)
|
||||||
.append(up_node)
|
.append(up_node)
|
||||||
.append(down_node)
|
.append(down_node)
|
||||||
.append($('<span class="uoj-click-zan-cnt">[<strong>' + (cnt > 0 ? '+' + cnt : cnt) + '</strong>]</span>'));
|
.append($('<span class="uoj-click-zan-cnt">[<strong>' + display_cnt + '</strong>]</span>'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user