feature/main20240421
郭嘉 8 months ago
parent 03513f4bf6
commit 39a3a4b46d
  1. 19
      app/api/controller/Square.php
  2. 5
      app/common/model/Square.php
  3. 5
      app/common/model/Squarelike.php
  4. 1
      public/install/data/install_struct.sql

@ -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);
}
}

@ -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 是否在回收站

@ -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 是否在回收站

@ -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 '更新时间',

Loading…
Cancel
Save