Ejemplo n.º 1
0
 function getSchoolPrice($schoolId, $uid)
 {
     $tblPrice = new DB_Udo_SchoolPrice();
     $tblBought = new DB_Udo_UserBought();
     $tblResource = new DB_Sso_Resource();
     $bought = 0;
     //查找出频道的定价信息
     $price = $tblPrice->scalar("priceType,price", "where resourceId = {$schoolId}");
     //没有查询到定价信息的频道一律按照免费处理
     if (!$price) {
         $price = array("priceType" => Common_Config::UDO_PRICETYPE_FREE, "price" => 0);
     }
     //查找用户的购买信息
     //原则上免费课程不能加入购买表中
     $isBought = $tblBought->fetchAll("resourceId", "where schoolId = {$schoolId} and resourceType = 2 and userId = {$uid}");
     //print_r($isBought);
     //查找该频道下的所有非免费课程
     $resource = $tblResource->fetchAll("id", "where entrance_id = {$schoolId} and type = 6 and price_type <> 3 and enabled = 1");
     //如果定价免费
     if ($price['priceType'] == 3) {
         $bought = 1;
     } else {
         $boughtCount = 0;
         foreach ($resource as $k => $value) {
             foreach ($isBought as $l => $val) {
                 if ($value['id'] == $val['resourceId']) {
                     $boughtCount++;
                     break;
                 }
             }
         }
         //考虑到频道中的课程可能会有更新,所以不能以当前频道的购买状态作为频道是否购买的依据,
         //而是要以非免费课程和已购买课程的数量是否相等作为依据
         if ($boughtCount == count($resource) && count($resource) != 0) {
             $bought = 1;
         }
     }
     return array("price" => $price['price'], "priceType" => $price['priceType'], "isBought" => $bought);
 }
Ejemplo n.º 2
0
 function newSchoolPrice($id, $priceType, $discount)
 {
     $tblSchoolPrice = new DB_Udo_SchoolPrice();
     $tblResource = new DB_Sso_Resource();
     $courseType = Common_Config::PUBLIC_COURSE_TYPE;
     //当前频道是否已经定价
     $schoolPrice = $tblSchoolPrice->scalar("*", "where resourceId = {$id}");
     $resource = $tblResource->fetchAll("id,price_type,cur_price", "where entrance_id = {$id} and type = {$courseType} and price_type = {$priceType}");
     //计算当前频道下的课程总价
     $totalPrice = 0;
     foreach ($resource as $k => $val) {
         $totalPrice += $val['cur_price'];
     }
     $finalPrice = ceil($totalPrice * $discount);
     //如果频道的定价已经存在,那么更新数据
     if ($schoolPrice) {
         $result = $tblSchoolPrice->query("update udo_school_price set priceType={$priceType},discount={$discount},price={$finalPrice}");
     } else {
         $result = $tblSchoolPrice->insert(array("priceType" => $priceType, "price" => $finalPrice, "discount" => $discount, "createTime" => time()));
     }
     //根据priceType判断,频道定价类型免费时,则所有下属resource的数据需更新为免费;如果定价类型不免费,那么所有不免费resource的类型也需同时改变
     if ($priceType == Common_Config::UDO_PRICETYPE_FREE) {
         $updateResource = $tblResource->query("update resource set price_type = 3,cur_price=0 where entrance_id = {$id}");
     } else {
         $updateResource = $tblResource->query("update resource set price_type = {$priceType} where entrance_id = {$id} and cur_price<>0");
     }
     return $result;
 }
Ejemplo n.º 3
0
 function alterAccount($uid, $schoolId)
 {
     $tblSchoolPrice = new DB_Udo_SchoolPrice();
     $tblResource = new DB_Sso_Resource();
     $tblBought = new DB_Udo_UserBought();
     $tblOrder = new DB_Udo_Order();
     $schoolPrice = $tblSchoolPrice->scalar("*", "where resourceId = {$schoolId}");
     $courseType = Common_Config::PUBLIC_COURSE_TYPE;
     $free = Common_Config::UDO_PRICETYPE_FREE;
     $course = $tblResource->fetchAll("id", "where type = {$courseType} and price_type <> {$free} and entrance_id = {$schoolId}");
     $resource = [];
     foreach ($course as $key => $value) {
         array_push($resource, array("resourceType" => 2, "resourceId" => $value['id']));
     }
     //print_r($resource);
     $courseIds = $tblResource->columnRow($course, "id");
     $resourceType = Common_Config::UDO_RESOURCE_COURSE;
     $newOrder = $tblOrder->insert(array("userId" => $uid, "resource" => json_encode($resource), "createTime" => time(), "status" => Common_Config::ORDER_SUCCESS, "payType" => $schoolPrice['priceType'] == 1 ? 2 : 1));
     foreach ($courseIds as $key => $value) {
         $tblBought->insert(array("resourceId" => $value, "userId" => $uid, "schoolId" => $schoolId, "createTime" => time(), "resourceType" => $resourceType, "orderId" => $newOrder));
     }
     return 1;
 }