Browse Source

动态删除同步话题数量

zhangxiaobin 1 year ago
parent
commit
36c7fc1a90
1 changed files with 25 additions and 3 deletions
  1. 25 3
      application/api/controller/Topicdongtai.php

+ 25 - 3
application/api/controller/Topicdongtai.php

@@ -5,6 +5,8 @@ namespace app\api\controller;
 use app\common\controller\Api;
 use think\Db;
 use app\common\library\Keyworld;
+use think\Exception;
+
 /**
  * 圈子动态
  */
@@ -92,9 +94,29 @@ class Topicdongtai extends Api
 
     //动态删除
     public function delete(){
-        $id = input('id',0);
-        Db::name('topic_dongtai')->where('id',$id)->where('user_id',$this->auth->id)->delete();
-        $this->success('删除成功');
+        try {
+            $id = input('id',0);
+            $where['id'] = $id;
+            $where['user_id'] = $this->auth->id;
+            $dongtai = Db::name('topic_dongtai')->field('id,topic_id')->where($where)->find();
+            if (empty($dongtai)) {
+                throw new Exception('未找到动态信息');
+            }
+            $delRes = Db::name('topic_dongtai')->where('id',$id)->where('user_id',$this->auth->id)->delete();
+            if (!$delRes) {
+                throw new Exception('动态删除失败');
+            }
+            //圈子新增一个贴
+            if (!empty($dongtai['topic_id'])) {
+                $res = Db::name('topic_hub')->where('id',$dongtai['topic_id'])->setDec('t_number');
+                if (!$res) {
+                    throw new Exception('更新话题数量失败');
+                }
+            }
+            $this->success('删除成功');
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
     }
 
     //是否点赞