Connectapi.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. namespace app\common\logic;
  3. /**
  4. * ============================================================================
  5. *
  6. * ============================================================================
  7. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  8. * 网站地址: https://www.valimart.net/
  9. * ----------------------------------------------------------------------------
  10. *
  11. * ============================================================================
  12. * 逻辑层模型
  13. */
  14. class Connectapi{
  15. public function smsRegister($phone, $captcha, $password, $client, $inviter_id = 0) {
  16. if ($this->check_captcha($phone, $captcha)) {
  17. if (config('ds_config.sms_register') != 1) {
  18. return array('state' => 0, 'msg' => '系统没有开启手机注册功能');
  19. }
  20. $member_model = model('member');
  21. $member_name = 'phone_' . random(10);
  22. $member = $member_model->getMemberInfo(array('member_name' => $member_name)); //检查重名
  23. if (!empty($member)) {
  24. return array('state' => 0, 'msg' => '用户名已被注册');
  25. }
  26. $member = $member_model->getMemberInfo(array('member_mobile' => $phone)); //检查手机号是否已被注册
  27. if (!empty($member)) {
  28. return array('state' => 0, 'msg' => '手机号已被注册');
  29. }
  30. $member = array();
  31. $member['member_name'] = $member_name;
  32. $member['member_password'] = $password;
  33. $member['member_mobile'] = $phone;
  34. $member['member_email'] = '';
  35. $member['member_mobilebind'] = 1;
  36. $member['inviter_id'] = $inviter_id;
  37. $insert_id = $member_model->addMember($member);
  38. if ($insert_id) {
  39. $member_model->addMemberAfter($insert_id,$member);
  40. $member = $member_model->getMemberInfo(array('member_mobile' => $phone));
  41. $key = $member_model->getBuyerToken($member['member_id'], $member['member_name'], $client);
  42. return array('state' => 1, 'username' => $member_name, 'token' => $key,'info'=>$member);
  43. } else {
  44. return array('state' => 0, 'msg' => '注册失败', $member);
  45. }
  46. }
  47. }
  48. /**
  49. * 手机找回密码
  50. * @param array $order_info
  51. * @param string $phone 手机号码
  52. * @param string $password 密码
  53. * @return array
  54. */
  55. public function smsPassword($phone, $captcha, $password, $client) {
  56. if (config('ds_config.sms_password') != 1) {
  57. return array('state' => 0, 'msg' => '系统没有开启手机找回密码功能');
  58. }
  59. $condition = array();
  60. $condition[] = array('smslog_phone','=',$phone);
  61. $condition[] = array('smslog_captcha','=',$captcha);
  62. $condition[] = array('smslog_type','=',3);
  63. $smslog_model = model('smslog');
  64. $sms_log = $smslog_model->getSmsInfo($condition);
  65. if (empty($sms_log) || ($sms_log['smslog_smstime'] < TIMESTAMP - 1800)) {//半小时内进行验证为有效
  66. return array('state' => 0, 'msg' => '动态码错误或已过期,重新输入');
  67. }
  68. $member_model = model('member');
  69. $member = $member_model->getMemberInfo(array('member_mobile' => $phone)); //检查手机号是否已被注册
  70. if (!empty($member)) {
  71. $new_password = md5($password);
  72. $member_model->editMember(array('member_id' => $member['member_id']), array('member_password' => $new_password),$member['member_id']);
  73. $member_model->createSession($member); //自动登录
  74. if (!$member['member_state']) {
  75. return array('state' => 0, 'msg' => lang('login_index_account_stop'));
  76. }
  77. $key = $member_model->getBuyerToken($member['member_id'], $member['member_name'], $client);
  78. return array('state' => 1, 'msg' => '密码修改成功', 'token' => $key,'info'=>$member);
  79. }
  80. }
  81. public function getStateInfo() {
  82. $data['sms_register'] = config('ds_config.sms_register') == 1 ? 1 : 0;
  83. $data['sms_login'] = config('ds_config.sms_login') == 1 ? 1 : 0;
  84. $data['sms_password'] = config('ds_config.sms_password') == 1 ? 1 : 0;
  85. return $data;
  86. }
  87. /**
  88. * 手机验证码验证
  89. */
  90. protected function check_captcha($phone, $captcha, $type = '1') {
  91. if (strlen($phone) == 11 && strlen($captcha) == 6) {
  92. $condition = array();
  93. $condition[] = array('smslog_phone','=',$phone);
  94. $condition[] = array('smslog_captcha','=',$captcha);
  95. $condition[] = array('smslog_type','=',$type);
  96. $smslog_model = model('smslog');
  97. $sms_log = $smslog_model->getSmsInfo($condition);
  98. if (empty($sms_log) || ($sms_log['smslog_smstime'] < TIMESTAMP - 1800)) {//半小时内进行验证为有效
  99. $state = '动态码错误或已过期,重新输入';
  100. ds_json_encode('10001',$state);
  101. }
  102. return true;
  103. }
  104. return false;
  105. }
  106. /**
  107. * 微信注册
  108. * @param type $reg_info
  109. * @param type $reg_type 自动注册类型 wx qq sina
  110. * @return type
  111. */
  112. public function wx_register($reg_info, $reg_type) {
  113. $reg_info['nickname'] = isset($reg_info['nickname']) ? $reg_info['nickname'] : '';
  114. $reg_info['nickname'] = removeEmoji($reg_info['nickname']);
  115. $member = array();
  116. $member_model = model('member');
  117. if ($reg_type == 'wx' && !empty($reg_info['member_wxunionid'])) {
  118. //如果用户存在.
  119. $exist_member = $member_model->getMemberInfo(array('member_wxunionid' => $reg_info['member_wxunionid']));
  120. if (!empty($exist_member)) {
  121. return $exist_member;
  122. }
  123. $member['member_wxunionid'] = $reg_info['member_wxunionid'];
  124. $member['member_wxopenid'] = $reg_info['member_wxopenid'];
  125. $member['member_wxinfo'] = serialize($reg_info);
  126. }elseif ($reg_type == 'qq' && !empty($reg_info['member_qqopenid'])) {
  127. //如果用户存在.
  128. $exist_member = $member_model->getMemberInfo(array('member_qqopenid' => $reg_info['member_qqopenid']));
  129. if (!empty($exist_member)) {
  130. return $exist_member;
  131. }
  132. $member['member_qqopenid'] = $reg_info['member_qqopenid'];
  133. $member['member_qqinfo'] = serialize($reg_info);
  134. }elseif ($reg_type == 'sina' && !empty($reg_info['member_sinaopenid'])){
  135. //如果用户存在.
  136. $exist_member = $member_model->getMemberInfo(array('member_sinaopenid' => $reg_info['member_sinaopenid']));
  137. if (!empty($exist_member)) {
  138. return $exist_member;
  139. }
  140. $member['member_sinaopenid'] = $reg_info['member_sinaopenid'];
  141. $member['member_sinainfo'] = serialize($reg_info);
  142. }else{
  143. return;
  144. }
  145. $member['member_password'] = rand(100000, 999999);
  146. $member['member_email'] = '';
  147. $member['member_birthday'] = TIMESTAMP;
  148. $member['member_nickname'] = $reg_info['nickname'];
  149. if (isset($reg_info['inviter_id'])) {
  150. $member['inviter_id'] = $reg_info['inviter_id'];
  151. }
  152. /*
  153. $rand = rand(100, 899);
  154. if (empty($reg_info['nickname']))
  155. $reg_info['nickname'] = 'name_' . $rand;
  156. if (strlen($reg_info['nickname']) < 3)
  157. $reg_info['nickname'] = $reg_info['nickname'] . $rand;
  158. $member_name = $reg_info['nickname'];
  159. */
  160. $member_name = $reg_type . '_' . random(10);
  161. $member_info = $member_model->getMemberInfo(array('member_name' => $member_name));
  162. if (empty($member_info)) {
  163. $member['member_name'] = $member_name;
  164. $insert_id = $member_model->addMember($member);
  165. $member_info = $member_model->getMemberInfo(array('member_name' => $member_name));
  166. } else {
  167. for ($i = 1; $i < 999; $i++) {
  168. /*
  169. $rand += $i;
  170. $member_name = $reg_info['nickname'] . $rand;
  171. */
  172. $member_name = $reg_type . '_' . random(10);
  173. $member_info = $member_model->getMemberInfo(array('member_name' => $member_name));
  174. if (empty($member_info)) {//查询为空表示当前会员名可用
  175. $member['member_name'] = $member_name;
  176. $insert_id = $member_model->addMember($member);
  177. break;
  178. }
  179. }
  180. }
  181. if ($insert_id) {
  182. $member_model->addMemberAfter($insert_id,$member_info);
  183. if (0 && isset($reg_info['headimgurl'])) {#提高体验暂时不对图片进行处理
  184. $headimgurl = $reg_info['headimgurl'];
  185. $avatar = @copy($headimgurl, BASE_UPLOAD_PATH . '/' . ATTACH_AVATAR . "/avatar_$insert_id.jpg");
  186. if ($avatar) {
  187. $member_model->editMember(array('member_id' => $insert_id), array('member_avatar' => "avatar_$insert_id.jpg"),$insert_id);
  188. }
  189. }
  190. $member = $member_model->getMemberInfo(array('member_id' => $insert_id));
  191. return $member;
  192. }
  193. }
  194. }