Esempio n. 1
0
 function getBought($uid = 0, $previousId = 0, $pageSize = 20, $startTime = 0, $endTime = 0, $page = 1)
 {
     $tblBought = new DB_Udo_UserBought();
     $tblResource = new DB_Sso_Resource();
     $tblEntrance = new DB_Sso_Entrance();
     $tblSta = new DB_Udo_SchoolStatistics();
     $tradeModel = new TradeModel();
     $userModel = new UserModel();
     if (!$previousId) {
         $previousId = 0;
     }
     $where = "where resourceType = 2";
     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}";
         }
     }
     $boughtCount = $tblBought->queryCount($where);
     //首先获取用户购买的课程和所在的频道
     $bought = $tblBought->fetchLimit("userId,id,resourceId,schoolId,orderId,createTime", $where, "order by id desc", $page, $pageSize);
     //print_r($bought);
     $newArray = [];
     //接下来对逐个课程,获取频道的具体信息和课程的具体信息
     foreach ($bought as $k => $value) {
         $entrance = $tblEntrance->scalar("customer_name,customer_title,logo,api_udo_url", "where id = {$value['schoolId']}");
         //$sta = $tblSta->queryCount("where schoolId = {$value['schoolId']} group by userId");
         $staResult = $tblSta->fetchAll("*", "where schoolId = {$value['schoolId']} group by userId");
         $sta = count($staResult);
         //print_r($sta." ");
         if (!$sta) {
             $sta = 0;
         }
         $info = $sta . "人已学";
         $resource = $tblResource->scalar("name", "where id = {$value['resourceId']}");
         //获取课程的localId供在列表中进行跳转
         $localId = $tradeModel->getLocalId($value['resourceId'], $value['schoolId']);
         $value['mobile'] = $userModel->getUserName($value['userId'])['mobile'];
         $value['userName'] = $userModel->getUserName($value['userId'])['name'];
         $newArray[$k] = array("listId" => $value['id'], "id" => $value['resourceId'], "userId" => $value['userId'], "mobile" => $value['mobile'], "userName" => $value['userName'], "localId" => $localId['local_id'], "logo" => $entrance['logo'], "name" => $resource['name'], "schoolName" => $entrance['customer_name'], "schoolTitle" => $entrance['customer_title'], "info" => $info, "schoolId" => $value['schoolId'], "apiUdoUrl" => $entrance['api_udo_url'], "courseType" => 0, "orderId" => $value['orderId'], "createTime" => date("Y-m-d H:i:s", $value['createTime']));
     }
     return array("bought" => $newArray, "boughtCount" => $boughtCount);
 }