1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace app\api\controller\dinner;
- use app\hander\HelpHander;
- use think\Controller;
- use think\Db;
- class Login extends Controller
- {
- protected $middleware = ['Cross'];
- public function login(){
- $phone = input('phone','','trim');
- $password = input('password','','trim');
- if(!$phone){
- HelpHander::error('请输入手机号');
- }
- if(!$password){
- HelpHander::error('请输入密码');
- }
- $ret = model('DinnerUser')->login($phone,$password);
- HelpHander::success($ret);
- }
- public function autologin(){
- $token = input('token');
- $userId = input('userId');
- if(empty($token) || empty($userId)){
- HelpHander::error('登录信息已失效',100200);
- }
- $tokeninfo = Db::name('token')
- ->where('code',$token)
- ->where('user_id',$userId)
- ->find();
- if(!$tokeninfo){
- HelpHander::error('登录信息已失效',100200);
- }
- // 检查用户是否被禁用
- $user = Db::name('user')->where('id',$userId)->find();
- if(!$user || $user['enable'] == 0 || $user['del'] == 1){
- HelpHander::error('登录信息已失效',100200);
- }
- // 检查点餐用户是否存在
- $duser = Db::name('dinner_user')->where('phone',$user['phone'])->where('del',0)->find();
- if(!$duser || $duser['enable'] != 1){
- HelpHander::error('未注册点餐系统,请联系管理员',100200);
- }
- $token = md5($user['id'].'-'.time().rand(1000,9999));
- $ret = Db::name('dinner_user')->where('id',$duser['id'])->update([
- 'login_time' => date('Y-m-d H:i:s'),
- 'token' => $token
- ]);
- if(!$ret){
- HelpHander::error('登录失败',100200);
- }
- HelpHander::success(['user_id' => $duser['id'], 'token' => $token]);
- }
- public function updatePwd(){
- $phone = input('mobile','','trim');
- $password = input('newPassword','','trim');
- $code = input('code','','trim');
- model('User')->forgetPassword($phone,$password,$code);
- HelpHander::success([],'修改成功');
- }
- }
|