接口案例

This commit is contained in:
Anyon 2020-07-14 11:50:00 +08:00
parent a1b74ef396
commit 85ad0106e9
4 changed files with 22 additions and 18 deletions

View File

@ -19,8 +19,7 @@ class Article extends Controller
*/
public function getTags()
{
$table = 'DataArticleTags';
$query = $this->_query($table)->like('title');
$query = $this->_query('DataArticleTags')->like('title');
$query->where(['deleted' => 0, 'status' => 1])->withoutField('sort,status,deleted');
$this->success('获取文章标签列表', $query->order('sort desc,id desc')->page(false, false));
}

View File

@ -33,7 +33,7 @@ class Login extends Controller
'password.require' => '登录密码不能为空!',
]);
$map = ['deleted' => 0, 'phone' => $data['phone']];
$user = $this->app->db->name('DataMember')->where($map)->find();
$user = $this->app->db->name($this->table)->where($map)->find();
if (empty($user)) $this->error('该手机号还没有注册哦!');
if (empty($user['status'])) $this->error('该会员账号状态异常!');
if (md5($data['password']) === $user['password']) {

View File

@ -12,6 +12,11 @@ use app\data\service\MemberService;
*/
class Center extends Member
{
/**
* 绑定数据表
* @var string
*/
protected $table = 'DataMember';
/**
* 更新会员资料
@ -30,7 +35,7 @@ class Center extends Member
]);
foreach ($data as $key => $vo) if ($vo === '') unset($data[$key]);
if (empty($data)) $this->error('没有需要修改的数据!');
if ($this->app->db->name('DataMember')->where(['id' => $this->mid])->update($data) !== false) {
if ($this->app->db->name($this->table)->where(['id' => $this->mid])->update($data) !== false) {
$this->success('更新会员资料成功!', $this->getMember());
} else {
$this->error('更新会员资料失败!');
@ -65,10 +70,10 @@ class Center extends Member
if ($data['from'] == $this->mid) {
$this->error('邀请人不能是自己哦', MemberService::instance()->total($this->mid));
}
$from = $this->app->db->name('DataMember')->where(['id' => $data['from']])->find();
$from = $this->app->db->name($this->table)->where(['id' => $data['from']])->find();
if (empty($from)) $this->error('邀请人状态异常', MemberService::instance()->total($this->mid));
if ($this->member['from'] > 0) $this->error('您已经绑定了邀请人', MemberService::instance()->total($this->mid));
if ($this->app->db->name('DataMember')->where(['id' => $this->mid])->update($data) !== false) {
if ($this->app->db->name($this->table)->where(['id' => $this->mid])->update($data) !== false) {
$this->success('绑定邀请人成功!', MemberService::instance()->total($this->mid));
} else {
$this->error('绑定邀请人失败!', MemberService::instance()->total($this->mid));
@ -83,7 +88,7 @@ class Center extends Member
*/
public function getFrom()
{
$query = $this->_query('DataMember');
$query = $this->_query($this->table);
$query->where(['from' => $this->mid])->field('id,from,user,nickname,headimg,create_at');
$this->success('获取我邀请的朋友', $query->order('id desc')->page(true, false, false, 15));
}

View File

@ -29,8 +29,8 @@ class MemberService extends Service
*/
public function get(string $token, array $data = []): array
{
$map = ['token' => $token, 'deleted' => 0];
$query = $this->app->db->name($this->table)->where($map);
$query = $this->app->db->name($this->table);
$query->where(['token' => $token, 'deleted' => 0]);
$member = $query->withoutField('status,deleted')->find();
if (empty($member)) throw new \think\Exception('会员查询失败');
if ($member['tokenv'] !== $this->buildTokenVerify()) {
@ -60,15 +60,6 @@ class MemberService extends Service
return $this->get($up['token'], $data);
}
/**
* 获取认证信息编码
* @return string
*/
protected function buildTokenVerify(): string
{
return md5($this->app->request->server('HTTP_USER_AGENT', '-'));
}
/**
* 获取会员数据统计
* @param int $mid 会员MID
@ -80,4 +71,13 @@ class MemberService extends Service
return ['myinvited' => $query->where(['from' => $mid])->count()];
}
/**
* 获取认证信息编码
* @return string
*/
private function buildTokenVerify(): string
{
return md5($this->app->request->server('HTTP_USER_AGENT', '-'));
}
}