Connectqq.php 10 KB

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