123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class UserActionBar extends Model
- {
- protected $table = "user_action_bars";
- protected $fillable = ["owner_type", "owner_id", "bar_id"];
- public $timestamps = false;
- public function AddUserActionBar($ownerType, $ownerId, $barId)
- {
- if ($ownerType == "") {
- return ["code" => EMPTY_OWNER_TYPE];
- }
- if ($ownerId == "") {
- return ["code" => EMPTY_OWNER_ID];
- }
- if ($barId == "") {
- return ["code" => EMPTY_BAR_ID];
- }
- // check owner and barId if exist in system.
- $code = $this->checkOwner($ownerType, $ownerId);
- if ($code != 0) {
- return ["code" => $code];
- }
- $code = $this->checkActionBar($barId);
- if ($code != 0) {
- return ["code" => $code];
- }
- $result = $this->firstOrCreate(["owner_type" => $ownerType, "owner_id" => $ownerId, "bar_id" => $barId, "is_del" => false]);
- unset($result["is_del"]);
- unset($result["created_user_id"]);
- unset($result["updated_user_id"]);
- return ["code" => 0, "data" => $result];
- }
- private function checkActionBar($barId)
- {
- return SUCCESS;
- }
- private function checkOwner($ownerType, $ownerId)
- {
- return SUCCESS;
- }
- public function RemoveUserActionBar($id)
- {
- if ($id < 1) {
- return INVALID_U_A_ID;
- }
- // check the data if exist in system.
- $item = $this->where("id", $id)->where("is_del", false)->first();
- if (!$item) {
- return INVALID_U_A_ID;
- }
- $this->where("id", $id)->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;
- }
- }
|