示例#1
0
文件: Credit.php 项目: krisrita/udo
 function getCredit1($userId, $actionId, $userAuth)
 {
     $tblCredit = new DB_Udo_CreditAction();
     $tblLog = new DB_Udo_UserCreditLog();
     if ($actionId == 200) {
         $actionId = -1;
     }
     //获取该动作的基础信息
     $result = $tblCredit->scalar("creditAmount,outputInput,ratio,times,isSynthesized,actionType", "where actionId = {$actionId}");
     //print_r($result);
     //开始判断第一种情况,该操作是综合类产出
     if ($result['isSynthesized']) {
         //找到该操作的所有同类操作
         $sameAction = $tblCredit->fetchAll("actionId", "where actionType = {$result['actionType']}");
         //print_r($sameAction);
         //从用户积分日志表中找到同类操作的次数
         $strAction = "(";
         foreach ($sameAction as $k => $value) {
             $str = (string) $value['actionId'];
             $strAction .= $str;
             if (array_key_exists($k + 1, $sameAction)) {
                 $strAction .= ",";
             }
         }
         $strAction .= ")";
         //获取积分日志中该类别综合产出的次数
         $today = strtotime("today");
         $tomorrow = strtotime("tomorrow");
         //失败的记录之后如果重新插入成功,额外多加一条成功日志而不是更新失败日志
         $actionLog = $tblLog->fetchAll("id,userId,actionId,status,createTime", "where actionId in {$strAction} and createTime between {$today} and {$tomorrow}\r\n             and status <> 0");
         //$times:增加积分的次数;$save:目前在log日志中存储的尚未增加积分的和当前操作不同的同类操作
         $times = $tblLog->queryCount("where actionId= {$actionId} and createTime between {$today} and {$tomorrow}\r\n             and status = 1");
         $save = $tblLog->fetchAll("actionId,count(*)", "where actionId in {$strAction} and actionId <> {$actionId} and createTime between {$today} and {$tomorrow}\r\n             and status = 3 group by actionId");
         /*            print_r($times);
                     print_r($result['times']);
                     print_r($save);*/
         //如果综合产出奖励积分的次数已达上限
         if ($times >= $result['times']) {
             $insertArray = array("userId" => $userId, "creditSource" => 0, "actionId" => $actionId, "creditAmount" => 0, "status" => 3, "isAuthorized" => $userAuth, "createTime" => time());
             $tblLog->insert($insertArray);
             return array("creditAmount" => 0, "isEnough" => 1, "text" => "上限");
             //写入用户行为日志,积分操作已达上限
         }
         //如果综合产出奖励积分的次数未达上限,且就差一个达到要求
         if ($times < $result['times'] && count($sameAction) - count($save) == 1) {
             //更新日志中显示未加积分的操作的状态
             foreach ($save as $k => $val) {
                 $id = $tblLog->scalar("id", "where actionId = {$val['actionId']} and createTime between {$today} and {$tomorrow}\r\n             and status = 3");
                 $update = $tblLog->update($id['id'], array("status" => 1));
             }
             $insertArray = array("userId" => $userId, "creditSource" => 0, "actionId" => $actionId, "creditAmount" => 0, "status" => 1, "isAuthorized" => $userAuth, "createTime" => time());
             $insert = $tblLog->insert($insertArray);
             //在用户账户里增加相应积分
             //返回积分增加信息
             return array("creditAmount" => $result['creditAmount'], "isEnough" => 1, "text" => "+{$result['creditAmount']}积分");
         }
         //否则,在日志表中插入一条新记录
         $insertArray = array("userId" => $userId, "creditSource" => 0, "actionId" => $actionId, "creditAmount" => 0, "status" => 3, "isAuthorized" => $userAuth, "createTime" => time());
         $tblLog->insert($insertArray);
         return array("creditAmount" => 0, "isEnough" => 1, "text" => "");
     }
     //结束综合产出的情况
     //如果是消耗积分
     //从
     //测试返回:
     return array("creditAmount" => 3, "isEnough" => 1, "text" => "+3积分!");
 }
示例#2
0
文件: Account.php 项目: krisrita/udo
 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);
 }