wesmiler 2 anni fa
parent
commit
f2774a66e2
1 ha cambiato i file con 3 aggiunte e 3 eliminazioni
  1. 3 3
      app/Services/Api/VideoCollectService.php

+ 3 - 3
app/Services/Api/VideoCollectService.php

@@ -301,7 +301,7 @@ class VideoCollectService extends BaseService
             $id = isset($collectInfo['id']) ? $collectInfo['id'] : 0;
 
             // 信息
-            $info = VideoModel::where(['id' => $collectId, 'mark' => 1])->select(['id', 'user_id', 'tags'])->first();
+            $info = VideoModel::where(['id' => $collectId, 'mark' => 1])->select(['id', 'user_id','collect_num','like_num', 'tags'])->first();
             $collectUid = isset($info['user_id']) ? $info['user_id'] : 0;
             if (empty($info)) {
                 $this->error = 1039;
@@ -336,9 +336,9 @@ class VideoCollectService extends BaseService
 
             $updateData = ['update_time' => time()];
             if ($type == 2) {
-                $updateData['collect_num'] = DB::raw('collect_num ' . ($status == 1 ? '+ 1' : '-1'));
+                $updateData['collect_num'] = ($status == 1 ? $info['collect_num']+1 : max(0, $info['collect_num']-1));
             } else if ($type == 3) {
-                $updateData['like_num'] = DB::raw('like_num ' . ($status == 1 ? '+ 1' : '-1'));
+                $updateData['like_num'] = ($status == 1 ? $info['like_num']+1 : max(0, $info['like_num']-1));
             }
             if (!VideoModel::where(['id' => $collectId, 'mark' => 1])->update($updateData)) {
                 DB::rollBack();