mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
修改会员接口
This commit is contained in:
parent
116b22a8b9
commit
04f29ccfc2
77
app/data/controller/api/Login.php
Normal file
77
app/data/controller/api/Login.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\data\controller\api;
|
||||||
|
|
||||||
|
use app\data\service\MemberService;
|
||||||
|
use think\admin\Controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员登录注册接口
|
||||||
|
* Class Login
|
||||||
|
* @package app\data\controller\api
|
||||||
|
*/
|
||||||
|
class Login extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 绑定数据表
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'DataMember';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员登录接口
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function in()
|
||||||
|
{
|
||||||
|
$data = $this->_vali([
|
||||||
|
'code.require' => '验证码不能为空!',
|
||||||
|
'phone.mobile' => '手机号码格式错误!',
|
||||||
|
'phone.require' => '手机号码不能为空!',
|
||||||
|
'password.require' => '登录密码不能为空!',
|
||||||
|
]);
|
||||||
|
$map = ['deleted' => 0, 'phone' => $data['phone']];
|
||||||
|
$user = $this->app->db->name('DataMember')->where($map)->find();
|
||||||
|
if (empty($user)) $this->error('该手机号还没有注册哦!');
|
||||||
|
if (empty($user['status'])) $this->error('该会员账号状态异常!');
|
||||||
|
if (md5($data['password']) !== $user['password']) {
|
||||||
|
$this->success('手机登录成功!', MemberService::instance()->token($user['id']));
|
||||||
|
} else {
|
||||||
|
$this->error('账号登录失败,请稍候再试!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员统一注册入口
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$data = $this->_vali([
|
||||||
|
'username.default' => '',
|
||||||
|
'region_area.default' => '',
|
||||||
|
'region_city.default' => '',
|
||||||
|
'region_province.default' => '',
|
||||||
|
'phone.mobile' => '手机号码格式错误!',
|
||||||
|
'phone.require' => '手机号码不能为空!',
|
||||||
|
'password.require' => '登录密码不能为空!',
|
||||||
|
]);
|
||||||
|
$map = ['phone' => $data['phone'], 'deleted' => 0];
|
||||||
|
if ($this->app->db->name($this->table)->where($map)->count() > 0) {
|
||||||
|
$this->error('手机号已注册,请使用其它手机号!');
|
||||||
|
}
|
||||||
|
$data['password'] = md5($data['password']);
|
||||||
|
if (($mid = $this->app->db->name($this->table)->insertGetId($data)) !== false) {
|
||||||
|
$this->success('会员注册成功!', MemberService::instance()->token($mid));
|
||||||
|
} else {
|
||||||
|
$this->error('手机注册失败!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -30,9 +30,9 @@ class MemberService extends Service
|
|||||||
*/
|
*/
|
||||||
public function get($openid, $data = [])
|
public function get($openid, $data = [])
|
||||||
{
|
{
|
||||||
$map = ['id|openid' => $openid];
|
$map = ['id|openid' => $openid, 'deleted' => 0];
|
||||||
$query = $this->app->db->name($this->table)->where(['deleted' => 0]);
|
$query = $this->app->db->name($this->table)->where($map);
|
||||||
$member = $query->withoutField('status,deleted')->where($map)->find();
|
$member = $query->withoutField('status,deleted')->find();
|
||||||
if (empty($member)) throw new \think\Exception('会员查询失败');
|
if (empty($member)) throw new \think\Exception('会员查询失败');
|
||||||
return array_merge($member, $data);
|
return array_merge($member, $data);
|
||||||
}
|
}
|
||||||
@ -49,7 +49,8 @@ class MemberService extends Service
|
|||||||
*/
|
*/
|
||||||
public function token($openid, $data = [])
|
public function token($openid, $data = [])
|
||||||
{
|
{
|
||||||
$this->app->db->name($this->table)->where(['id|openid' => $openid])->update([
|
$map = ['id|openid' => $openid, 'deleted' => 0];
|
||||||
|
$this->app->db->name($this->table)->where($map)->update([
|
||||||
'token' => CodeExtend::random(20, 3, 't'),
|
'token' => CodeExtend::random(20, 3, 't'),
|
||||||
]);
|
]);
|
||||||
return $this->get($openid, $data);
|
return $this->get($openid, $data);
|
||||||
@ -63,7 +64,7 @@ class MemberService extends Service
|
|||||||
public function total($mid)
|
public function total($mid)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'myinvited' => $this->app->db->name('DataMember')->where(['from' => $mid])->count(),
|
'myinvited' => $this->app->db->name($this->table)->where(['from' => $mid])->count(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user