123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Log;
- use PhpParser\Node\Expr\AssignOp\Mod;
- class Group extends Model
- {
- protected $table = "groups";
- public $timestamps = false;
- /**
- * 创建一个用户组,组名必填
- *
- * @param array $params
- * @return array|int
- */
- public function CreateGroup(array $params)
- {
- $this->name = $params["name"];
- $this->description = $params["description"];
- $this->icon = $params["icon"];
- $this->status = "normal";
- if ($this->name == "") {
- return ["code" => EMPTY_GROUP_NAME];
- }
- // check and isn't allowed same name of group
- $group = $this->where("name", $this->name)->where("is_del", false)->first();
- if ($group) {
- return ["code" => REPEAT_GROUP_NAME];
- }
- $this->save();
- $params["id"] = $this->getQueueableId();
- return ["code" => SUCCESS, "data" => $params];
- }
- public function ModifyGroup(array $params)
- {
- $update = [];
- $gid = $params["id"];
- if ($gid == "") {
- return EMPTY_GROUP_ID;
- }
- if ($params["name"] != "") {
- $update["name"] = $params["name"];
- }
- if ($params["description"] != "") {
- $update["description"] = $params["description"];
- }
- if ($params["icon"] != "") {
- $update["icon"] = $params["icon"];
- }
- if (count($update) == 0) {
- return NOTHING_UPDATE;
- }
- $group = $this->where("id", $gid)->where("is_del", false)->first();
- if (!$group) {
- return INVALID_GROUP_ID;
- }
- $this->where("id", $gid)->where("is_del", false)->update($update);
- return SUCCESS;
- }
- public function DeleteGroup(array $params)
- {
- $gid = $params["id"];
- if ($gid == "") {
- return EMPTY_GROUP_ID;
- }
- $row = $this->where("id", $gid)->where("is_del", false)->update(["is_del" => true]);
- if ($row == 0) {
- return INVALID_GROUP_ID;
- }
- return SUCCESS;
- }
- // public function LoadGroup(array $params){
- // $gid = $params["gid"];
- // if ($gid == ""){
- // return"empty group id";
- // }
- // }
- public function ListGroup(array $params)
- {
- $uid = $params["uid"];
- $groupUser = new GroupUser();
- $groupIds = $groupUser->ListGroupIds($uid);
- if (count($groupIds) == 0) {
- return [];
- }
- //
- $result = $this->select("id", "name", "description", "icon", "status")
- ->where("id", $groupIds)
- ->where("is_del", false)
- ->all();
- return $result;
- }
- }
|