示例#1
0
文件: Trade.php 项目: krisrita/udo
 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()));
         }
     }
 }
示例#2
0
文件: School.php 项目: krisrita/udo
 function searchSchool($keyword, $ssotoken)
 {
     $tblLog = new DB_Udo_SearchLog();
     $userModel = new UserModel();
     $uid = $userModel->getUserId($ssotoken);
     //print_r($keyword);
     //先进行结果查询,将查询出来的id记录下来
     $tblEntrance = new DB_Sso_Entrance();
     //记录结果id的数组
     $result = [];
     $resultIds = [];
     //关键字搜索的长度限制
     //获取输入的关键字的字符串长度
     /* $length = strlen($keyword);
             for($i = $length;$i >=1 ;$i--){
                 //对关键词进行拆分
                 $split_array = str_split($keyword,$i);
                 foreach ($split_array as $k=>$value){
                     //对于每一个截断后的结果进行搜索
                     $name = $tblEntrance->fetchAll("id","where customer_name like '%{$value}%' or customer_title like '%{$value}%' ");
                     $result = array_merge($result,$name);
                 }
     
             }
             $resultIds = $tblEntrance->columnRow($result,"id");
             print_r(array_unique($resultIds));
             print_r(str_split("外语"));
             print_r(preg_split("/[\s,]+/","外语 教学,研究"));
     
             $tempaddtext="php对UTF8字体串进行单字分割返回数组";
             //$cind代表的是字符位移
             $cind = 0;
             $arr_cont = array();
             for ($i = 0; $i < strlen($tempaddtext); $i++) {
                 if (strlen(substr($tempaddtext, $cind, 1)) > 0) {
                 if (ord(substr($tempaddtext, $cind, 1)) < 192) {
                 if (substr($tempaddtext, $cind, 1) != " ") {
                     array_push($arr_cont, substr($tempaddtext, $cind, 1));}
                 $cind++;}
                 elseif(ord(substr($tempaddtext, $cind, 1)) < 224) {
                 array_push($arr_cont, substr($tempaddtext, $cind, 2));
                     $cind+=2;} else {array_push($arr_cont, substr($tempaddtext, $cind, 3));$cind+=3;}}}
             print_r($arr_cont);*/
     $result = $tblEntrance->fetchAll("id", "where customer_name like '%{$keyword}%' or customer_title like '%{$keyword}%' ");
     $resultIds = $tblEntrance->columnRow($result, 'id');
     if (!$resultIds) {
         $tblLog->insert(array("userId" => $uid, "keyword" => $keyword, "result" => -1, "createTime" => time()));
         return -1;
     }
     //print_r($resultIds);
     $result_array = [];
     //从sso获取所有频道
     $url = Common_Config::SSO_SCHOOL_URL;
     $post_data = array("ssotoken" => $ssotoken);
     $cl = new Common_Curl();
     $array = $cl->request($url, $post_data);
     $array['entrances'] = $this->schoolOrder($array);
     //针对搜索结果,返回频道的基础信息
     foreach ($resultIds as $l) {
         foreach ($array['entrances'] as $k => $val) {
             if ($val['id'] == $l) {
                 $price = $this->getSchoolPrice($l, $uid);
                 $val = array_merge($val, array("isSubscribed" => $this->getIfSub($val['id'], $uid) ? 1 : 0), $price);
                 $index = 0;
                 //过滤掉apiBaseUrl项目
                 while ($key = key($val)) {
                     if ($key == "apiBaseUrl") {
                         array_splice($val, $index, 1);
                         break;
                     }
                     $index++;
                     next($val);
                 }
                 array_push($result_array, $val);
             }
         }
         if (count($result_array) == count($resultIds)) {
             break;
         }
     }
     if (!$result_array) {
         $tblLog->insert(array("userId" => $uid, "keyword" => $keyword, "result" => -1, "createTime" => time()));
         return -1;
     }
     $tblLog->insert(array("userId" => $uid, "keyword" => $keyword, "result" => count($result_array), "resultString" => implode(',', $resultIds), "createTime" => time()));
     //print_r($result_array);
     return $result_array;
 }