コード例 #1
0
ファイル: Handler.php プロジェクト: suffrajet/gdoctor
 /**
  * Handle GDoctor business command
  *
  * @param $app
  * @param $user
  * @param $replyArr
  * @return message string
  */
 public static function handle($app, $openId, $replyArr)
 {
     $cmdType = self::dispatch($replyArr);
     switch ($cmdType) {
         case self::CMD_ACTIVITY:
             return self::activityPlugin($app, $openId, $replyArr);
             break;
         case self::CMD_SUBSCRIBE:
             return SubscribeHandler::subscribe($app, $openId, $replyArr);
             break;
         case self::CMD_UNSUBSCRIBE:
             return SubscribeHandler::unsubscribe($app, $openId);
             break;
         case self::CMD_REGISTER:
             return RegisterHandler::userRegister($app, $openId, $replyArr);
             break;
         case self::CMD_VALIDATE:
             return RegisterHandler::userValidate($app, $openId, $replyArr);
             break;
         case self::CMD_PUBLIC:
             return ReplyFormat::replyPublic($replyArr);
             break;
         default:
             return false;
             break;
     }
 }
コード例 #2
0
ファイル: Subscribe.php プロジェクト: suffrajet/gdoctor
 /**
  * reply subscribe command
  *
  * @param $replyArr
  * @return Message string
  */
 public static function subscribe($app, $openId, $replyArr)
 {
     $isDelete = UserOpenid::isDelete($app['id'], $openId);
     if ($isDelete) {
         $model = UserOpenid::where(['wechat_id' => $app['id'], 'open_id' => $openId, 'is_delete' => 1])->get()->first();
         if ($model) {
             $model->is_delete = 0;
             $model->updated_at = Carbon::now();
             if ($model->save()) {
                 if (UserCache::addUser($app, $openId)) {
                     return ReplyFormat::replyPublic($replyArr);
                 }
             }
         }
     } else {
         $model = new UserOpenid();
         $model->open_id = $openId;
         $model->is_delete = 0;
         $model->created_at = Carbon::now();
         $model->updated_at = Carbon::now();
         if ($model->save()) {
             if (UserCache::addUser($app, $openId)) {
                 return ReplyFormat::replyPublic($replyArr);
             }
         }
     }
     return false;
 }
コード例 #3
0
ファイル: Handler.php プロジェクト: suffrajet/gdoctor
 /**
  * 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;
     }
 }
コード例 #4
0
ファイル: KshUtils.php プロジェクト: suffrajet/gdoctor
 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;
 }
コード例 #5
0
ファイル: KshActivity.php プロジェクト: suffrajet/gdoctor
 public static function queryPrize($app, $user, $replyArr)
 {
     //TODO 查看当前科室会的奖品
     return ReplyFormat::replyPublic($replyArr);
 }
コード例 #6
0
ファイル: Register.php プロジェクト: suffrajet/gdoctor
 /**
  * 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);
 }