Exemplo n.º 1
0
 /**
  * Handler activity by command
  *
  * @param $app WechatApp
  * @param $user User
  * @return string message
  */
 public static function handle($app, $openId, $replyArr)
 {
     $user = UserCache::getByOpenId($app, $openId);
     $eventCode = Event::getEventCode($replyArr['event_id']);
     if (!$user) {
         SysLog::error(__FILE__, __METHOD__, __LINE__, 'user not found by openid');
         return false;
     }
     if (!$user['mobile']) {
         return ReplyFormat::replyText(SysParams::sys_error['error_user_not_register']);
     }
     switch ($eventCode) {
         case self::ACTIVITY_INIT:
             return KshActivity::startKsh($app, $user, $replyArr, $user['time_out']);
             break;
         case self::ACTIVITY_CLOSE:
             return KshActivity::stopKsh($app, $user, $replyArr);
             break;
         case self::ACTIVITY_DRAW:
             return KshActivity::drawKsh($app, $user, $replyArr);
             break;
         case self::QUESTION_BROWSE:
             return KshActivity::browseKshQuestionStore($app, $user, $replyArr);
             break;
         case self::PRIZE_BROWSE:
             return KshActivity::browseKshPrizeStore($app, $user, $replyArr);
             break;
         case self::ACTIVITY_JOIN:
             return KshActivity::joinKsh($app, $user, $replyArr);
             break;
         case self::ACTIVITY_ANSWER:
             return KshActivity::answerKsh($app, $user, $replyArr);
             break;
         case self::QUERY_WINNER:
             return KshActivity::queryWinner($app, $user, $replyArr);
             break;
         case self::QUERY_PRIZE:
             return KshActivity::queryPrize($app, $user, $replyArr);
             break;
             //            case self::QUESTION_CHOOSE:
             //                return Ksh::setActivityQuestion($app, $user, $replyArr);
             //                break;
             //            case self::PRIZE_CHOOSE:
             //                return Ksh::setActivityPrize($app, $user, $replyArr);
             //                break;
         //            case self::QUESTION_CHOOSE:
         //                return Ksh::setActivityQuestion($app, $user, $replyArr);
         //                break;
         //            case self::PRIZE_CHOOSE:
         //                return Ksh::setActivityPrize($app, $user, $replyArr);
         //                break;
         default:
             return false;
             break;
     }
 }
Exemplo n.º 2
0
 public static function queryWinner($app, $user, $replyArr)
 {
     //只有注册的活动管理着参加活动的注册用户可以查看活动中奖情况
     if ($user['type'] == UserOpenid::TYPE_MANAGER) {
         return KshUtils::managerQueryWinner($app, $user, $replyArr);
     } else {
         if ($user['type'] == UserOpenid::TYPE_DOCTOR) {
             return KshUtils::memberQueryWinner($app, $user, $replyArr);
         } else {
             return ReplyFormat::replyText(KshParams::ksh_error['error_no_authority_query_win']);
         }
     }
 }
Exemplo n.º 3
0
 public static function managerQueryWinner($app, $manager, $replyArr)
 {
     //活动类型ID
     $typeId = Event::getActivityTypeId($replyArr['event_id']);
     $result = BaseActivity::managerGetActivitySession($app['id'], $typeId, $manager['id']);
     switch ($result['status']) {
         case ErrorCode::err_activity_session_not_exist:
         case ErrorCode::err_activity_not_exist:
             return ReplyFormat::replyText(KshParams::ksh_error['error_activity_not_exist']);
             break;
         case ErrorCode::success:
             $param = BaseActivity::getActivityParam($app['id'], $typeId, $manager['id'], 'member_count');
             $memberCount = $param['param'];
             $param = BaseActivity::getActivityParam($app['id'], $typeId, $manager['id'], 'member_id');
             $memberIdArr = $param['param'];
             $param = BaseActivity::getActivityParam($app['id'], $typeId, $manager['id'], 'member_answers_results');
             $memberAnswerArr = $param['param'];
             $param = BaseActivity::getActivityParam($app['id'], $typeId, $manager['id'], 'question_count');
             $quesCount = $param['param'];
             $param = BaseActivity::getActivityParam($app['id'], $typeId, $manager['id'], 'prize_count');
             $prizeCount = $param['param'];
             $param = BaseActivity::getActivityParam($app['id'], $typeId, $manager['id'], 'is_draw');
             $isDraw = $param['param'];
             //检查活动题目是否设置
             if ($quesCount == 0) {
                 return ReplyFormat::replyText(KshParams::ksh_error['error_activity_question_not_set']);
             }
             //检查活动奖品是否设置
             if ($prizeCount == 0) {
                 return ReplyFormat::replyText(KshParams::ksh_error['error_activity_prize_not_set']);
             }
             //统计
             $winner = [];
             foreach ($memberIdArr as $memberId) {
                 $rightCount = 0;
                 $memberResult = $memberAnswerArr[$memberId];
                 foreach ($memberResult as $ques => $answer) {
                     if ($answer) {
                         $rightCount++;
                     }
                 }
                 if ($rightCount == $quesCount) {
                     $winner[] = $memberId;
                 }
             }
             //中奖人数
             $winnerCount = count($winner);
             //中奖着手机后4位尾号
             $mobileString = '';
             $Doctors = Doctor::whereIn('id', $winner)->get();
             foreach ($Doctors as $doctor) {
                 $mobileString .= substr_replace($doctor['mobile'], '****', 3, 4) . ', ' . PHP_EOL;
             }
             //检查是否开奖
             if (!$isDraw) {
                 return ReplyFormat::replyText(KshParams::ksh_error['error_manager_not_draw_activity']);
             } else {
                 //没有中奖的
                 if ($winnerCount == 0) {
                     return ReplyFormat::replyText(sprintf(KshParams::ksh_error['error_activity_no_winner'], $memberCount, $winnerCount));
                 } else {
                     if ($winnerCount > 0 && $winnerCount <= $memberCount) {
                         return ReplyFormat::replyText(sprintf(KshParams::ksh_success['success_query_winners'], $memberCount, $winnerCount, $mobileString));
                     }
                 }
             }
             break;
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * Validate mobile
  *
  * @param $app
  * @param $user
  * @param $replyArr
  * @return message string
  */
 public static function userValidate($app, $openId, $replyArr)
 {
     $user = UserCache::getByOpenId($app, $openId);
     if (!$user) {
         SysLog::error(__FILE__, __METHOD__, __LINE__, 'user not found by openid');
         return false;
     }
     if (!array_key_exists('cmd_number', $replyArr)) {
         return ReplyFormat::replyText(SysParams::sys_error['error_empty_validate_code']);
     }
     //验证码
     $code = $replyArr['cmd_number'][0];
     //验证码位数错误
     if (strlen($code) != 6) {
         return ReplyFormat::replyText(SysParams::sys_error['error_invalid_validate_code']);
     }
     //检查验证码正确性
     $data = self::validateRegisterCode($app, $user, $code);
     if (!$data) {
         return ReplyFormat::replyText(SysParams::sys_error['error_wrong_validate_code']);
     }
     //用户注册处理
     $isReg = self::registerHandle($app, $user, $data['mobile']);
     if (!$isReg) {
         return false;
     }
     return ReplyFormat::replyPublic($replyArr);
 }