|
@@ -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());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//是否点赞
|