Ejemplo n.º 1
0
 function getCoursePrice($courseId, $uid)
 {
     $tblResource = new DB_Sso_Resource();
     $tblUserBought = new DB_Udo_UserBought();
     $courseType = Common_Config::UDO_RESOURCE_COURSE;
     $priceInfo = $tblResource->scalar("cur_price,price_type", "where id = {$courseId} and enabled = 1");
     $isBought = $tblUserBought->scalar("id", "where resourceType = {$courseType} and userId = {$uid} and resourceId = {$courseId}");
     //print_r($isBought);
     return array("price" => $priceInfo['cur_price'], "priceType" => $priceInfo['price_type'], "isBought" => $isBought ? 1 : 0);
 }
Ejemplo n.º 2
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));
 }
Ejemplo n.º 3
0
 function newOrder($ssotoken, $uid, $schoolId, $courseCount = 0, $payType, $resource = [], $coinId = 0, $amount, $platform = 0, $couponId = 0, $couponAmt = 0)
 {
     $tblOrder = new DB_Udo_Order();
     $tblSchoolPrice = new DB_Udo_SchoolPrice();
     $tblResource = new DB_Sso_Resource();
     $tblCoinInfo = new DB_Udo_CoinInfo();
     $tblBought = new DB_Udo_UserBought();
     $tradeModel = new TradeModel();
     $correct = 0;
     $schoolPrice = $tblSchoolPrice->scalar("priceType,price", "where resourceId = {$schoolId}");
     $balance = $this->getSsoBalance($ssotoken);
     $userModel = new UserModel();
     $mobile = $userModel->getUserName($uid)['mobile'];
     //生成订单前,首先判断资源定价信息是否有误
     if ($payType == Common_Config::UDO_PAYTYPE_COIN || $payType == Common_Config::UDO_PAYTYPE_CREDIT) {
         //如果是频道类型,首先获取频道的定价类型和定价
         //根据用户提交过来的参数并不知道是否全部购买了课程
         //$resource 获取所有非免费课程
         $charge = $tblResource->fetchAll("id", "where entrance_id = {$schoolId} and type = 6 and price_type <> 3 and enabled = 1");
         $totalPrice = 0;
         foreach ($resource as $k => $val) {
             if ($val['resourceType'] == 1) {
                 continue;
             }
             $resourcePrice = $tblResource->scalar("id,type,entrance_id,price_type,cur_price", "where id = {$val['resourceId']}");
             $totalPrice += $resourcePrice['cur_price'];
             //print_r($resourcePrice['price_type']);
             if ($payType == Common_Config::UDO_PAYTYPE_COIN && $resourcePrice['price_type'] == Common_Config::UDO_PRICETYPE_COIN || $payType == Common_Config::UDO_PAYTYPE_CREDIT && $resourcePrice['price_type'] == Common_Config::UDO_PRICETYPE_CREDIT) {
                 $correct = 1;
             } else {
                 return Common_Error::ERROR_COURSE_PRICETYPE;
             }
             //再判断课程用户是否已经购买
             $bought = $tblBought->scalar("id", "where userId ={$uid} and resourceId= {$val['resourceId']} and schoolId = {$schoolId}");
             //print_r($bought);
             if ($bought) {
                 return Common_Error::ERROR_COURSE_BOUGHT;
             }
         }
         //再判断定价值是否正确
         //如果传过来的课程数量就是所有需付费的课程,那么总价是频道定价
         if (count($charge) == $courseCount) {
             $totalPrice = $schoolPrice['price'];
         }
         if ($amount != $totalPrice) {
             return Common_Error::ERROR_COURSE_PRICE;
         }
         //总价核验后,再核验账户余额
         if ($totalPrice > ($payType == Common_Config::UDO_PAYTYPE_COIN ? $balance['amt'] : $balance['score'])) {
             return Common_Error::ERROR_SHORT_BALANCE;
         }
         //在数据核验准确后,生成订单
         $newOrder = [];
         $retry = 0;
         //如果生成失败会再循环尝试三次
         while ($retry <= 3 && !$newOrder) {
             $newOrder = $tblOrder->insert(array("userId" => $uid, "mobile" => $mobile, "payType" => $payType, "resource" => json_encode($resource), "amount" => $amount, "createTime" => time(), "status" => Common_Config::ORDER_NOT_PAY));
             $retry++;
             //如果第三次仍失败,返回订单创建失败
             if ($retry == 3) {
                 return Common_Error::ERROR_ORDER_FAIL;
             }
         }
         return $newOrder;
     } elseif ($payType == Common_Config::UDO_PAYTYPE_RECHARGE) {
         $coinInfo = $tblCoinInfo->scalar("amt", "where id = {$coinId}");
         if ($amount != $coinInfo['amt']) {
             return Common_Error::ERROR_COIN_INFO;
         }
         //在数据核验准确后,生成订单
         $newOrder = [];
         $retry = 0;
         $coinMoney = $tradeModel->getCoinMoney($coinId);
         //如果生成失败会再循环尝试三次
         while ($retry <= 3 && !$newOrder) {
             $newOrder = $tblOrder->insert(array("userId" => $uid, "mobile" => $mobile, "payType" => $payType, "coinId" => $coinId, "money" => $coinMoney['price'], "amount" => $amount, "platform" => $platform, "createTime" => time(), "status" => Common_Config::ORDER_NOT_PAY));
             $retry++;
             //如果第三次仍失败,返回订单创建失败
             if ($retry == 3) {
                 return Common_Error::ERROR_ORDER_FAIL;
             }
         }
         return $newOrder;
     }
 }