/** * 获取APP中所有分享成功的相关数据 * @param $userId * @param $shareType * @param $shareId * @param $platform * @return array */ public function postShareInfo($userId, $shareType, $shareId, $platform) { $data = array(); $nowTime = date("Y-m-d H-i-s"); //当前时间 try { Yii::app()->cnhutong_user->createCommand()->insert('log_user_share', array('user_id' => $userId, 'share_type' => $shareType, 'share_id' => $shareId, 'platform' => $platform, 'create_ts' => $nowTime)); // 当前日期分享的次数 $count = count(self::IssetShare($userId)); if ($count > 5) { $pointChange = 0; } else { $pointChange = 1; } $change = $pointChange; $reason = 7; // 积分变化类型 scoreChangeByReason($reason) 获得类型 $scoreRest = UserScoreHistory::model()->getPoint($userId) + $pointChange; $createTs = $nowTime; $memo = null; // 积分变化记录历史 $scoreHistory = UserScoreHistory::model()->insertScoreHistory($userId, $change, $reason, $scoreRest, $createTs, $memo); $scoreUpdate = UserScoreHistory::model()->updateUserScore($userId, $scoreRest); $data['point'] = $pointChange; } catch (Exception $e) { error_log($e); } return $data; }
/** * 用户绑定手机 * @param $mobile * @param $password * @param $checkNum * @param $token * @param $userId * @param $referee * @return array */ public function bindMobile($mobile, $password, $checkNum, $token, $userId, $referee) { $data = array(); $nowTime = date("Y-m-d H:m:i"); try { $user = self::IsUserId($userId); if (!$user) { return 20008; // MSG_ERR_FAIL_USER } $userToken = UserToken::model()->IsToken($userId, $token); // var_dump($userToken);exit; if (!$userToken) { return 20007; // MSG_ERR_FAIL_TOKEN } $mobile_checkcode = LogMobileCheckcode::model()->checkCode($mobile, $checkNum); if (!$mobile_checkcode) { return 20003; // MSG_ERR_CODE_OVER_TIME } // 用户手机绑定成功后 update $recommand = self::getUserByMobile($referee); // 推荐人用户ID if (!$recommand) { $recommand = null; } Yii::app()->cnhutong_user->createCommand()->update('user', array('mobile' => $mobile, 'password' => $password, 'recommand' => $recommand), 'id = :userId', array(':userId' => $userId)); // 绑定手机号成功,验证码使用后改变验证码status状态 Yii::app()->cnhutong_user->createCommand()->update('log_mobile_checkcode', array('status' => 1), 'mobile = :mobile', array(':mobile' => $mobile)); //用户昵称,积分,等级 $userMessage = self::getUserMessageByUserId($userId); $data['nickname'] = $userMessage['username']; // 绑定手机(注册)成功,增加积分 $change = 200; // 绑定手机/注册 增加200积分 $reason = 3; // 积分变化类型 scoreChangeByReason($reason) 获得类型 $scoreRest = UserScoreHistory::model()->getPoint($userId) + $change; $createTs = $nowTime; $memo = null; // 积分变化记录历史 $scoreHistory = UserScoreHistory::model()->insertScoreHistory($userId, $change, $reason, $scoreRest, $createTs, $memo); $scoreUpdate = UserScoreHistory::model()->updateUserScore($userId, $scoreRest); } catch (Exception $e) { error_log($e); } return $data; }
/** * action_id : 2114 * 用户在app中获取积分历史 * @token $token string --登录token * @userId $userId int --用户id * @return result 调用返回结果 * @return msg 调用返回结果说明 * @return data 调用返回数据 */ public function actionGetUserPointHistory() { if (!isset($_REQUEST['token']) || !isset($_REQUEST['userId']) || !isset($_REQUEST['historyId'])) { $this->_return('MSG_ERR_LESS_PARAM'); } $token = Yii::app()->request->getParam('token', NULL); $userId = Yii::app()->request->getParam('userId', NULL); $historyId = Yii::app()->request->getParam('historyId', NULL); if (!ctype_digit($userId)) { $this->_return('MSG_ERR_FAIL_USER'); } if (!ctype_digit($historyId)) { $this->_return('MSG_ERR_HISTORY_ID'); } // 用户user/token验证 $userToken = UserToken::model()->IsToken($userId, $token); if (!$userToken) { $this->_return('MSG_ERR_FAIL_TOKEN'); // MSG_ERR_FAIL_TOKEN } $data = UserScoreHistory::model()->userPointHistory($userId, $historyId); if ($data === 20030) { $this->_return('MSG_ERR_NULL_HISTORY'); } // TODO : add log $actionId = 2114; $params = ''; foreach ($_REQUEST as $key => $value) { $params .= $key . '=' . $value . '&'; } LogUserAction::model()->userAction($userId, $actionId, $params); $this->_return('MSG_SUCCESS', $data); }
/** * 用户在app中进行抽奖,以获取相关积分 * @param $userId * @return array|int */ public function prizeSign($userId) { $data = array(); $nowTime = date("Y-m-d H:i:s"); try { // 调用此方法说明用户当前抽奖,更新user_daily_sign数据 // 验证是否可以抽奖 $prizeFlag = self::flag($userId)['prizeFlag']; // var_dump($prizeFlag);exit; if ($prizeFlag == 0) { return 20027; } $change = rand(1, 500); // 用户抽奖后获取的积分值 $reason = 2; // 积分变化类型 scoreChangeByReason($reason) 获得类型 $scoreRest = UserScoreHistory::model()->getPoint($userId) + $change; $createTs = $nowTime; // 抽奖后改变抽奖状态为0,即不可抽奖; 修改签到天数为1;记录抽奖日期 Yii::app()->cnhutong_user->createCommand()->update('user_daily_sign', array('sign_days' => 1, 'prize_flag' => 0, 'last_prize_ts' => $nowTime), 'user_id = :userId', array(':userId' => $userId)); // 积分变化记录历史 $scoreHistory = UserScoreHistory::model()->insertScoreHistory($userId, $change, $reason, $scoreRest, $createTs, $memo = null); $scoreUpdate = UserScoreHistory::model()->updateUserScore($userId, $scoreRest); $data['point'] = UserScoreHistory::model()->getPoint($userId); if ($change >= 0) { $change = '+' . $change; } else { $change = '-' . $change; } $data['pointChange'] = $change; $sign = self::flag($userId); $data['signDays'] = $sign['signDays']; $data['signFlag'] = $sign['signFlag']; $data['prizeFlag'] = $sign['prizeFlag']; } catch (Exception $e) { error_log($e); } return $data; }
/** * 学员对上过的课时进行评价和打分 * @param $userId -- 用户ID * @param $token -- 用户验证token * @param $memberId -- 用户当前绑定的学员对对应的ID * @param $lessonStudentId -- 课时唯一编号 * @param teachAttitude -- 学员给教学态度的评分,1-5分 * @param teachContent -- 学员给教学内容的评分,1-5分 * @param teachEnvironment -- 学员给教学环境的评分,1-5分 * @param $stateComment -- 课时评价,可以为空 * @return array|int */ public function lessonStudent($userId, $token, $memberId, $lessonStudentId, $teachAttitude, $teachContent, $teachEnvironment, $stateComment) { $nowTime = date("Y-m-d H-i-s"); //当前时间 $data = array(); try { // 用户ID验证 $user = User::model()->IsUserId($userId); if (!$user) { return 20008; // MSG_ERR_FAIL_USER } // 用户token验证 $userToken = UserToken::model()->IsToken($userId, $token); // var_dump($userToken);exit; if (!$userToken) { return 20007; // MSG_ERR_FAIL_TOKEN } $isExistUserMemberId = UserMember::model()->IsExistMemberId($userId, $memberId); if (!$isExistUserMemberId) { return 200017; // MSG_ERR_FAIL_MEMBER } $isLessonStudentId = self::IsLessonStudentId($memberId, $lessonStudentId); if (!$isLessonStudentId) { return 20021; } if ($teachAttitude < 0 || $teachAttitude > 5 || ($teachContent < 0 || $teachContent > 5) || ($teachEnvironment < 0 || $teachEnvironment > 5)) { return 20022; } $issetEval = self::IssetEval($memberId, $lessonStudentId); if ($issetEval) { return 20024; } // insert 学生对课程评分和评价 $eval = Yii::app()->cnhutong_user->createCommand()->insert('lesson_student_eval', array('member_id' => $memberId, 'lesson_student_id' => $lessonStudentId, 'teach_attitude' => $teachAttitude, 'teach_content' => $teachContent, 'teach_environment' => $teachEnvironment, 'statement' => $stateComment, 'create_ts' => $nowTime)); // 连接 CMS 数据库系统, 更新课时评价数据 $score = $teachAttitude + $teachContent + $teachEnvironment; // cms系统评分为教学三项评分总和 $result = Yii::app()->cnhutong->createCommand()->update('ht_lesson_student', array('student_rating' => $score, 'student_comment' => $stateComment), 'student_id = :studentId And id = :id', array(':studentId' => $memberId, ':id' => $lessonStudentId)); // 课程评价 // 学员评价课程,积分增加 50 $change = 50; $reason = 5; // 积分变化类型 scoreChangeByReason($reason) 获得类型 $scoreRest = UserScoreHistory::model()->getPoint($userId) + $change; $createTs = $nowTime; $memo = null; // 积分变化记录历史 $scoreHistory = UserScoreHistory::model()->insertScoreHistory($userId, $change, $reason, $scoreRest, $createTs, $memo); $scoreUpdate = UserScoreHistory::model()->updateUserScore($userId, $scoreRest); // $data = $result; } catch (Exception $e) { error_log($e); } return $data; }
/** * 用户完成测试试卷后提交试卷 * @param $userId * @param $token * @param $testId * @param $answer * @return array */ public function postTestAnswer($userId, $token, $testId, $answer) { $nowTime = date("Y-m-d H-i-s", strtotime("now")); //当前时间; $data = array(); try { // 用户ID验证 $user = User::model()->IsUserId($userId); if (!$user) { return 20008; // MSG_ERR_FAIL_USER } // 用户token验证 $userToken = UserToken::model()->IsToken($userId, $token); // var_dump($userToken);exit; if (!$userToken) { return 20007; // MSG_ERR_FAIL_TOKEN } // 测试编号testId验证 $userTestId = self::IsTestId($testId); if (!$userTestId) { return 20012; // MSG_ERR_FAIL_TESTID } // 3-2|2-1|4-1234 拆分为 数组 3-2,2-1,4-1234 $question_answer = explode("|", $answer); // var_dump($question_answer); $len = count($question_answer); // var_dump($len); // 一维数组 3-1,2-1,4-1234 拆分为二位数组 $questions = array(); for ($i = 0; $i < $len; $i++) { $questions[$i] = explode('-', $question_answer[$i]); } $q = ''; $a = ''; // $q 题目ID字符串 以‘|’连接 // $a 题目答案字符串 以 ‘|’ 连接 for ($j = 0; $j < count($questions); $j++) { $q .= $questions[$j][0] . '|'; $a .= $questions[$j][1] . '|'; } $q = rtrim($q, "|"); $a = rtrim($a, "|"); // var_dump($questions); // var_dump($q); // var_dump($a); $rightAnswer = ''; $rightAnswer = Yii::app()->cnhutong_user->createCommand()->select('question_id, answers')->from('user_question_history')->where('id = :testId And user_id = :userId', array(':testId' => $testId, ':userId' => $userId))->queryRow(); // var_dump($rightAnswer);exit; // 答案数组 $aAnswer = explode('|', $a); // var_dump($aAnswer); // 题目ID数组 $aQuestion = explode('|', $q); // 比对生成题目ID的顺序与提交题目ID的顺序是否相同,如果不同,报错 // 正确答案数组 $aRightAnswer = explode('|', $rightAnswer['answers']); // var_dump($aRightAnswer);exit; // 正确题目ID数组 $aRightQuestion = explode('|', $rightAnswer['question_id']); // var_dump($aRightQuestion); // var_dump($aQuestion); // 比对题目数组交集 $count = count(array_intersect_assoc($aRightQuestion, $aQuestion)); // var_dump(array_intersect_assoc($aRightQuestion, $aQuestion)); // var_dump($count); // 实际题目数量 $num = count($aQuestion); // var_dump($num); if ($count !== $num) { return 20023; } // 比对答案得出分数 $score = count(array_intersect_assoc($aRightAnswer, $aAnswer)) * 20; // var_dump($score); // var_dump(array_intersect_assoc($aRightAnswer, $aAnswer)); // 提交答案比对生成题库答案,得出分数score,更新得分等数据 $scoreResult = Yii::app()->cnhutong_user->createCommand()->update('user_question_history', array('update_ts' => $nowTime, 'post_answer' => $a, 'score' => $score), 'id = :testId And user_id = :userId', array(':testId' => $testId, ':userId' => $userId)); // 答题得积分 (用户每天首轮答题,1题2积分) $point = count(array_intersect_assoc($aRightAnswer, $aAnswer)) * 2; // 答对题数获得的积分,1题2分 $count = count(self::IssetQuestion($userId)); if ($count > 1) { $pointChange = 0; } else { $pointChange = $point; } $change = $pointChange; $reason = 6; // 积分变化类型 scoreChangeByReason($reason) 获得类型 $scoreRest = UserScoreHistory::model()->getPoint($userId) + $pointChange; $createTs = $nowTime; $memo = null; // 积分变化记录历史 $scoreHistory = UserScoreHistory::model()->insertScoreHistory($userId, $change, $reason, $scoreRest, $createTs, $memo); $scoreUpdate = UserScoreHistory::model()->updateUserScore($userId, $scoreRest); // 获得此课程类型的所有答题分数 $scores = self::getAllScores($testId); // 得分在分数组中位置 $num = array_search($score, $scores) + 1; // 课程答题人数 $testUsers = self::testUsers($testId); $percent = $num / $testUsers * 10000; $percent = explode(".", $percent); // $data['scores'] = $scores; $data['percent'] = $percent[0]; $data['testScore'] = $score; $data['point'] = $pointChange; } catch (Exception $e) { error_log($e); } return $data; }