예제 #1
0
 public function checkIsLoginHeader($user, $request, $app)
 {
     $data = array();
     $userId = $user->getId();
     $data['id'] = $userId;
     if ($userId) {
         $user->setId($userId);
         $user = $app['repository.user']->findById($user);
         if ($user->getStatus() == 0) {
             CommonFunc::alertBack('未激活,请联系管理员或到邮箱激活');
             return;
         }
         $data['id'] = $userId;
         $data['isLogin'] = 1;
         $data['name'] = $user->getName();
         $data['lastLoginTime'] = date("Y-m-d H:i:s", $user->getLastLoginTime());
         $data['integration'] = $user->getIntegration();
         $data['vipStartTime'] = date("Y-m-d H:i:s", $user->getVipStartTime());
         $data['vipEndTime'] = date("Y-m-d H:i:s", $user->getVipEndTime());
         $data['vipTime'] = intval(($user->getVipEndTime() - $user->getVipStartTime()) / (24 * 60 * 60));
         if ($user->getVipEndTime() < time() and $user->getIsVip() == 1) {
             $user = new User();
             $user->setId($userId);
             $user->setIsVip(0);
             $resultChangeIsVip = $app['repository.user']->changeIsVip($user);
             if (!$resultChangeIsVip) {
                 CommonFunc::alertBack('系统错误,请联系管理员');
                 return;
             }
         }
         $data['isVip'] = $user->getIsVip();
         $data['lastSignInTime'] = $user->getLastSignInTime();
         $data['purchasedGoodsId'] = $user->getPurchasedGoodsId();
         $data['shareKey'] = $user->getShareKey();
         if ($data['lastSignInTime'] > strtotime(date("Y-m-d"))) {
             $data['isSignIn'] = 1;
         } else {
             $data['isSignIn'] = 0;
         }
     } else {
         $form = $app['form.factory']->create(new UserLoginType(), $user);
         if ($request->isMethod('POST')) {
             $form->bind($request);
             if ($form->isValid()) {
                 $resultFindByNameAndPassword = $app['repository.user']->findByNameAndPassword($user);
                 if (!$resultFindByNameAndPassword) {
                     CommonFunc::alertBack('账号或密码错误,请重试');
                     return;
                 }
                 if ($resultFindByNameAndPassword->getStatus() == 0) {
                     CommonFunc::alertBack('未激活,请联系管理员或到邮箱激活');
                     return;
                 }
                 $resultFindByNameAndPassword->setLastLoginTime(time());
                 $app['repository.user']->editLastLoginTime($resultFindByNameAndPassword);
                 $resultFindByNameAndPassword->setLastLoginIp(CommonFunc::getIP());
                 $app['repository.user']->editLastLoginIp($resultFindByNameAndPassword);
                 $userId = $resultFindByNameAndPassword->getId();
                 $app['session']->set('userId', $userId);
                 //                    $redirect = $app['url_generator']->generate('userIndex');
                 //                    return $app->redirect($redirect);
                 $user->setId($userId);
                 $user = $app['repository.user']->findById($user);
                 $data['id'] = $userId;
                 $data['isLogin'] = 1;
                 $data['name'] = $user->getName();
                 $data['lastLoginTime'] = date("Y-m-d H:i:s", $user->getLastLoginTime());
                 $data['integration'] = $user->getIntegration();
                 $data['vipStartTime'] = date("Y-m-d H:i:s", $user->getVipStartTime());
                 $data['vipEndTime'] = date("Y-m-d H:i:s", $user->getVipEndTime());
                 $data['vipTime'] = intval(($user->getVipEndTime() - $user->getVipStartTime()) / (24 * 60 * 60));
                 if ($user->getVipEndTime() < time() and $user->getIsVip() == 1) {
                     $user = new User();
                     $user->setId($userId);
                     $user->setIsVip(0);
                     $resultChangeIsVip = $app['repository.user']->changeIsVip($user);
                     if (!$resultChangeIsVip) {
                         CommonFunc::alertBack('系统错误,请联系管理员');
                         return;
                     }
                 }
                 $data['isVip'] = $user->getIsVip();
                 $data['lastSignInTime'] = $user->getLastSignInTime();
                 $data['purchasedGoodsId'] = $user->getPurchasedGoodsId();
                 $data['shareKey'] = $user->getShareKey();
                 if ($data['lastSignInTime'] > strtotime(date("Y-m-d"))) {
                     $data['isSignIn'] = 1;
                 } else {
                     $data['isSignIn'] = 0;
                 }
                 return $data;
             }
         }
         $data['isLogin'] = 0;
         $data['isVip'] = 0;
         $data['form'] = $form->createView();
     }
     return $data;
 }
 public function userUseCardKeyAjaxAction(Request $request, Application $app)
 {
     $userCardKey = $request->query->get('cardKey');
     $userId = $app['session']->get('userId');
     $cardKey = new CardKey();
     $cardKey->setCardKey($userCardKey);
     $cardKeyInfo = $app['repository.cardKey']->findById($cardKey);
     if (!$cardKeyInfo) {
         $result = array('result' => 0, 'msg' => '卡密错误,请重新输入');
         return JsonResponse::create($result);
     }
     $cardKeyStatus = $cardKeyInfo->getStatus();
     if ($cardKeyStatus == -1) {
         $result = array('result' => -7, 'msg' => '卡密已经被删除');
         return JsonResponse::create($result);
     }
     if ($cardKeyStatus == 3) {
         $result = array('result' => -8, 'msg' => '卡密已经被兑换');
         return JsonResponse::create($result);
     }
     $cardKeyClass = new CardKeyClass();
     $cardKeyClass->setId($cardKeyInfo->getCardKeyClassId());
     $cardKeyClassInfo = $app['repository.cardKeyClass']->findById($cardKeyClass);
     if (!$cardKeyClassInfo) {
         $result = array('result' => -1, 'msg' => '卡密类型bug,请联系管理员');
         return JsonResponse::create($result);
     }
     $cardKeyClassType = $cardKeyClassInfo->getIsVipOrInt();
     $cardKeyClassNum = $cardKeyClassInfo->getNumber();
     $nowTime = time();
     if ($cardKeyClassType == 1) {
         $user = new User();
         $user->setId($userId);
         $userInfo = $app['repository.user']->findById($user);
         if ($userInfo->getVipEndTime() < $nowTime) {
             $user->setVipStartTime($nowTime);
             $user->setVipEndTime($nowTime + $cardKeyClassNum * 24 * 60 * 60);
         } else {
             $user->setVipStartTime($userInfo->getVipStartTime());
             $user->setVipEndTime($userInfo->getVipEndTime() + $cardKeyClassNum * 24 * 60 * 60);
         }
         $resultChangeVipTime = $app['repository.user']->changeVipTime($user);
         if ($resultChangeVipTime) {
             $cardKey = new CardKey();
             $cardKey->setStatus(3);
             $cardKey->setCardKey($userCardKey);
             $resultEditStatus = $app['repository.cardKey']->editStatus($cardKey);
             if ($resultEditStatus) {
                 $user = new User();
                 $user->setId($userId);
                 $user->setIsVip(1);
                 if ($userInfo->getIsVip() == 0) {
                     $resultChangeIsVip = $app['repository.user']->changeIsVip($user);
                 } else {
                     $resultChangeIsVip = 1;
                 }
                 if ($resultChangeIsVip) {
                     $result = array('result' => 1, 'msg' => '兑换成功');
                     return JsonResponse::create($result);
                 } else {
                     $result = array('result' => -6, 'msg' => '数据库错误,请联系管理员');
                     return JsonResponse::create($result);
                 }
             } else {
                 $result = array('result' => -3, 'msg' => '数据库错误,请联系管理员');
                 return JsonResponse::create($result);
             }
         } else {
             $result = array('result' => -2, 'msg' => '数据库错误,请联系管理员');
             return JsonResponse::create($result);
         }
     } else {
         if ($cardKeyClassType == 2) {
             $user = new User();
             $user->setId($userId);
             $userInfo = $app['repository.user']->findById($user);
             $user->setIntegration($userInfo->getIntegration() + $cardKeyClassNum);
             $user->setId($userId);
             $resultChangeIntegration = $app['repository.user']->changeIntegration($user);
             if ($resultChangeIntegration) {
                 $cardKey = new CardKey();
                 $cardKey->setStatus(3);
                 $cardKey->setCardKey($userCardKey);
                 $resultEditStatus = $app['repository.cardKey']->editStatus($cardKey);
                 if ($resultEditStatus) {
                     $result = array('result' => 1, 'msg' => '兑换成功');
                     return JsonResponse::create($result);
                 } else {
                     $result = array('result' => -5, 'msg' => '数据库错误,请联系管理员');
                     return JsonResponse::create($result);
                 }
             } else {
                 $result = array('result' => -4, 'msg' => '数据库错误,请联系管理员');
                 return JsonResponse::create($result);
             }
         }
     }
 }