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