function getResourceInfo($type, $id = 0, $localId = 0, $name = "") { $tblEntrance = new DB_Sso_Entrance(); $tblResource = new DB_Sso_Resource(); switch ($type) { case Common_Config::PUBLIC_SCHOOL_TYPE: $entrance = $tblEntrance->scalar("customer_name,customer_title,logo", "where id = {$id}"); return $entrance; case Common_Config::PUBLIC_COURSE_TYPE || Common_Config::PUBLIC_CHAPTER_TYPE || Common_Config::PUBLIC_SECTION_TYPE: if ($id) { $course = $tblResource->scalar("name,entrance_id", "where id = {$id}"); $logo = $tblEntrance->scalar("logo", "where id = {$id}"); $course = array_merge($course, $logo); return $course; } else { $schoolId = $tblResource->scalar("entrance_id", "where name='{$name}' and local_id = {$localId}"); //print_r($schoolId); $logo = $tblEntrance->scalar("logo,customer_name", "where id = {$schoolId['entrance_id']}"); return $logo; } } }
function testBought() { $tblUser = new DB_Sso_User(); $tblBought = new DB_Udo_UserBought(); $tblEntrance = new DB_Sso_Entrance(); $tblResource = new DB_Sso_Resource(); $entranceIds = $tblEntrance->fetchAll("id", "where id%3=0"); $entranceIdsPart = $tblEntrance->fetchAll("id", "where id%3=1 or id%3=2"); $userIds = $tblUser->fetchAll("id"); //$entranceId = $tblEntrance->scalar("id"); foreach ($userIds as $k => $value) { //首先对所有模3为0的,全部购买 foreach ($entranceIds as $m => $val) { $resourceIds = $tblResource->fetchAll("id", "where entrance_id = {$val['id']} and type = 6"); $insert = $tblBought->insert(array("userId" => $value['id'], "resourceId" => $val['id'], "resourceType" => 1, "schoolId" => $val['id'], "createTime" => time())); foreach ($resourceIds as $n => $v) { $tblBought->insert(array("userId" => $value['id'], "resourceId" => $v['id'], "resourceType" => 2, "schoolId" => $val['id'], "createTime" => time())); } } foreach ($entranceIdsPart as $l => $v2) { $resourceId = $tblResource->scalar("id", "where entrance_id = {$v2['id']} and type = 6"); $tblBought->insert(array("userId" => $value['id'], "resourceId" => $resourceId['id'], "resourceType" => 2, "schoolId" => $v2['id'], "createTime" => time())); } } }
function searchBought($uid, $key) { //$key = "金"; $tblBought = new DB_Udo_UserBought(); $tblResource = new DB_Sso_Resource(); $tblEntrance = new DB_Sso_Entrance(); $tblSta = new DB_Udo_SchoolStatistics(); $tradeModel = new TradeModel(); //首先获取用户购买的课程和所在的频道 $bought = $tblBought->fetchAll("id,resourceId,schoolId", "where userId ={$uid} and resourceType = 2 ", "order by id asc"); //print_r($bought); //print_r($bought); $resultArray = []; //接下来对逐个课程,获取频道的具体信息和课程的具体信息 foreach ($bought as $k => $value) { $entrance = $tblEntrance->scalar("customer_name,customer_title,logo,api_udo_url", "where id = {$value['schoolId']} and (customer_name like '%{$key}%'\r\n or customer_title like '%{$key}%')"); $resource = $tblResource->scalar("name", "where id = {$value['resourceId']} and name like '%{$key}%'"); //如果搜索到了频道或课程包含关键词,再显示该条信息 if ($entrance || $resource) { $sta = $tblSta->queryCount("where schoolId = {$value['schoolId']} group by userId"); if (!$sta) { $sta = 0; } $entrance = $tblEntrance->scalar("customer_name,customer_title,logo,api_udo_url", "where id = {$value['schoolId']}"); $resource = $tblResource->scalar("name", "where id = {$value['resourceId']} "); $info = $sta . "人已学"; //获取课程的localId供在列表中进行跳转 $localId = $tradeModel->getLocalId($value['resourceId'], $value['schoolId']); array_push($resultArray, array("id" => $value['resourceId'], "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)); } } return $resultArray; }