12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?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($uid, $barId)
- {
- if ($uid == "") {
- 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(user_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);");
- $result = DB::insert($sql, [$uid, $barId, $uid, $barId]);
- Log::debug("AddUserActionBar " . $result);
- return "success";
- }
- public function RemoveUserActionBar($uid, $barId)
- {
- if ($uid == "") {
- return "empty user id";
- }
- if ($barId == "") {
- return "empty action bar id";
- }
- $data = $this->where("user_id", $uid)
- ->where("bar_id", $barId)
- ->where("is_del", false)
- ->first();
- if (!$data) {
- return "nothing to remove";
- }
- $this->is_del = true;
- $this->where("user_id", $uid)
- ->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;
- }
- }
|