Пример #1
0
 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;
 }