* @version : HUOSDK 8.0 */ namespace huo\controller\member; use huo\controller\common\Base; use huo\controller\integral\MemIa; use huo\model\member\MemberModel; use huolib\constant\IaConst; use huolib\sms\Sms; use huolib\status\MemberStatus; use huolib\tool\StrUtils; use think\Session; class Bind extends Base { /** * 获取已绑定的手机号 * * @param $mem_id * * @return null */ public function getHasBindMobile($mem_id) { $_mem_info = (new MemCache())->getInfoById($mem_id); if (empty($_mem_info) || empty($_mem_info['mobile'])) { return null; } $_mobile = $_mem_info['mobile']; $this->setHasBind($_mobile); return $_mobile; } /** * 发送手机短信 * * @param string $mobile * @param int $type 4 校验 6 绑定手机 * * @return array */ public function smsSend($mobile, $type) { if (!$this->getCheckOk()) { if ($this->getHasBind()) { $mobile = $this->getOldMobile(); } } $_rs = (new Sms())->send($mobile, $type); if (MemberStatus::NO_ERROR == $_rs['code']) { return $this->huoError($_rs['code'], $_rs['msg'], $_rs['data']); } return $this->huoSuccess($_rs['code'], $_rs['msg'], $_rs['data']); } /** * 校验原有手机 * * @param $mobile * @param $code * @param $type */ public function checkOldMobile($mobile, $code, $type) { if ($this->getHasBind()) { $mobile = $this->getOldMobile(); } /* 校验短信是否正确 */ $_sms_rs = (new Sms())->check($mobile, $code, $type); if (MemberStatus::NO_ERROR != $_sms_rs['code']) { return $this->huoError($_sms_rs['code'], $_sms_rs['msg']); } $this->setCheckOk(); $_code = MemberStatus::NO_ERROR; return $this->huoSuccess($_code, MemberStatus::getMsg($_code)); } /** * 绑定手机中更新信息 * * @param int $mem_id * @param string $mobile * @param string $code * @param int $type * @param string $password * * @return array */ public function bindPost($mem_id, $mobile, $code, $type, $password = '') { /* 屏蔽密码 20180130 $_chk_pwd_rs = UserUtils::checkPassword($password); if (MemberStatus::NO_ERROR != $_chk_pwd_rs) { return $this->huoError($_chk_pwd_rs, MemberStatus::getMsg($_chk_pwd_rs)); } */ /* 校验密码是否正确 */ $_mem_class = new Member(); $_mem_data = (new MemCache())->getInfoById($mem_id); if (false == $this->getCheckOk() || !empty($_mem_data['password'])) { /* 绑定需要输入密码 */ /* 屏蔽密码 20180130 $_chk_pwd = $_mem_class->checkPwd($password, $_mem_data['password']); if (false == $_chk_pwd) { $_code = MemberStatus::USERNAME_OR_PASSWORD_ERR; return $this->huoError($_code, MemberStatus::getMsg($_code)); } */ if (empty($mobile)) { $_code = MemberStatus::PHONE_ERROR; return $this->huoError($_code, MemberStatus::getMsg($_code)); } } else { $password = ''; } /* 有绑定手机 请先校验原有手机 */ if ($this->getHasBind() && false == $this->getCheckOk()) { $_code = MemberStatus::PHONE_NOT_CHECK; return $this->huoError($_code, MemberStatus::getMsg($_code)); } /* 校验短信是否正确 */ $_sms_rs = (new Sms())->check($mobile, $code, $type); if (MemberStatus::NO_ERROR != $_sms_rs['code']) { return $this->huoError($_sms_rs['code'], $_sms_rs['msg']); } $_rs = $this->updateData($mem_id, $mobile); if (MemberStatus::NO_ERROR != $_rs) { return $this->huoError($_rs, MemberStatus::getMsg($_rs)); } $_code = MemberStatus::NO_ERROR; /* 手机绑定手机获得积分 */ if (false == $this->getHasBind()) { (new MemIa($mem_id))->doItgAct(IaConst::IA_BIND_MOBILE); } $_member_count = (new MemberModel()) ->getMemNumber($mobile); if ($_member_count > 8){ $_code = MemberStatus::PHONE_BIND_TOOMUCH; return $this->huoError($code, MemberStatus::getMsg($_code)); } $this->clearSession(); return $this->huoSuccess($_code, MemberStatus::getMsg($_code)); } /** * @param int $mem_id * @param string $mobile * @param string $password * * @return int */ public function updateData($mem_id, $mobile, $password = '') { $_mc_class = new MemCache(); if (!empty($password)) { $_mem_data['password'] = $password; } $_mem_data['mobile'] = $mobile; $_rs = $_mc_class->updateMem($mem_id, $_mem_data); if (false !== $_rs) { $_code = MemberStatus::NO_ERROR; } else { $_code = MemberStatus::UNKNOWN_ERROR; } return $_code; } public function clearSession() { Session::set('bind_mobile.has_bind_ok', 0); } /** * 设置是否校验OK * */ public function setCheckOk() { Session::set('bind_mobile.has_bind_ok', 1); } /** * @return bool */ public function getCheckOk() { $_has_bind = Session::get('bind_mobile.has_bind_ok'); if (empty($_has_bind)) { return false; } return true; } public function setHasBind($mobile) { Session::set('bind_mobile.has_bind', 1); $this->setOldMobile($mobile); } public function getHasBind() { $_has_bind = Session::get('bind_mobile.has_bind'); if (empty($_has_bind)) { return false; } return true; } public function setOldMobile($mobile) { Session::set('bind_mobile.old_mobile', $mobile); } public function getOldMobile() { $_old_mobile = Session::get('bind_mobile.old_mobile'); return $_old_mobile; } /** * 获取绑定信息 * * @param $mem_id * * @return array */ public function getBindInfo($mem_id) { $_mc_class = MemCache::ins(); $_mem_data = $_mc_class->getInfoById($mem_id); if (empty($_mem_data)) { $_code = MemberStatus::USERNAME_NOT_EXISTS; return $this->huoError($_code, MemberStatus::getMsg($_code)); } if (!empty($_mem_data['mobile'])) { $this->setHasBind($_mem_data['mobile']); } $_data = [ 'mobile' => (string)StrUtils::encryptPhone($_mem_data['mobile'], 3, 6), 'email' => (string)StrUtils::encryptEmail($_mem_data['email']), ]; return $this->huoSuccess(MemberStatus::NO_ERROR, MemberStatus::getMsg(MemberStatus::NO_ERROR), $_data); } }