123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- /**
- * Bind.php UTF-8
- *
- *
- * @date : 2018/5/4 11:57
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\controller\agent;
- use huo\controller\common\Base;
- use huolib\sms\Sms;
- use huolib\status\MemberStatus;
- use think\Session;
- class Bind extends Base {
- /**
- * 获取已绑定的手机号
- *
- * @param int $agent_id
- *
- * @return null
- */
- public function getHasBindMobile($agent_id) {
- $_agent_info = (new AgentCache())->getInfoByAgentId($agent_id);
- if (empty($_agent_info) || empty($_agent_info['mobile'])) {
- return null;
- }
- $_mobile = $_agent_info['mobile'];
- $this->setHasBind($_mobile);
- return $_mobile;
- }
- /**
- * 发送手机短信
- *
- * @param string $mobile
- * @param int $type 4 校验 6 绑定手机
- *
- * @return array
- */
- public function smsSend($mobile, $type) {
- 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
- *
- * @return array
- */
- 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 $agent_id
- * @param string $mobile
- * @param string $code
- * @param int $type
- *
- * @return array
- */
- public function bindPost($agent_id, $mobile, $code, $type) {
- $_ac_class = AgentCache::ins();
- $_agent_data = $_ac_class->getInfoByAgentId($agent_id);
- if (empty($mobile)) {
- $_code = MemberStatus::PHONE_ERROR;
- return $this->huoError($_code, MemberStatus::getMsg($_code));
- }
- /* 有绑定手机 请先校验原有手机 */
- 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']);
- }
- $_agent_data['mobile'] = $mobile;
- $_rs = $_ac_class->updateAgent($agent_id, $_agent_data);
- if (MemberStatus::NO_ERROR != $_rs) {
- return $this->huoError($_rs, MemberStatus::getMsg($_rs));
- }
- $_code = MemberStatus::NO_ERROR;
- $this->clearSession();
- return $this->huoSuccess($_code, MemberStatus::getMsg($_code));
- }
- /**
- *
- */
- public function clearSession() {
- Session::clear('bind_mobile');
- }
- /**
- * 设置是否校验OK
- *
- */
- public function setCheckOk() {
- Session::set('bind_mobile.has_bind_ok', 1);
- }
- /**
- * @return bool
- */
- public function getCheckOk() {
- $_has_bind = Session::get('has_bind_ok', 'bind_mobile');
- 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('has_bind', 'bind_mobile');
- 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('old_mobile', 'bind_mobile');
- return $_old_mobile;
- }
- }
|