Exemplo n.º 1
0
 function getCredit($userId, $actionId, $schoolId)
 {
     $tblCredit = new DB_Udo_CreditAction();
     $tblAccount = new DB_Pay_Account();
     $tblCreditLog = new DB_Udo_UserCreditLog();
     $rand = new Common_Char();
     //获取该动作的基础信息
     $result = $tblCredit->scalar("creditAmount,name,outputInput,ratio,times,isSynthesized,actionType", "where actionId = {$actionId} and isValid = 1");
     if (!$result) {
         return Common_Error::ERROR_ACTION;
     }
     $upTimes = $result['times'];
     //接下来获取用户当日的同action的操作
     $today = strtotime("today");
     $tomorrow = strtotime("tomorrow");
     $statusSuccess = Common_Config::CREDIT_SUCCESS;
     $sameTimes = $tblCreditLog->queryCount("where actionId = {$actionId} and userId = {$userId} and createTime between {$today} and {$tomorrow}\r\n             and status = {$statusSuccess}");
     //如果今日增长已经超出限额
     if ($sameTimes >= $upTimes) {
         return Common_Error::ERROR_OVER_TIMES;
     }
     //否则更新账户信息,如果失败再重试三次
     $retry = 0;
     $updateAccount = 0;
     $id = $tblAccount->scalar("id,amt,score", "where sso_id = {$userId}");
     //print_r($id);
     //$testUpdate = $tblAccount->query("update account set score = 1895 where id = {$id['id']}");
     //print_r($testUpdate);
     while (!$updateAccount && $retry <= 3) {
         $score = $id['score'] + $result['creditAmount'];
         //print_r($score);
         //$updateAccount = $tblAccount->query("update account set score = {$score} where id = {$id['id']}");
         $remark = "日常活动";
         $random = $rand->getRandChar(8);
         $sign = md5(Common_Config::PAY_OSID . $userId . $result['creditAmount'] . $remark . $random . Common_Config::PAY_SECRET);
         //print_r(Common_Config::PAY_OSID.(string)$userId.(string)$score.$remark.$random.Common_Config::PAY_SECRET);
         $url = Common_Config::CREDIT_UPDATE;
         $post_data = array("osid" => Common_Config::PAY_OSID, "ssoId" => $userId, "score" => $result['creditAmount'], "remark" => $remark, "random" => $random, "sign" => $sign);
         $cl = new Common_Curl();
         $updateAccount = $cl->request($url, $post_data);
         $retry++;
         //print_r($updateAccount);
     }
     //账户更新失败返回失败信息
     if (!$updateAccount) {
         return Common_Error::ERROR_UPDATE_BALANCE;
     }
     //账户更新成功,插入学分和U币变动日支
     $tblCreditLog->insert(array("userId" => $userId, "creditSource" => Common_Config::DAILY_CREDIT_ACTION, "actionId" => $actionId, "info" => $result['name'] . "获得学分", "amt" => $result['creditAmount'], "status" => Common_Config::CREDIT_SUCCESS, "schoolId" => $schoolId, "createTime" => time()));
     return Common_Error::ERROR_SUCCESS;
 }
Exemplo n.º 2
0
 function getCreditLog($uid = 0, $previousId = 0, $pageSize = 20, $startTime = 0, $endTime = 0, $page = 1)
 {
     $tblCreditLog = new DB_Udo_UserCreditLog();
     $userModel = new UserModel();
     $resultArray = [];
     if (!$previousId) {
         $previousId = 0;
     }
     //获取分页列表时注意按照时间顺序倒序排
     //首条数据的获取规则不是和上条对比,而是直接按照id来排
     $where = "where id>0 ";
     if ($uid) {
         $where .= " and userId = {$uid} ";
     }
     if ($previousId) {
         $where .= " and id<{$previousId}";
     }
     if ($startTime || $endTime) {
         if (!$endTime) {
             $where .= " and createTime >= {$startTime}";
         } else {
             $where .= " and createTime >={$startTime} and createTime <= {$endTime}";
         }
     }
     $creditCount = $tblCreditLog->queryCount($where);
     $creditLog = $tblCreditLog->fetchLimit("id,amt,info,createTime,userId", $where, "order by id desc", $page, $pageSize);
     //如果首次请求,前一个月数据为0
     if ($previousId == 0) {
         $previousMonth = 0;
     } else {
         $getPrevious = $tblCreditLog->scalar("id,amt,info,createTime", "where id = {$previousId}");
         $previousMonth = date('m', $getPrevious['createTime']);
     }
     //对结果列表中的每一条数据,需要与上月数据对比,如果月份不一样,需要在本条数据之前插入月份信息
     $year = date('Y-m', time());
     foreach ($creditLog as $k => $value) {
         //非首页请求的第一条数据需要和上一条对比
         $currentMonth = date('m', $value['createTime']);
         if ($previousMonth && $previousMonth != $currentMonth || !$previousMonth) {
             $currentYear = date('Y-m', $value['createTime']);
             $createTime = $year == $currentYear ? "本月" : $currentMonth . "月";
             array_push($resultArray, array("id" => 0, "userId" => 0, "name" => 0, "mobile" => 0, "convertedTime" => $createTime, "amt" => 0, "info" => "", "createTime" => $createTime, "context" => ""));
         }
         $value['convertedTime'] = date('Y-m-d H:i:s', $value['createTime']);
         $previousMonth = date('m', $value['createTime']);
         $value['createTime'] = date('m-d', $value['createTime']);
         $value['context'] = "";
         $value['name'] = $userModel->getUserName($value['userId'])['name'];
         $value['mobile'] = $userModel->getUserName($value['userId'])['mobile'];
         array_push($resultArray, $value);
     }
     return array("creditLog" => $resultArray, "creditCount" => $creditCount);
 }