From bfb9d35d6a7d029dd4cfc60e9277a756f11a1a41 Mon Sep 17 00:00:00 2001 From: hujiabin Date: Tue, 20 Sep 2022 21:34:06 +0800 Subject: [PATCH] 1 --- webapp/controller/UserController.class.php | 19 +++++++++++++++++++ webapp/models/User.php | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/webapp/controller/UserController.class.php b/webapp/controller/UserController.class.php index a5c001e2..44bff372 100644 --- a/webapp/controller/UserController.class.php +++ b/webapp/controller/UserController.class.php @@ -534,4 +534,23 @@ class UserController extends BaseAuthedController { )); } + public function like(){ + $account_id = getReqVal('target_id', ''); + if (! $account_id){ + $this->_rspErr(1, 'target_id param error'); + return; + } + if ($account_id == $this->_getAccountId()){ + $this->_rspErr(1, 'target_id param error'); + return; + } + $userDb = User::find($account_id); + if (!$userDb){ + $this->_rspErr(1, 'target_id param error'); + return; + } + User::updateLikeCount($account_id); + $this->_rspOk(); + } + } diff --git a/webapp/models/User.php b/webapp/models/User.php index cd763084..41ef87f2 100644 --- a/webapp/models/User.php +++ b/webapp/models/User.php @@ -143,4 +143,19 @@ class User extends BaseModel { ); } + public static function updateLikeCount($targetId){ + SqlHelper::update + (myself()->_getSelfMysql(), + 't_user', + array( + 'account_id' => $targetId, + ), + array( + 'like_count' => function(){ + return "like_count + 1"; + } + ) + ); + } + }