Connectqq.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Connectqq extends BaseMall {
  18. public function initialize() {
  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. if (session('is_login') == '1') {
  44. //qq绑定
  45. $this->bindqq();
  46. } else {
  47. $this->autologin();
  48. $this->register();
  49. }
  50. }
  51. private function checkWapQQlogin() {
  52. if ((session('m'))) {
  53. return true;
  54. }
  55. return false;
  56. }
  57. /**
  58. * qq绑定新用户
  59. */
  60. public function register() {
  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. $member_model = model('member');
  156. //验证QQ账号用户是否已经存在
  157. $array = array();
  158. $array['member_qqopenid'] = session('openid');
  159. $member_info = $member_model->getMemberInfo($array);
  160. if (is_array($member_info) && count($member_info) > 0) {
  161. session('openid', null);
  162. $this->error(lang('home_qqconnect_binding_exist'), 'memberconnect/qqbind'); //'该QQ账号已经绑定其他商城账号,请使用其他QQ账号与本账号绑定'
  163. }
  164. //获取qq账号信息
  165. require_once(PLUGINS_PATH . '/login/qq/user/get_user_info.php');
  166. $qquser_info = get_user_info();
  167. $edit_state = $member_model->editMember(array('member_id' => session('member_id')), array(
  168. 'member_qqopenid' => session('openid'), 'member_qqinfo' => serialize($qquser_info)
  169. ),session('member_id'));
  170. if ($edit_state) {
  171. $this->success(lang('home_qqconnect_binding_success'), 'memberconnect/qqbind');
  172. } else {
  173. $this->error(lang('home_qqconnect_binding_fail'), 'memberconnect/qqbind'); //'绑定QQ失败'
  174. }
  175. }
  176. /**
  177. * 绑定qq后自动登录
  178. */
  179. public function autologin() {
  180. //查询是否已经绑定该qq,已经绑定则直接跳转
  181. $member_model = model('member');
  182. $array = array();
  183. $array['member_qqopenid'] = session('openid');
  184. $member_info = $member_model->getMemberInfo($array);
  185. if (is_array($member_info) && count($member_info) > 0) {
  186. if (!$member_info['member_state']) {//1为启用 0 为禁用
  187. $this->error(lang('login_index_account_stop'));
  188. }
  189. $member_model->createSession($member_info);
  190. //是否有卖家账户
  191. $seller_model = model('seller');
  192. $seller_info = $seller_model->getSellerInfo(array('member_id' => $member_info['member_id']));
  193. if ($seller_info) {
  194. // 更新卖家登陆时间
  195. $seller_model->editSeller(array('last_logintime' => TIMESTAMP), array('seller_id' => $seller_info['seller_id']));
  196. $sellergroup_model = model('sellergroup');
  197. $seller_group_info = $sellergroup_model->getSellergroupInfo(array('sellergroup_id' => $seller_info['sellergroup_id']));
  198. $store_model = model('store');
  199. $store_info = $store_model->getStoreInfoByID($seller_info['store_id']);
  200. $seller_model->createSellerSession($member_info, $store_info, $seller_info, is_array($seller_group_info) ? $seller_group_info : array());
  201. }
  202. if ($this->checkWapQQlogin()) {
  203. @header('location: ' . API_SITE_URL . '/login/type/qq');
  204. exit;
  205. } else {
  206. $success_message = lang('login_index_login_success');
  207. $this->success($success_message, HOME_SITE_URL);
  208. }
  209. }
  210. }
  211. /**
  212. * 更换绑定QQ号码
  213. */
  214. public function changeqq() {
  215. //如果用户已经登录,进入此链接则显示错误
  216. if (session('is_login') == '1') {
  217. $this->error(lang('home_qqconnect_error'), 'index/index'); //'系统错误'
  218. }
  219. session('openid', null);
  220. @header('Location:' . HOME_SITE_URL . '/api/toqq');
  221. exit;
  222. }
  223. }