123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- class GroupUser extends Model
- {
- protected $table = "group_users";
- public $timestamps = false;
- protected $fillable = ["group_id", "user_id"];
- /**
- * todo
- * 这里需要分页,也可能需要根据群组的状态排序,后面再处理
- * 列出用户相关的群组
- *
- * @param $uid
- * @return array
- */
- public function ListGroupIds($uid)
- {
- $groups = $this->select("group_id")->where("user_id", $uid)->where("is_del", false)->all();
- $group_ids = [];
- foreach ($groups as $group) {
- array_push($group_ids, $group->group_id);
- }
- return $group_ids;
- }
- public function GroupAddUser($gid, $uid)
- {
- if ($gid == "") {
- return ["code" => EMPTY_GROUP_ID];
- }
- if ($uid == "") {
- return ["code" => EMPTY_USER_ID];
- }
- $result = $this->firstOrCreate(["group_id" => $gid, "user_id" => $uid, "is_del" => false]);
- unset($result["is_del"]);
- unset($result["created_user_id"]);
- unset($result["updated_user_id"]);
- return ["code" => SUCCESS, "data" => $result];
- }
- public function GroupRemoveUser($id)
- {
- if ($id < 1) {
- return INVALID_GROUP_USER_ID;
- }
- $row = $this->where("id", $id)->where("is_del", false)->update(["is_del" => true]);
- if ($row == 0) {
- return INVALID_GROUP_USER_ID;
- }
- return SUCCESS;
- }
- }
|