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