From 39a3a4b46d99a74dddadd51712f99ad2a7c5feeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E5=98=89?= <445241500@qq.com> Date: Thu, 9 May 2024 21:45:32 +0800 Subject: [PATCH] trac --- app/api/controller/Square.php | 19 +++++++++++++++++++ app/common/model/Square.php | 5 +++-- app/common/model/Squarelike.php | 5 +++++ public/install/data/install_struct.sql | 1 + 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/api/controller/Square.php b/app/api/controller/Square.php index 5866ca70..d041c220 100644 --- a/app/api/controller/Square.php +++ b/app/api/controller/Square.php @@ -71,7 +71,12 @@ class Square extends Controller foreach ($list['data'] as $kr => $r) { $model = new UserModel(); $user = $model->where(['user_id' => $r['user_name']])->find()->toArray(); + + $modelLike = new squarelikeModel(); + $like = $modelLike->where(['user_id' => $r['user_name']])->where(['square_id' => $r['square_id']])->find()->toArray(); + $res[$kr]['imgs'] = []; + $res[$kr]['isLike'] = !empty($like) ? true : false; $res[$kr]['avatar_url'] = []; if ($r['imgs']) { $img_ids = explode(",", $r['imgs']); @@ -95,14 +100,28 @@ class Square extends Controller $data = $this->postForm(); if (empty($detail)) { if ($model->add($data)) { + $this->dynamicLikeNum($id); return $this->renderSuccess('操作成功'); } } else { $data['squarelike_id'] = $detail['squarelike_id']; if ($detail->delete($data)) { + $this->dynamicLikeNum($id); return $this->renderSuccess('操作成功'); } } } + public function dynamicLikeNum(int $id) : Json + { + $detail = squareModel::detail($id); + $count = squarelikeModel::getCount($id); + $arr = [ + 'likeNum' => $count, + 'square_id' => $id + ]; + $detail->edit($arr); + + } + } diff --git a/app/common/model/Square.php b/app/common/model/Square.php index 019e7e59..85eabb0b 100644 --- a/app/common/model/Square.php +++ b/app/common/model/Square.php @@ -34,15 +34,16 @@ class Square extends BaseModel * @param int $storeId * @return static|array|null */ - public static function detail(int $merchantId) + public static function detail(int $squareId) { $where = [ - 'merchant_id' => $merchantId, + 'square_id' => $squareId, 'store_id' => self::$storeId ]; return static::get($where, []); } + /** * 获取列表数据 * @param bool $isRecycle 是否在回收站 diff --git a/app/common/model/Squarelike.php b/app/common/model/Squarelike.php index ef503dbc..f5faaf66 100644 --- a/app/common/model/Squarelike.php +++ b/app/common/model/Squarelike.php @@ -44,6 +44,11 @@ class Squarelike extends BaseModel return static::get($where, []); } + public static function getCount(int $squareId) { + return self::where('square_id', '=', $squareId) + ->count(); + } + /** * 获取列表数据 * @param bool $isRecycle 是否在回收站 diff --git a/public/install/data/install_struct.sql b/public/install/data/install_struct.sql index 2751aec9..b403bf28 100644 --- a/public/install/data/install_struct.sql +++ b/public/install/data/install_struct.sql @@ -1752,6 +1752,7 @@ CREATE TABLE `yoshop_square` ( `cate` varchar(200) NOT NULL DEFAULT '' COMMENT '动态类别', `user_name` varchar(100) NOT NULL DEFAULT '' COMMENT '买家用户名', `real_name` varchar(100) NOT NULL DEFAULT '' COMMENT '真实用户名', + `likeNum` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '点赞数量', `is_delete` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除', `create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', `update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',