123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- class UserActionBar extends Model
- {
- protected $table = "user_action_bars";
- public $timestamps = false;
- public function AddUserActionBar($owner_type, $owner_id, $barId)
- {
- if ($owner_type == "") {
- return "empty user type";
- }
- if ($owner_id == "") {
- return "empty user id";
- }
- if ($barId == "") {
- return "empty action bar id";
- }
- //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(owner_type, owner_id, bar_id)
- select ?, ?, ? from temp_uab
- where not exists(
- select id from user_action_bars
- where owner_type = ? and owner_id = ? and bar_id = ? and is_del = false);");
- $result = DB::insert($sql, [$owner_type, $owner_id, $barId, $owner_type, $owner_id, $barId]);
- Log::debug("AddUserActionBar " . $result);
- return "success";
- }
- public function RemoveUserActionBar($owner_type, $owner_id, $barId)
- {
- if ($owner_type == "") {
- return "empty user type";
- }
- if ($owner_id == "") {
- return "empty user id";
- }
- if ($barId == "") {
- return "empty action bar id";
- }
- $data = $this->where("owner_type", $owner_type)
- ->where("owner_id", $owner_id)
- ->where("bar_id", $barId)
- ->where("is_del", false)
- ->first();
- if (!$data) {
- return "nothing to remove";
- }
- $this->is_del = true;
- $this->where("owner_type", $owner_type)
- ->where("owner_id", $owner_id)
- ->where("bar_id", $barId)
- ->where("is_del", false)
- ->update(["is_del" => true]);
- return "success";
- }
- /**
- * @param $uid
- * @return array
- */
- public function ListActionBarIds($uid)
- {
- $bars = $this->select("bar_id")
- ->where("user_id", $uid)
- ->where("status", "normal")
- ->where("is_del", false)
- ->get();
- if (count($bars) == 0) {
- return [];
- }
- $bar_ids = [];
- foreach ($bar_ids as $bar_id) {
- array_push($bar_ids, $bar_id->bar_id);
- }
- return $bar_ids;
- }
- }
|