Example #1
0
 function getAvailableRes($uid, $domainId)
 {
     $schoolModel = new SchoolModel();
     $tblResource = new DB_Sso_Resource();
     $tblBought = new DB_Udo_UserBought();
     $availableArray = [];
     //首先从SSO获取到云滴请求的资源列表
     $url = Common_Config::SSO_USER_SINGLE_RESOURCE;
     $post_data = array("domainId" => $domainId, "userId" => $uid, "parentId" => 0, "localType" => Common_Config::UDO_LOCAL_COURSE_TYPE);
     $cl = new Common_Curl();
     $array = $cl->request($url, $post_data);
     //获取频道的定价信息
     $schoolPrice = $schoolModel->getSchoolPrice($domainId, $uid);
     $totalPrice = 0;
     $hasBought = 0;
     $children = [];
     foreach ($array as $k => $course) {
         //对于每一个父节点,根据id判断定价类型,现价和原价
         $priceInfo = $tblResource->scalar("price_type,cur_price,ori_price", "where id = {$course['id']}");
         //接下来获取当前资源用户是否已经购买
         $bought = $tblBought->scalar("id", "where userId = {$uid} and schoolId = {$domainId} and resourceId = {$course['id']} and resourceType = 2");
         if ($bought || $priceInfo['price_type'] == 3) {
             if ($bought) {
                 $hasBought = 1;
             }
             continue;
         } else {
             array_push($children, array("courseId" => $course['id'], "priceType" => $priceInfo['price_type'], "price" => $priceInfo['cur_price'], "localId" => $this->getLocalId($course['id'], $domainId)['local_id']));
             $totalPrice += $priceInfo['cur_price'];
         }
     }
     if (!$children) {
         return -1;
     }
     //生成返回列表
     //如果用户购买过频道的课程,那么不再按折扣价格计算
     if ($hasBought) {
         $price = $totalPrice;
     } else {
         $price = $schoolPrice['price'];
     }
     $availableArray = array("schoolId" => $domainId, "priceType" => $schoolPrice['priceType'], "price" => $price);
     return array_merge($availableArray, array("children" => $children));
 }
Example #2
0
 function getSchoolAction()
 {
     $request = $this->getRequest();
     //print_r($request->getMethod());
     // die();
     if ('POST' == $request->getMethod()) {
         //var_dump($this->post());
         $ssotoken = $this->post("ssotoken");
         //->get();
         $type = $this->post()->get("type");
         $schoolId = $this->post()->get("schoolId");
         //die($ssotoken);
     } else {
         //$ssotoken = "token439f0036-e5c7-4053-a48e-0c23c91ec41epylmt67C";
         $ssotoken = $this->get("ssotoken");
         $type = $this->get("type");
         $schoolId = $this->get("schoolId");
     }
     $type = $type ? $type : 1;
     if (!$ssotoken || !$type) {
         $this->displayJsonUdo(Common_Error::ERROR_PARAM);
     }
     if ($type == 4 && !$schoolId) {
         $this->displayJsonUdo(Common_Error::ERROR_PARAM, "", "缺失参数schoolId");
     }
     $url = Common_Config::SSO_SCHOOL_URL;
     $post_data = array("ssotoken" => $ssotoken);
     //获取用户id
     $userModel = new UserModel();
     $schoolModel = new SchoolModel();
     $uid = $userModel->getUserId($ssotoken);
     if (is_array($uid)) {
         $this->displayJsonUdo(Common_Error::INVALID_TOKEN, "", $uid['msg']);
     }
     $cl = new Common_Curl();
     $array = $cl->request($url, $post_data);
     if (array_key_exists('code', $array) && $array['code'] == 0) {
         $this->displayJsonUdo(Common_Error::ERROR_FAIL, null, "SSO没有返回可以浏览的频道噢~");
     }
     $result = [];
     $newArray = [];
     //如果用户是请求所有频道
     if ($type == 1) {
         //获取到频道后,开始进行频道过滤
         //从本版本开始暂不进行频道过滤
         //$result = $schoolModel->schoolFilter($array);
         //过滤后的频道进行排序
         $result = $schoolModel->schoolOrder($array);
         //print_r($result);
         //print_r($result);
         //过滤后的结果去掉BaseUrl
     } elseif ($type == 3 || $type == 2) {
         $result = $schoolModel->getSubscribe($array['entrances'], $uid, $type);
     } elseif ($type == 4) {
         $result = $schoolModel->getSingleSchool($uid, $schoolId, $array['entrances']);
         if ($result == -1) {
             $this->displayJsonUdo(Common_Error::ERROR_FAIL, "", "没有返回有效的频道信息噢~");
         }
     }
     //测试用index
     // $i = 0;
     //在返回的频道列表中的每一项上附加上订阅信息
     foreach ($result as $k => $val) {
         //print_r($val);
         if (is_array($val)) {
             //测试用数据
             //$val['isAuthorized']= $val['isAuthorized']?0:1;
             if ($type == 2) {
                 $val = array_merge($val, array("isSubscribed" => 1));
             } else {
                 $val = array_merge($val, array("isSubscribed" => $schoolModel->getIfSub($val['id'], $uid) ? 1 : 0));
             }
             //附加频道的定价信息
             $val = array_merge($val, $schoolModel->getSchoolPrice($val['id'], $uid));
             //将SSO返回的无用字段过滤掉
             $index = 0;
             while ($key = key($val)) {
                 if ($key == "apiBaseUrl") {
                     array_splice($val, $index, 1);
                     break;
                 }
                 $index++;
                 next($val);
             }
         }
         $newArray[$k] = $val;
     }
     if ($type == 4) {
         $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, $newArray[0]);
     }
     $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, $newArray);
 }