1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\api\controller;
- use app\api\model\UsersModel;
- use app\common\controller\Api;
- use think\Db;
- class Login extends Api
- {
- protected $noNeedLogin = '*';
- protected $noNeedRight = '*';
-
- public function Login()
- {
- $data = $this->request->post();
- $rules = [
- 'user_tel' => 'require|max:11|number|min:11',
- 'user_pwd' => 'require|max:25|min:6'
- ];
- $msg = [
- 'user_tel.require' => '手机号不能为空',
- 'user_tel.max' => '手机号长度不正确',
- 'user_tel.min' => '手机号长度不正确',
- 'user_tel.number' => '手机号必须为数字',
- 'user_pwd.require' => '密码不能为空',
- 'user_pwd.max' => '密码长度过长',
- 'user_pwd.min' => '密码长度不足',
- ];
- if (isset($data['user_tel']) && isset($data['user_pwd'])) {
- $validata = $this->validate($data, $rules, $msg);
- if (is_string($validata)) {
- return $this->result($validata, [], 100);
- }
- $valdatatel = UsersModel::where('user_tel', $data['user_tel'])->find();
- if ($valdatatel) {
- $data['user_pwd'] = sha1(md5($data['user_pwd']));
- $validatapwd = UsersModel::where('user_pwd', $data['user_pwd'])->where('user_tel', $data['user_tel'])->find();
- if ($validatapwd) {
- return $this->result('登录成功,欢迎回来', $validatapwd, 200);
- } else {
- return $this->result('密码错误', [], 100);
- }
- } else {
- return $this->result('手机号不存在', [], 100);
- }
- }
- if (isset($data['user_openid'])) {
- $validataopenid = UsersModel::where('user_openid', $data['user_openid'])->find();
- if ($validataopenid) {
- return $this->result('登陆成功,欢迎回来', $validataopenid, 200);
- } else {
- return $this->result('暂无该用户', [], 100);
- }
- }
- }
-
- public function validatatel($tel)
- {
- $tel = UsersModel::where('user_tel', $tel)->find();
- $num = count($tel);
- if ($num > 0) {
- return $this->result('手机号已存在', [], 100);
- }
- }
-
- public function agreement()
- {
- $data = Db::name('agreement')->where('type', 0)->find();
- if ($data) {
- return $this->result('', $data, 200);
- } else {
- return $this->result('网络错误', [], 100);
- }
- }
-
- }
|