123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- namespace App\Http\Controllers\Wap;
- use App\Http\Controllers\FrontController;
- use App\Models\Member;
- use App\Models\Shop;
- use App\Servers\CommonServer;
- use App\Servers\MemberServer;
- use App\Servers\RedisDataServer;
- use App\Servers\WeixinServer;
- class MemberController extends FrontController
- {
- public function __construct()
- {
- parent::__construct();
- }
- function index()
- {
- return view('home.index');
- }
- /**
- * 获取微信会员信息
- */
- function getWxInfo()
- {
- $is_wx = CommonServer::creatServer()->isWeixin();
- if (empty($is_wx)) {
- echo '请使用微信打开';
- } else {
- $redirect_uri = request()->input('redirect_url', '');
- if (empty($redirect_uri)) {
- $redirect_uri = 'http://wap.jhcs888.com/home';
- } else {
- $redirect_uri = base64_decode($redirect_uri);
- }
- if (empty($redirect_uri)) {
- echo '请携带回调地址';
- } else {
- $invite_code = request()->input('inviteCode', '');
- $wx_info = WeixinServer::creatServer()->authorize();
- if ($wx_info) {
- $ret = MemberServer::creatServer()->setWxOpen($wx_info, $invite_code);
- if (empty($ret)) {
- //获取微信信息失败
- echo '登陆失败';
- } else {
- // $ret=array_merge($ret,$data);
- // dd($ret);
- $redirect_uri = str_replace('m_id', 'm_mid', $redirect_uri);
- $redirect_uri = str_replace('token', 'm_token', $redirect_uri);
- $ret = http_build_query($ret);
- if (strpos($redirect_uri, '?') !== false) {
- $redirect_uri .= ('&' . $ret);
- } else {
- $redirect_uri .= ('?' . $ret);
- }
- //跳转至原来的页面
- WeixinServer::creatServer()->redirect($redirect_uri);
- }
- } else {
- echo '获取基本信息失败';
- }
- }
- }
- }
- /**
- * 商户端员工绑定微信
- */
- function staffBind()
- {
- $is_wx = CommonServer::creatServer()->isWeixin();
- $data = ['code' => 0, 'msg' => '信息错误', 'data' => []];
- if (empty($is_wx)) {
- $data['msg'] = '请使用微信打开';
- } else {
- $bindingCode = request()->input('bindingCode', '');
- $staffPhone = request()->input('staffPhone', '');
- $shopId = request()->input('shopId', '');
- if (empty($bindingCode) || empty($staffPhone) || empty($shopId)) {
- $data['msg'] = '缺少必要信息';
- } else {
- if(CommonServer::creatServer()->verifyPhoneNumber($staffPhone)){
- $member = session('login_info');
- if ($member) {
- $isBinding=MemberServer::creatServer()->checkStaffBind($member['m_id']);
- if($isBinding){
- $data['msg'] = '当前微信已绑定,请解绑后再操作';
- }else{
- $shopInfo = Shop::where('id', $shopId)->select(['id', 'shop_logo', 'shop_name'])->first();
- if (empty($shopInfo)) {
- $data['msg'] = '店铺信息错误';
- } else {
- $data['code'] = 1;
- $shopInfo->{'staff_phone'} = $staffPhone;
- $shopInfo->{'binding_code'} = $bindingCode;
- $data['data'] = $shopInfo;
- }
- }
- } else {
- $data['msg'] = '登陆信息错误';
- }
- }else{
- $data['msg'] = '手机号码格式错误';
- }
- }
- }
- $data['wx_js'] = WeixinServer::creatServer()->getJsConfig();
- $data['data'] = json_encode($data['data']);
- return view('home.binding', $data);
- }
- /**
- * 员工绑定操作
- * @return \Illuminate\Http\JsonResponse
- */
- function setBinding()
- {
- $bindingCode = request()->input('binding_code', '');
- $status = request()->input('status', '');
- if (empty($bindingCode)) {
- return $this->apiResponseError('缺少必要参数');
- }
- $member = session('login_info');
- if (empty($member)) {
- return $this->apiResponseError('登陆信息错误');
- }
- $member['status']=$status;
- RedisDataServer::creatServer()->setData($bindingCode,$member,'json',600);
- if($status==1){
- return $this->apiResponseSuccess('绑定成功');
- }else{
- return $this->apiResponseError('绑定已拒绝');
- }
- }
- }
|