MemberController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace App\Http\Controllers\Wap;
  3. use App\Http\Controllers\FrontController;
  4. use App\Models\Member;
  5. use App\Models\Shop;
  6. use App\Servers\CommonServer;
  7. use App\Servers\MemberServer;
  8. use App\Servers\RedisDataServer;
  9. use App\Servers\WeixinServer;
  10. class MemberController extends FrontController
  11. {
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. }
  16. function index()
  17. {
  18. return view('home.index');
  19. }
  20. /**
  21. * 获取微信会员信息
  22. */
  23. function getWxInfo()
  24. {
  25. $is_wx = CommonServer::creatServer()->isWeixin();
  26. if (empty($is_wx)) {
  27. echo '请使用微信打开';
  28. } else {
  29. $redirect_uri = request()->input('redirect_url', '');
  30. if (empty($redirect_uri)) {
  31. $redirect_uri = 'http://wap.jhcs888.com/home';
  32. } else {
  33. $redirect_uri = base64_decode($redirect_uri);
  34. }
  35. if (empty($redirect_uri)) {
  36. echo '请携带回调地址';
  37. } else {
  38. $invite_code = request()->input('inviteCode', '');
  39. $wx_info = WeixinServer::creatServer()->authorize();
  40. if ($wx_info) {
  41. $ret = MemberServer::creatServer()->setWxOpen($wx_info, $invite_code);
  42. if (empty($ret)) {
  43. //获取微信信息失败
  44. echo '登陆失败';
  45. } else {
  46. // $ret=array_merge($ret,$data);
  47. // dd($ret);
  48. $redirect_uri = str_replace('m_id', 'm_mid', $redirect_uri);
  49. $redirect_uri = str_replace('token', 'm_token', $redirect_uri);
  50. $ret = http_build_query($ret);
  51. if (strpos($redirect_uri, '?') !== false) {
  52. $redirect_uri .= ('&' . $ret);
  53. } else {
  54. $redirect_uri .= ('?' . $ret);
  55. }
  56. //跳转至原来的页面
  57. WeixinServer::creatServer()->redirect($redirect_uri);
  58. }
  59. } else {
  60. echo '获取基本信息失败';
  61. }
  62. }
  63. }
  64. }
  65. /**
  66. * 商户端员工绑定微信
  67. */
  68. function staffBind()
  69. {
  70. $is_wx = CommonServer::creatServer()->isWeixin();
  71. $data = ['code' => 0, 'msg' => '信息错误', 'data' => []];
  72. if (empty($is_wx)) {
  73. $data['msg'] = '请使用微信打开';
  74. } else {
  75. $bindingCode = request()->input('bindingCode', '');
  76. $staffPhone = request()->input('staffPhone', '');
  77. $shopId = request()->input('shopId', '');
  78. if (empty($bindingCode) || empty($staffPhone) || empty($shopId)) {
  79. $data['msg'] = '缺少必要信息';
  80. } else {
  81. if(CommonServer::creatServer()->verifyPhoneNumber($staffPhone)){
  82. $member = session('login_info');
  83. if ($member) {
  84. $isBinding=MemberServer::creatServer()->checkStaffBind($member['m_id']);
  85. if($isBinding){
  86. $data['msg'] = '当前微信已绑定,请解绑后再操作';
  87. }else{
  88. $shopInfo = Shop::where('id', $shopId)->select(['id', 'shop_logo', 'shop_name'])->first();
  89. if (empty($shopInfo)) {
  90. $data['msg'] = '店铺信息错误';
  91. } else {
  92. $data['code'] = 1;
  93. $shopInfo->{'staff_phone'} = $staffPhone;
  94. $shopInfo->{'binding_code'} = $bindingCode;
  95. $data['data'] = $shopInfo;
  96. }
  97. }
  98. } else {
  99. $data['msg'] = '登陆信息错误';
  100. }
  101. }else{
  102. $data['msg'] = '手机号码格式错误';
  103. }
  104. }
  105. }
  106. $data['wx_js'] = WeixinServer::creatServer()->getJsConfig();
  107. $data['data'] = json_encode($data['data']);
  108. return view('home.binding', $data);
  109. }
  110. /**
  111. * 员工绑定操作
  112. * @return \Illuminate\Http\JsonResponse
  113. */
  114. function setBinding()
  115. {
  116. $bindingCode = request()->input('binding_code', '');
  117. $status = request()->input('status', '');
  118. if (empty($bindingCode)) {
  119. return $this->apiResponseError('缺少必要参数');
  120. }
  121. $member = session('login_info');
  122. if (empty($member)) {
  123. return $this->apiResponseError('登陆信息错误');
  124. }
  125. $member['status']=$status;
  126. RedisDataServer::creatServer()->setData($bindingCode,$member,'json',600);
  127. if($status==1){
  128. return $this->apiResponseSuccess('绑定成功');
  129. }else{
  130. return $this->apiResponseError('绑定已拒绝');
  131. }
  132. }
  133. }