Ejemplo n.º 1
0
 public static function memberQueryWinner($app, $member, $replyArr)
 {
     //活动类型ID
     $typeId = Event::getActivityTypeId($replyArr['event_id']);
     $result = BaseActivity::memberGetActivitySession($app['id'], $typeId, $member['id']);
     switch ($result['status']) {
         case ErrorCode::err_activity_manager_not_found:
             return KshNotice::replyText($app, $member, KshParams::ksh_error['error_member_not_in_activity']);
             break;
         case ErrorCode::err_activity_not_exist:
         case ErrorCode::err_activity_session_not_exist:
             return KshNotice::replyText($app, $member, KshParams::ksh_error['error_activity_not_exist']);
             break;
         case ErrorCode::success:
             $managerId = $result['param']['activity']['activity_manager_id'];
             $param = BaseActivity::getActivityParam($app['id'], $typeId, $managerId, 'member_id');
             $memberIdArr = $param['param'];
             $param = BaseActivity::getActivityParam($app['id'], $typeId, $managerId, 'member_answers_results');
             $memberAnswerArr = $param['param'];
             $param = BaseActivity::getActivityParam($app['id'], $typeId, $managerId, 'question_count');
             $quesCount = $param['param'];
             $param = BaseActivity::getActivityParam($app['id'], $typeId, $managerId, 'is_draw');
             $isDraw = $param['param'];
             //检查是否加入活动
             if (!in_array($member['id'], $memberIdArr)) {
                 return KshNotice::replyText($app, $member, KshParams::ksh_error['error_member_not_in_activity']);
             }
             //检查用户是否答过题
             if (empty($memberAnswerArr[$member['id']])) {
                 self::addMemberMsgRecord($app['id'], $typeId, $managerId, $member['id'], $replyArr['cmd_original'], 'error_not_answer_question_yet');
                 return KshNotice::replyText($app, $member, KshParams::ksh_error['error_not_answer_question_yet']);
             }
             //检查是否已开奖
             if (!$isDraw) {
                 self::addMemberMsgRecord($app['id'], $typeId, $managerId, $member['id'], $replyArr['cmd_original'], 'error_activity_is_not_draw');
                 return KshNotice::replyText($app, $member, KshParams::ksh_error['error_activity_is_not_draw']);
             }
             //查询中奖结果
             $rightCount = 0;
             $rightString = '';
             $memberResult = $memberAnswerArr[$member['id']];
             foreach ($memberResult as $ques => $answer) {
                 if ($answer) {
                     $rightCount++;
                     $rightString .= $ques . ', ';
                 }
             }
             if ($rightCount == $quesCount) {
                 self::addMemberMsgRecord($app['id'], $typeId, $managerId, $member['id'], $replyArr['cmd_original'], 'success_answer_all_right');
                 return KshNotice::replyText($app, $member, KshParams::ksh_success['success_answer_all_right']);
             }
             if ($rightCount > 0 && $rightCount < $quesCount) {
                 self::addMemberMsgRecord($app['id'], $typeId, $managerId, $member['id'], $replyArr['cmd_original'], 'error_member_part_right_answer');
                 return KshNotice::replyText($app, $member, sprintf(KshParams::ksh_error['error_member_part_right_answer'], $rightString));
             } else {
                 self::addMemberMsgRecord($app['id'], $typeId, $managerId, $member['id'], $replyArr['cmd_original'], 'error_member_no_right_answer');
                 return KshNotice::replyText($app, $member, KshParams::ksh_error['error_member_no_right_answer']);
             }
             break;
     }
     return false;
 }
Ejemplo n.º 2
0
 public static function answerKsh($app, $user, $replyArr)
 {
     //权限检查
     if ($user['type'] != UserOpenid::TYPE_DOCTOR) {
         return KshNotice::replyText($app, $user, KshParams::ksh_error['error_no_authority_answer_question']);
     }
     //答案编号是否为空
     if (!array_key_exists('cmd_number', $replyArr)) {
         return KshNotice::replyText($app, $user, KshParams::ksh_error['error_empty_member_answer_code']);
     }
     //因为答案中可能有数字相同的编号, 所以多个题目的答案中间不能有分隔符
     $answerString = $replyArr['cmd_number'][0];
     $answerArr = [];
     for ((int) ($i = 0); $i < strlen($answerString); $i++) {
         $answerArr[] = $answerString[$i];
     }
     //获取当前活动session
     $typeId = Event::getActivityTypeId($replyArr['event_id']);
     $result = BaseActivity::memberGetActivitySession($app['id'], $typeId, $user['id']);
     switch ($result['status']) {
         case ErrorCode::err_activity_manager_not_found:
             return KshNotice::replyText($app, $user, KshParams::ksh_error['error_member_not_in_activity']);
             break;
         case ErrorCode::err_activity_not_exist:
         case ErrorCode::err_activity_session_not_exist:
             return KshNotice::replyText($app, $user, KshParams::ksh_error['error_activity_not_exist']);
             break;
         case ErrorCode::success:
             //答题前检查
             $activity = $result['param']['activity'];
             $checkRes = KshUtils::checkBeforeAnswer($app, $typeId, $activity['activity_manager_id'], $user, $answerArr, $replyArr['cmd_original']);
             if ($checkRes != 'success') {
                 return $checkRes;
             }
             //答题
             $answerRes = KshUtils::answer($app['id'], $typeId, $activity['activity_manager_id'], $user['id'], $answerArr);
             if ($answerRes != 'success') {
                 KshUtils::addMemberMsgRecord($app['id'], $typeId, $activity['activity_manager_id'], $user['id'], $replyArr['cmd_original'], 'error_update_activity_status');
                 return KshNotice::replyText($app, $user, KshParams::ksh_error['error_update_activity_status']);
             } else {
                 KshUtils::addMemberMsgRecord($app['id'], $typeId, $activity['activity_manager_id'], $user['id'], $replyArr['cmd_original'], 'success_answer_activity_question');
                 return KshNotice::replyText($app, $user, KshParams::ksh_success['success_answer_activity_question']);
             }
             break;
     }
     return false;
 }