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