getMember( )获取会员信息

/**
* 获取会员(应用如需要使用会员登录,请使用本函数获取会员)
* 请区别 函数 getMemberInfo
* @return bool|mixed
*/
function getMember($member_id = '')
{
$friendModel = new \app\common\model\MpFriends();
if ($member_id) {
$member = $friendModel->getMemberInfo(['id' => $member_id]);
} else {
if (!$mid = input('mid')) {
exit('公众号标识mid不存在');
}
$c = cookie('member_' . $mid) ? cookie('member_' . $mid) : [];
$s = session('member_' . $mid) ? session('member_' . $mid) : [];
$member = array_merge($c, $s);
}
if (!empty($member)) {
$group = \think\Db::name('member_group')->where(['mpid' => $member['mpid']])->order('up_score ASC,up_money ASC,discount ASC')->select();
$group_id = '0';
$group_name = '';
if (!empty($group)) {
$model = new \app\common\model\MemberWealthRecord();
$score = $model->getMemberScoreBySum($member['id'], $member['mpid']);
$money = $model->getMemberMoneyBySum($member['id'], $member['mpid']);

foreach ($group as $key => $val) {
if ($val['up_type'] == '0') {
if ($score > $val['up_score'] || $money > $val['up_money']) {
$group_id = $val['gid'];
$group_name = $val['group_name'];
}
} elseif ($val['up_type'] == '1') {
if ($score > $val['up_score'] && $money > $val['up_money']) {
$group_id = $val['gid'];
$group_name = $val['group_name'];
}
}
}
$friendModel->updateMember(['id' => $member['id']], ['group_id' => $group_id]);
}
$member = $friendModel->getMemberInfo(['id' => $member['id']]);//可能COOKIE SESSION缓存原因 重新获取最新会员数据
if (!empty($member)) {
$group = \think\Db::name('member_group')->where(['gid' => $member['group_id']])->field('gid,group_name,discount')->find();
if (!empty($group)) {
$member['gid'] = $group['gid'];
$member['group_name'] = $group['group_name'];
$member['discount'] = $group['discount'];
} else {
$member['gid'] = '';
$member['group_name'] = '';
$member['discount'] = '';
}
return json_decode(json_encode($member), true);
} else {
//考虑没有认证号获取基本信息
return false;
}
} else {
return false;
}
}

0 个评论

要回复文章请先登录注册