Browse Source

修改UserActionBar的字段,剩下ListActionBarIds没有处理

DESKTOP-C21C1Q8\tangs 6 years ago
parent
commit
23c68505d3
2 changed files with 24 additions and 14 deletions
  1. 6 4
      app/Http/Controllers/UserActionBarController.php
  2. 18 10
      app/Models/UserActionBar.php

+ 6 - 4
app/Http/Controllers/UserActionBarController.php

@@ -10,21 +10,23 @@ class UserActionBarController extends Controller
 {
     public function AddUserActionBar(Request $request)
     {
-        $uid = $request->input("uid");
+        $owner_type = $request->input("owner_type");
+        $owner_id = $request->input("owner_id");
         $barId = $request->input("barId");
 
         $userActionBar = new Models\UserActionBar();
-        $userActionBar->AddUserActionBar($uid, $barId);
+        $userActionBar->AddUserActionBar($owner_type, $owner_id, $barId);
         return "success";
     }
 
     public function RemoveActionBar(Request $request)
     {
-        $uid = $request->input("uid");
+        $owner_type = $request->input("owner_type");
+        $owner_id = $request->input("owner_id");
         $barId = $request->input("barId");
 
         $userActionBar = new Models\UserActionBar();
-        $userActionBar->RemoveUserActionBar($uid, $barId);
+        $userActionBar->RemoveUserActionBar($owner_type, $owner_id, $barId);
         return "success";
     }
 }

+ 18 - 10
app/Models/UserActionBar.php

@@ -11,9 +11,12 @@ class UserActionBar extends Model
     protected $table = "user_action_bars";
     public $timestamps = false;
 
-    public function AddUserActionBar($uid, $barId)
+    public function AddUserActionBar($owner_type, $owner_id, $barId)
     {
-        if ($uid == "") {
+        if ($owner_type == "") {
+            return "empty user type";
+        }
+        if ($owner_id == "") {
             return "empty user id";
         }
         if ($barId == "") {
@@ -21,27 +24,31 @@ class UserActionBar extends Model
         }
 
         //INSERT INTO demo_in(a,b,c) SELECT 123, 2, 4 FROM DUAL WHERE NOT EXISTS(SELECT c FROM demo_in WHERE c = 4);
-        $sql = sprintf("insert into user_action_bars(user_id, bar_id) 
-                                    select ?, ? from temp_uab 
+        $sql = sprintf("insert into user_action_bars(owner_type, owner_id, bar_id) 
+                                    select ?, ?, ? from temp_uab 
                                     where not exists(
                                     select id from user_action_bars
-                                    where user_id = ? and bar_id = ? and is_del = false);");
+                                    where owner_type = ? and owner_id = ? and bar_id = ? and is_del = false);");
 
-        $result = DB::insert($sql, [$uid, $barId, $uid, $barId]);
+        $result = DB::insert($sql, [$owner_type, $owner_id, $barId, $owner_type, $owner_id, $barId]);
         Log::debug("AddUserActionBar " . $result);
         return "success";
     }
 
-    public function RemoveUserActionBar($uid, $barId)
+    public function RemoveUserActionBar($owner_type, $owner_id, $barId)
     {
-        if ($uid == "") {
+        if ($owner_type == "") {
+            return "empty user type";
+        }
+        if ($owner_id == "") {
             return "empty user id";
         }
         if ($barId == "") {
             return "empty action bar id";
         }
 
-        $data = $this->where("user_id", $uid)
+        $data = $this->where("owner_type", $owner_type)
+            ->where("owner_id", $owner_id)
             ->where("bar_id", $barId)
             ->where("is_del", false)
             ->first();
@@ -49,7 +56,8 @@ class UserActionBar extends Model
             return "nothing to remove";
         }
         $this->is_del = true;
-        $this->where("user_id", $uid)
+        $this->where("owner_type", $owner_type)
+            ->where("owner_id", $owner_id)
             ->where("bar_id", $barId)
             ->where("is_del", false)
             ->update(["is_del" => true]);