作者 郭文星
... ... @@ -231,10 +231,10 @@ class Client extends Api
/*
7.生成二维码 及 规则 https://coupon.xp.yn.cn?store_id=1&activity_id=3
7.生成二维码 及 规则 https://coupon.xp.yn.cn?store_id=1&activity_id=3&share_id=2
二维码 没有则创新
参数 用户id 门店id 活动id
store_id activiy_id
share_id store_id activiy_id
请求需要加 header token
由前端自行合成分销图片
*/
... ... @@ -242,7 +242,7 @@ class Client extends Api
//参数
$param = request()->param();
$user_id = $this->auth->id;
$user_id=2;
//验证
if(empty($user_id)){return $this->error('用户信息错误');}
if(empty($param['store_id'])){return $this->error('请确认门店');}
... ... @@ -253,6 +253,7 @@ class Client extends Api
$r = Db::name('verification_user_synthesis')->where($w)->find();
//有 则 返回 无 则新增
if(empty($r)){
$param['share_id']=$user_id;
$url = (new \app\api\controller\v1\Base())->url_h5.'?'.http_build_query($param);
$res = (new \app\api\controller\v1\Index())->build($url);
$w['create_at'] = time();
... ...
... ... @@ -151,15 +151,18 @@ class Wechat extends Api
https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
2.2 由微信回跳后,获取code 和 state 参数,由前端post code给后台
返回 token 前端存储 每次请求 放在header里
2.3 分销地址 如 https://coupon.xp.yn.cn?store_id=1&activity_id=3
假设 首页地址有参数 store_id activity_id,则表示分销首页,因此
2.3.1 未登录 则跳转官方,需要携带分销参数 登录成功后 获取token,再发送请求 store_id activity_id
2.3.2 已登录 有获取token,再发送请求 store_id activity_id
2.3 分销地址 如 https://coupon.xp.yn.cn?store_id=1&activity_id=3&share_id=2
假设 首页地址有参数 share_id store_id activity_id,则表示分销首页,因此
2.3.1 未登录 则跳转官方,需要携带分销参数 登录成功后 获取token,再发送请求 share_id store_id activity_id
2.3.2 已登录 有获取token,再发送请求 share_id store_id activity_id
无地址参数则不发送请求
*/
public function get_user_info_by_code (){
$user_id = 0;
if(empty(request()->param('code'))){
return $this->error('非法操作');
}
try{
$app = WehcatModule::getInstance()->initWechat();
$oauth = $app->oauth;
... ... @@ -183,12 +186,10 @@ class Wechat extends Api
}else{
Db::name('user')->where($w)->update($save);
}
//设置同域下的登录缓存
$user = Db::name('user')->where($w)->find();
//登录成功 存储服务器本地
$res=$this->auth->direct($user['id']);
//返回给前端
$user_id = $user['id'];
}catch(\Exception $e){
... ... @@ -207,6 +208,38 @@ class Wechat extends Api
/**注册 分销关系 如 https://coupon.xp.yn.cn?store_id=1&activity_id=3&share_id=2
* store_id,activity_id
* 关系 user表 id 和 pid
*/
public function register_relation(){
//参数
$param = request()->param();
if(empty($param['share_id'])){return $this->error('信息错误');}
if(empty($param['store_id'])){return $this->error('门店信息错误');}
if(empty($param['activity_id'])){return $this->error('活动信息错误');}
$my_user_id = $this->auth->id;
if(empty($my_user_id)){return $this->error('用户信息错误');}
//检测是存在关系
$w['id'] = $my_user_id;
$myInfo = Db::name('user')->where($w)->find();
if(empty($myInfo['pid'])){
//更新分销关系
Db::name('user')->where($w)->update(['id'=>$myInfo['pid']]);
return $this->success('更新关系');
}else{
if($myInfo['pid'] == $param['share_id']){
//是我的上线
return $this->success('是我的上线');
}else{
//不是我的上线
return $this->success('不是我的上线');
}
}
}
/*
... ...