123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class User extends Model
- {
- protected $table = "users";
- public $timestamps = false;
- public function CreateUser(array $params)
- {
- // todo 是否需要保证用户名唯一的功能
- $this->username = $params["username"];
- $this->password = $params["password"];
- $this->nickname = $params["nickname"];
- $this->icon = $params["icon"];
- $this->tel = $params["tel"];
- $this->email = $params["email"];
- $this->status = "normal";
- if ($this->username == "" || $this->password == "") {
- return "empty username or password";
- }
- if ($this->nickname == "") {
- $this->nickname = $this->username;
- }
- // todo 这里需要对密码加密
- $this->save();
- return "success";
- }
- public function ChangePassword($uid, $oldPwd, $newPwd)
- {
- }
- public function ModifyUser(array $params)
- {
- $update = [];
- $uid = $params["uid"];
- if ($uid == "") {
- return "empty user id";
- }
- if ($params["username"] != "") {
- $update["username"] = $params["username"];
- }
- if ($params["nickname"] != "") {
- $update["nickname"] = $params["nickname"];
- }
- if ($params["icon"] != "") {
- $update["icon"] = $params["icon"];
- }
- if ($params["tel"] != "") {
- $update["tel"] = $params["tel"];
- }
- if ($params["email"] != "") {
- $update["email"] = $params["email"];
- }
- if (count($update) == 0) {
- return "nothing to update";
- }
- $result = $this->where("id", $uid)
- ->where("is_del", false)
- ->update($update);
- return $result > 0 ? "success" : "fail";
- }
- public function DeleteUser($uid)
- {
- if ($uid == "") {
- return "empty user id";
- }
- $result = $this->where("id", $uid)
- ->where("is_del", false)
- ->update(["is_del" => true]);
- return $result>0?"success": "fail";
- }
- public function ListUser($page, $pageCount)
- {
- $data = $this->where("is_del", false)
- ->paginate($pageCount, ["*"], "page", $page)
- ->get();
- return $data;
- }
- }
|