diff --git a/web/app/models/ClickZans.php b/web/app/models/ClickZans.php
index 8659947..58ab89c 100644
--- a/web/app/models/ClickZans.php
+++ b/web/app/models/ClickZans.php
@@ -23,7 +23,7 @@ class ClickZans {
return true;
}
}
-
+
public static function query($id, $type, $user) {
if ($user == null) {
return 0;
@@ -44,13 +44,13 @@ class ClickZans {
public static function click($id, $type, $user, $delta) {
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);
-
+
$cur = ClickZans::query($id, $type, $user);
-
+
$row = DB::selectFirst([
"select zan from", DB::table($table_name),
"where", ['id' => $id], DB::for_update()
@@ -58,7 +58,7 @@ class ClickZans {
if (!$row) {
return '
failed
';
}
-
+
if ($cur != $delta) {
$cur += $delta;
if ($cur == 0) {
@@ -68,11 +68,11 @@ class ClickZans {
'username' => Auth::id(),
'type' => $type,
'target_id' => $id
- ]
+ ]
]);
} elseif ($cur != $delta) {
DB::update([
- "update click_zans",
+ "update click_zans",
"set", ['val' => $cur],
"where", [
'username' => Auth::id(),
@@ -96,17 +96,17 @@ class ClickZans {
} else {
$cnt = $row['zan'];
}
-
+
return ClickZans::getBlock($type, $id, $cnt, $cur);
}
-
+
public static function getBlock($type, $id, $cnt, $val = null) {
if ($val === null) {
$val = ClickZans::query($id, $type, Auth::user());
}
- return '';
+ return '';
}
-
+
public static function getCntBlock($cnt) {
$cls = 'uoj-click-zan-block-';
if ($cnt > 0) {
@@ -116,6 +116,11 @@ class ClickZans {
} else {
$cls .= 'neutral';
}
- return '[' . ($cnt > 0 ? '+' . $cnt : $cnt) . ']';
+
+ $display_cnt = $cnt > 0 ? '+' . $cnt : $cnt;
+
+ if ($cnt < 0) $display_cnt = '-';
+
+ return '[' . $display_cnt . ']';
}
}
diff --git a/web/js/uoj.js b/web/js/uoj.js
index 8356ff1..c920fd8 100644
--- a/web/js/uoj.js
+++ b/web/js/uoj.js
@@ -326,11 +326,15 @@ $.fn.click_zan_block = function() {
e.preventDefault();
click_zan(id, type, -1, node);
});
+
+ var display_cnt = cnt > 0 ? '+' + cnt : cnt;
+
+ if (cnt < 0) display_cnt = '-';
$(this)
.append(up_node)
.append(down_node)
- .append($('[' + (cnt > 0 ? '+' + cnt : cnt) + ']'));
+ .append($('[' + display_cnt + ']'));
});
}