예제 #1
0
 /**
  * 绑定手机
  */
 public function bindMobileAction()
 {
     $mobile = trim($this->_request->getPost('mobile'));
     $code = trim($this->_request->getPost('seccode'));
     $success = array();
     if (empty($mobile) || !Oray_Function::isMobile($mobile)) {
         return $this->json(false, '手机号码不正确');
     }
     if (empty($code)) {
         return $this->json(false, '验证码不能为空');
     }
     /* @var $daoMobile Dao_Md_User_Mobile */
     $daoMobile = $this->getDao('Dao_Md_User_Mobile');
     $bind = $daoMobile->getBind(array('orgid' => $this->_orgId, 'userid' => $this->_user->userId));
     if (null !== $bind && strcasecmp($mobile, $bind['mobile']) === 0) {
         $this->json(false, '新手机不能跟旧的绑定手机相同');
     }
     // 该手机号码是否已经绑定过了
     if ($daoMobile->existBind($mobile)) {
         return $this->json(false, '手机已跟其它用户绑定,请先更改手机');
     }
     if (!$daoMobile->checkCode($this->_orgId, $this->_user->userId, $mobile, $code)) {
         return $this->json(false, '验证码不正确或验证码已过期');
     }
     // 验证码为已用的
     $daoMobile->updateCode($this->_orgId, $this->_user->userId, $mobile, Dao_Md_User_Mobile::STATUS_USED);
     // 删除绑定
     $daoMobile->deleteBind($this->_orgId, $this->_user->userId);
     //添加用户绑定手机
     $ret = $daoMobile->createBind(array('orgid' => $this->_orgId, 'userid' => $this->_user->userId, 'mobile' => $mobile));
     if (!$ret) {
         return $this->json(false, '绑定手机失败,请重新');
     }
     $success['bind'] = true;
     /* @var $daoOrg Dao_Md_Org_Org */
     $daoOrg = $this->getDao('Dao_Md_Org_Org');
     // 本步骤是否已经扩容了
     $quoteMethod = $daoOrg->getQuota(array('orgid' => $this->_orgId, 'method' => 1));
     if (null === $quoteMethod || null !== $quoteMethod && (int) $quoteMethod['status'] != 1) {
         // 取得原来空间大小
         $org = $daoOrg->getOrgById($this->_orgId);
         $params = array('maxquota' => $org->maxQuota + 2000);
         $ret = $daoOrg->updateOrg($this->_orgId, $params);
         if (!$ret) {
             return $this->json(false, '更新图度空间容量失败,请联系客服!');
         }
         // 添加记录
         $daoOrg->createQuota(array('orgid' => $this->_orgId, 'uniqueid' => $this->_user->uniqueId, 'method' => 1, 'status' => 1, 'createtime' => time()));
         $success['quota'] = true;
     }
     return $this->json(true, '绑定手机成功', $success);
 }