Connectqq.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Connectqq extends BaseMall
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/connectqq.lang.php');
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/login-register.lang.php');
  19. /**
  20. * 判断qq互联功能是否开启
  21. */
  22. if (config('ds_config.qq_isuse') != 1) {
  23. $this->error(lang('home_qqconnect_unavailable')); //'系统未开启QQ互联功能'
  24. }
  25. /**
  26. * 初始化测试数据
  27. */
  28. if (!session('openid')) {
  29. $this->error(lang('home_qqconnect_error')); //'系统错误'
  30. }
  31. View::assign('hidden_nctoolbar', 1);
  32. }
  33. /**
  34. * 首页
  35. */
  36. public function index()
  37. {
  38. /**
  39. * 检查登录状态
  40. */
  41. if (session('is_login') == '1') {
  42. //qq绑定
  43. $this->bindqq();
  44. } else {
  45. $this->autologin();
  46. $this->register();
  47. }
  48. }
  49. private function checkWapQQlogin()
  50. {
  51. if ((session('m'))) {
  52. return true;
  53. }
  54. return false;
  55. }
  56. /**
  57. * qq绑定新用户
  58. */
  59. public function register()
  60. {
  61. //实例化模型
  62. $member_model = model('member');
  63. //检查登录状态
  64. $member_model->checkloginMember();
  65. //获取qq账号信息
  66. require_once(PLUGINS_PATH . '/login/qq/user/get_user_info.php');
  67. $qquser_info = get_user_info();
  68. if (request()->isPost()) {
  69. $type = input('param.type');
  70. $user = input('param.user');
  71. $password = input('param.password');
  72. $password2 = input('param.password2');
  73. $reg_info = array(
  74. 'member_qqopenid' => session('openid'),
  75. 'nickname' => isset($qquser_info['nickname']) ? $qquser_info['nickname'] : '',
  76. 'headimgurl' => isset($qquser_info['figureurl_qq_2']) ? $qquser_info['figureurl_qq_2'] : '',
  77. );
  78. $data = array(
  79. 'member_name' => $user,
  80. 'member_password' => $password,
  81. 'member_qqopenid' => $reg_info['member_qqopenid'],
  82. 'member_qqinfo' => serialize($reg_info),
  83. 'member_nickname' => $reg_info['nickname'],
  84. );
  85. if ($type == 1) { //注册
  86. $login_validate = ds_validate('member');
  87. if (!$login_validate->scene('register')->check($data)) {
  88. $this->error($login_validate->getError());
  89. }
  90. $member_info = $member_model->register($data);
  91. if (!isset($member_info['error'])) {
  92. $member_model->createSession($member_info, true);
  93. $headimgurl = $reg_info['headimgurl'];
  94. $avatar = @copy($headimgurl, BASE_UPLOAD_PATH . '/' . ATTACH_AVATAR . "/avatar_" . $member_info['member_id'] . ".jpg");
  95. if ($avatar) {
  96. $member_model->editMember(array('member_id' => $member_info['member_id']), array('member_avatar' => "avatar_" . $member_info['member_id'] . ".jpg"), $member_info['member_id']);
  97. }
  98. } else {
  99. $this->error($member_info['error']);
  100. }
  101. } else { //绑定
  102. $login_validate = ds_validate('member');
  103. if (!$login_validate->scene('login')->check($data)) {
  104. ds_json_encode(10001, $login_validate->getError());
  105. }
  106. $map = array(
  107. 'member_name' => $data['member_name'],
  108. 'member_password' => md5($data['member_password']),
  109. );
  110. $member_info = $member_model->getMemberInfo($map);
  111. if ($member_info) {
  112. $member_model->editMember(array('member_id' => $member_info['member_id']), array('member_qqopenid' => $data['member_qqopenid'], 'member_qqinfo' => $data['member_qqinfo']), $member_info['member_id']);
  113. } else {
  114. $this->error(lang('login_register_bind_fail'));
  115. }
  116. $member_model->createSession($member_info, true);
  117. }
  118. $this->success(lang('ds_common_save_succ'), HOME_SITE_URL);
  119. } else {
  120. if (config('ds_config.auto_register')) { //如果开启了自动注册
  121. $logic_connect_api = model('connectapi', 'logic');
  122. //注册会员信息 返回会员信息
  123. $reg_info = array(
  124. 'member_qqopenid' => session('openid'),
  125. 'nickname' => isset($qquser_info['nickname']) ? $qquser_info['nickname'] : '',
  126. 'headimgurl' => isset($qquser_info['figureurl_qq_2']) ? $qquser_info['figureurl_qq_2'] : '',
  127. );
  128. $wx_member = $logic_connect_api->wx_register($reg_info, 'qq');
  129. if ($wx_member) {
  130. if (!$wx_member['member_state']) {
  131. $this->error(lang('login_index_account_stop'), 'Index/index');
  132. }
  133. $member_model->createSession($wx_member, true);
  134. if ($this->checkWapQQlogin()) {
  135. @header('location: ' . API_SITE_URL . '/index.php/login/qq');
  136. exit;
  137. } else {
  138. $success_message = lang('login_index_login_success');
  139. $this->success($success_message, HOME_SITE_URL);
  140. }
  141. } else {
  142. $this->error(lang('login_usersave_regist_fail'), 'login/register'); //"会员注册失败"
  143. }
  144. } else {
  145. View::assign('qquser_info', $qquser_info);
  146. View::assign('user_passwd', '');
  147. echo View::fetch($this->template_dir . 'connect_register');
  148. }
  149. }
  150. }
  151. /**
  152. * 已有用户绑定QQ
  153. */
  154. public function bindqq()
  155. {
  156. $member_model = model('member');
  157. //验证QQ账号用户是否已经存在
  158. $array = array();
  159. $array['member_qqopenid'] = session('openid');
  160. $member_info = $member_model->getMemberInfo($array);
  161. if (is_array($member_info) && count($member_info) > 0) {
  162. session('openid', null);
  163. $this->error(lang('home_qqconnect_binding_exist'), 'memberconnect/qqbind'); //'该QQ账号已经绑定其他商城账号,请使用其他QQ账号与本账号绑定'
  164. }
  165. //获取qq账号信息
  166. require_once(PLUGINS_PATH . '/login/qq/user/get_user_info.php');
  167. $qquser_info = get_user_info();
  168. $edit_state = $member_model->editMember(array('member_id' => session('member_id')), array(
  169. 'member_qqopenid' => session('openid'), 'member_qqinfo' => serialize($qquser_info)
  170. ), session('member_id'));
  171. if ($edit_state) {
  172. $this->success(lang('home_qqconnect_binding_success'), 'memberconnect/qqbind');
  173. } else {
  174. $this->error(lang('home_qqconnect_binding_fail'), 'memberconnect/qqbind'); //'绑定QQ失败'
  175. }
  176. }
  177. /**
  178. * 绑定qq后自动登录
  179. */
  180. public function autologin()
  181. {
  182. //查询是否已经绑定该qq,已经绑定则直接跳转
  183. $member_model = model('member');
  184. $array = array();
  185. $array['member_qqopenid'] = session('openid');
  186. $member_info = $member_model->getMemberInfo($array);
  187. if (is_array($member_info) && count($member_info) > 0) {
  188. if (!$member_info['member_state']) { //1为启用 0 为禁用
  189. $this->error(lang('login_index_account_stop'));
  190. }
  191. $member_model->createSession($member_info);
  192. //是否有卖家账户
  193. $seller_model = model('seller');
  194. $seller_info = $seller_model->getSellerInfo(array('member_id' => $member_info['member_id']));
  195. if ($seller_info) {
  196. // 更新卖家登陆时间
  197. $seller_model->editSeller(array('last_logintime' => TIMESTAMP), array('seller_id' => $seller_info['seller_id']));
  198. $sellergroup_model = model('sellergroup');
  199. $seller_group_info = $sellergroup_model->getSellergroupInfo(array('sellergroup_id' => $seller_info['sellergroup_id']));
  200. $store_model = model('store');
  201. $store_info = $store_model->getStoreInfoByID($seller_info['store_id']);
  202. $seller_model->createSellerSession($member_info, $store_info, $seller_info, is_array($seller_group_info) ? $seller_group_info : array());
  203. }
  204. if ($this->checkWapQQlogin()) {
  205. @header('location: ' . API_SITE_URL . '/login/type/qq');
  206. exit;
  207. } else {
  208. $success_message = lang('login_index_login_success');
  209. $this->success($success_message, HOME_SITE_URL);
  210. }
  211. }
  212. }
  213. /**
  214. * 更换绑定QQ号码
  215. */
  216. public function changeqq()
  217. {
  218. //如果用户已经登录,进入此链接则显示错误
  219. if (session('is_login') == '1') {
  220. $this->error(lang('home_qqconnect_error'), 'index/index'); //'系统错误'
  221. }
  222. session('openid', null);
  223. @header('Location:' . HOME_SITE_URL . '/api/toqq');
  224. exit;
  225. }
  226. }