123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\index\controller;
- use library\Controller;
- use think\Db;
- /**
- * 应用入口
- * Class Index
- * @package app\index\controller
- */
- class Index extends Controller
- {
- /**
- * 入口跳转链接
- */
- public function index()
- {
- $this->redirect('@admin/login');
- }
- /**
- * 注册
- *
- * username 用户姓名
- * mobile 手机号
- * pwd 密码
- * level 0业主1德高会员2分销会员
- */
- public function register()
- {
- $data = $this->request->post();
- if (!isset($data['username']) || empty($data['username'])) return $this->error('请输入姓名');
- if (!isset($data['mobile']) || empty($data['mobile'])) return $this->error('请输入手机号');
- if (!isset($data['pwd']) || empty($data['pwd'])) return $this->error('请输入密码');
- if(strlen($data['username'])<3 || strlen($data['username'])>12) return $this->error('姓名长度为3-12位');
- if(!preg_match("/^1[34578]\d{9}$/", $data['mobile'])) return $this->error('手机号格式不正确');
- if(strlen($data['pwd'])<6 || strlen($data['pwd'])>18) return $this->error('密码长度为6-18位');
- $data['pwd'] = md5(md5($data['pwd']));
- // 检测该手机号是否注册过
- $isReg = Db::name('user')->where('mobile',$data['mobile'])->where('level',$data['level'])->find();
- if ($isReg) return $this->error('该手机号已被注册');
- $register = Db::name('user')->insert($data);
- if ($register) {
- return $this->success('注册成功');
- } else {
- return $this->error('注册失败');
- }
- }
- /**
- * 登录
- * mobile 手机号
- * pwd 密码
- * level 0业主1德高会员2分销会员
- */
- public function login()
- {
- $data = $this->request->post();
- if (!isset($data['mobile']) || empty($data['mobile'])) return $this->error('请输入手机号');
- if(!preg_match("/^1[34578]\d{9}$/", $data['mobile'])) return $this->error('手机号格式不正确');
- if (!isset($data['pwd']) || empty($data['pwd'])) return $this->error('请输入密码');
- if(strlen($data['pwd'])<6 || strlen($data['pwd'])>18) return $this->error('密码长度为6-18位');
- $isMobile = Db::name('user')->where('mobile',$data['mobile'])->where('level',$data['level'])->find();
- if ($isMobile) {
- $data['pwd'] = md5(md5($data['pwd']));
- $login = Db::name('user')->where($data)->find();
- if ($login) {
- $token = md5(md5(time()));
- $userTokenData = [
- 'uid' => $login['id'],
- 'token' => $token,
- 'create_time' => time(),
- ];
- Db::name('user_token')->where('uid',$login['id'])->delete();
- $saveToken = Db::name('user_token')->insert($userTokenData);
- $login['token'] = $token;
- unset($login['pwd']);
- return $this->success('登录成功',$login);
- } else {
- return $this->error('密码错误');
- }
- } else {
- return $this->error('暂未找到该账号');
- }
- }
-
-
- /**
- * 上传图片
- */
- public function upload()
- {
- $folder = 'images';
- $files = request()->file();
- if (empty($files) || $files == null) {
- $this->error('请上传文件');
- }
- $imags = [];
- $errors = [];
- $root = $this->app->getRootPath();
- foreach ($files as $file) {
- if ($folder) { //保存目录
- // 移动到框架应用根目录/public/uploads/ 目录下
- $info = $file->move($root.'/public/upload/'. $folder);
- if ($info) {
- // 成功上传后 获取上传信息
- //echo $info->getFilename();
- // $path = '/uploads/editor/' . $info->getSaveName();
- $path = $folder . '/' . $info->getSaveName();
- $fileName = str_replace('\\', '/', $path);
- array_push($imags, '/' . 'uploads/'.$fileName);
- } else {
- array_push($errors, $file->getError()); // 上传失败获取错误信息
- }
- }
- }
- if (!$errors) {
- $msg['code'] = 1;
- $msg['data'] = $imags;
- return json($msg);
- } else {
- $msg['code'] = 0;
- $msg['data'] = $imags;
- $msg['msg'] = "上传出错";
- return json($msg);
- }
- }
- }
|