瀏覽代碼

删除不需要的模型和控制器

刘忠健 2 年之前
父節點
當前提交
c0b203252c

+ 0 - 137
api/app/api/controller/Record.php

@@ -1,137 +0,0 @@
-<?php
-
-
-namespace app\api\controller;
-
-
-use app\common\ErrorCode;
-use app\common\model\Type;
-
-class Record extends BaseAuthorized
-{
-    public function typeList()
-    {
-        $typeList = Type::where("valid", "=", "1")->select();
-        $this->success($typeList);
-    }
-
-    public function add()
-    {
-        ///^(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$/;
-        $param = request()->param();
-        $rules = [
-            "record_date" => "require|date",
-            "record_begin" => "require",
-            "record_end" => "require",
-            "type_id" => "require|number",
-            "remark" => "require|max:25",
-        ];
-        $this->autoValid($rules, $param);
-        $record = new \app\common\model\Record([
-            "record_date" => $param["record_date"],
-            "record_begin" => $param["record_begin"],
-            "record_end" => $param["record_end"],
-            "type_id" => $param["type_id"],
-            "remark" => $param["remark"],
-            "user_id" => $this->user->id,
-        ]);
-        $record->record_long = $record->computeRecordLong();
-        $res = $record->save();
-        if ($res === false) {
-            //数据库读写失败
-            $this->error(ErrorCode::getError(ErrorCode::CODE_DB_ERROR), ErrorCode::CODE_DB_ERROR);
-
-        }
-        $this->success(ErrorCode::CODE_SUCC);
-
-    }
-
-    public function detail(){
-        $param = request()->param();
-        $rules = [
-            "id" => "require|number",
-
-        ];
-        $this->autoValid($rules, $param);
-        $record = \app\common\model\Record::find($param["id"]);
-        $record->type;
-        if (!$record) {
-            $this->error("记录未找到", ErrorCode::CODE_RECORD_NOT_FOUND);
-        }
-        $this->success($record);
-    }
-
-    public function edit()
-    {
-        $param = request()->param();
-        $rules = [
-            "id" => "require|number",
-            "record_date" => "require|date",
-            "record_begin" => "require",
-            "record_end" => "require",
-            "type_id" => "require|number",
-            "remark" => "require|max:25",
-        ];
-        $this->autoValid($rules, $param);
-        $record = \app\common\model\Record::find($param["id"]);
-        if (!$record) {
-            $this->error("记录未找到", ErrorCode::CODE_RECORD_NOT_FOUND);
-        }
-        $record->record_date = $param["record_date"];
-        $record->record_begin = $param["record_begin"];
-        $record->record_end = $param["record_end"];
-        $record->type_id = $param["type_id"];
-        $record->remark = $param["remark"];
-        $record->record_long = $record->computeRecordLong();
-        $res = $record->save();
-        if ($res === false) {
-            //数据库读写失败
-            $this->error(ErrorCode::getError(ErrorCode::CODE_DB_ERROR), ErrorCode::CODE_DB_ERROR);
-
-        }
-        $this->success(ErrorCode::CODE_SUCC);
-    }
-
-    public function delete()
-    {
-        $param = request()->param();
-        $rules = [
-            "id" => "require|number",
-        ];
-        $this->autoValid($rules, $param);
-        $res = \app\common\model\Record::where("id", "=", $param["id"])->delete();
-        if ($res === false) {
-            //数据库读写失败
-            $this->error(ErrorCode::getError(ErrorCode::CODE_DB_ERROR), ErrorCode::CODE_DB_ERROR);
-
-        }
-        $this->success(ErrorCode::CODE_SUCC);
-    }
-
-    public function index()
-    {
-        $param = request()->param();
-        $rules = [
-            "date" => "require|date"
-        ];
-        $this->autoValid($rules, $param);
-        //找当月
-        $dateStamp = strtotime($param["date"]);//当天的时间戳
-        $beginDay = date("Y-m-1", $dateStamp);//月头
-        $endDay = date("Y-m-" . date("t", $dateStamp), $dateStamp);
-        //找日期列表
-        $whereDateList[] = ["record_date", "between", [$beginDay, $endDay]];
-
-        $dateList = \app\common\model\Record::where($whereDateList)->field("record_date")->group("record_date")->order("record_date  asc")->select();
-        $dateArr = [];
-        foreach ($dateList as $key => $value) {
-            $dateArr[] = $value["record_date"];
-        }
-        //找当天
-        $recordList = \app\common\model\Record::with(["type"])->where("record_date", "=", date("Y-m-d", $dateStamp))->order("record_begin asc,id asc")->select();
-        $this->success([
-            "dateArr" => $dateArr,
-            "recordList" => $recordList
-        ]);
-    }
-}

+ 0 - 39
api/app/api/controller/User.php

@@ -1,39 +0,0 @@
-<?php
-
-
-namespace app\api\controller;
-
-
-use think\facade\Db;
-
-class User extends BaseAuthorized
-{
-    public function changePassword()
-    {
-        $param = request()->param();
-        $rules = [
-            "orgPassword" => "require|length:2,25",
-            'password' => 'require|length:6,25',
-            'repassword' => 'require|confirm:password',
-        ];
-        $this->autoValid($rules, $param);
-        $res = $this->user->changePassword($param["orgPassword"], $param["password"]);
-        if ($res["code"] != 0) {
-            $this->error($res['msg'], $res["code"]);
-        }
-        $this->success("");
-    }
-
-    /**
-     * 退出登录
-     */
-    public function loginOut(){
-        $res=$this->user->loginOut();
-        if ($res["code"] != 0) {
-            $this->error($res['msg'], $res["code"]);
-        }
-        $this->success("","退出成功");
-    }
-
-
-}

+ 0 - 35
api/app/common/model/Record.php

@@ -1,35 +0,0 @@
-<?php
-
-
-namespace app\common\model;
-
-
-class Record extends Base
-{
-
-    /**
-     * 计算时长
-     * @return int
-     */
-    public function computeRecordLong(){
-        $begin=strtotime(date("Y-m-d ").$this->record_begin);
-        $end=strtotime(date("Y-m-d ").$this->record_end);
-        return intval(($end-$begin)/60);
-    }
-
-    /**
-     * 关联类型
-     * @return \think\model\relation\HasOne
-     */
-    public function type(){
-        return $this->hasOne(Type::class,"id","type_id");
-    }
-
-    /**
-     * 关联用户
-     */
-    public function user(){
-        return $this->hasOne(User::class,"id","user_id");
-    }
-
-}

+ 0 - 10
api/app/common/model/Type.php

@@ -1,10 +0,0 @@
-<?php
-
-
-namespace app\common\model;
-
-
-class Type extends Base
-{
-
-}

+ 0 - 135
api/app/common/model/User.php

@@ -1,135 +0,0 @@
-<?php
-
-
-namespace app\common\model;
-
-
-use app\common\ErrorCode;
-
-class User extends Base
-{
-    public static $fieldStr = "id,login_name,salt,valid,last_login_time,login_count,token";
-
-    /**
-     * 检测用户是否存在
-     * @param $login_name
-     * @return array
-     */
-    public static function checkRegUser($login_name)
-    {
-        //检测账号是否被注册
-        $where['login_name'] = $login_name;
-        $exist = self::where($where)->find();
-        if ($exist) {
-            //用户存在
-            return self::standardOutput(9999, "用户已存在");
-        }
-        return self::standardOutput(ErrorCode::CODE_SUCC);
-    }
-
-    /**
-     * 用户注册
-     * @param $login_name
-     * @param $password
-     * @return array
-     */
-    public static function regUser($login_name, $password)
-    {
-        //注册用户
-        $res = self::checkRegUser($login_name);
-        if ($res["code"] != 0) {
-            return $res;
-        }
-        //创建用户
-        $salt = randNum(4);//生成随机盐
-        $user = new User([
-            "login_name" => $login_name,
-            "salt" => $salt,
-            "password" => md5($salt . $password),
-            "ext1" => $salt . $password
-        ]);
-        $res = $user->save();
-
-        if ($res === false) {
-            return self::standardOutput(ErrorCode::CODE_DB_ERROR, ErrorCode::getError(ErrorCode::CODE_DB_ERROR));
-        }
-        return self::standardOutput(ErrorCode::CODE_SUCC);
-    }
-
-    /**
-     * 用户登录
-     * @param $login_name
-     * @param $password
-     */
-    public static function login($login_name, $password)
-    {
-        $whereUser = [];
-        $whereUser["login_name"] = $login_name;
-        $user = self::where($whereUser)->find();
-        if (!$user) {
-            return self::standardOutput(9999, "用户不存在");
-        }
-        $passwordMd5 = md5($user->salt . $password);
-        if ($passwordMd5 != $user->password) {
-            return self::standardOutput(9999, "用户密码不正确");
-        }
-        //更新用户登录 信息
-        $user->last_login_time = getNow();
-        $user->login_count = $user->login_count + 1;
-        $user->token = $user->getToken();
-        $user->hidden(["salt","password"]);
-        $res = $user->save();
-        if ($res === false) {
-            //数据库读写失败
-            return self::standardOutput(ErrorCode::CODE_DB_ERROR, ErrorCode::getError(ErrorCode::CODE_DB_ERROR));
-        }
-        return self::standardOutput(ErrorCode::CODE_SUCC, "登录成功", $user);
-    }
-
-    /**
-     * 获取token
-     * @return string
-     */
-    public function getToken()
-    {
-        $expireDays = 7;//过期时间,单位天
-        //token:  md5([用户名][当前时间])|[用户id]|[过期时间]
-        $token = base64_encode(md5($this->login_name . getNow()) . "|" . $this->id . "|" . (time() + 86400 * $expireDays));
-        return $token;
-    }
-
-    /**
-     * 修改密码
-     */
-    public function changePassword($orgPassword, $newPassword)
-    {
-        //校验旧密码
-        $passwordMd5 = md5($this->salt . $orgPassword);
-        if ($passwordMd5 != $this->password) {
-            $str=$this->salt . $orgPassword."---".$passwordMd5."---".$this->password;
-            return self::standardOutput(9999, "原密码不正确".$str);
-        }
-        $this->password = md5($this->salt . $newPassword);
-        $res = $this->save();
-        if ($res === false) {
-            //数据库读写失败
-            return self::standardOutput(ErrorCode::CODE_DB_ERROR, ErrorCode::getError(ErrorCode::CODE_DB_ERROR));
-        }
-        return self::standardOutput(ErrorCode::CODE_SUCC);
-    }
-
-    /**
-     * 退出登录
-     */
-    public function loginOut()
-    {
-        $this->token = "";
-        $res = $this->save();
-        if ($res === false) {
-            //数据库读写失败
-            return self::standardOutput(ErrorCode::CODE_DB_ERROR, ErrorCode::getError(ErrorCode::CODE_DB_ERROR));
-        }
-        return self::standardOutput(ErrorCode::CODE_SUCC);
-    }
-
-}