Connectapi.php 9.7 KB

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