예제 #1
0
파일: School.php 프로젝트: krisrita/udo
 function getResourceInfo($type, $id = 0, $localId = 0, $name = "")
 {
     $tblEntrance = new DB_Sso_Entrance();
     $tblResource = new DB_Sso_Resource();
     switch ($type) {
         case Common_Config::PUBLIC_SCHOOL_TYPE:
             $entrance = $tblEntrance->scalar("customer_name,customer_title,logo", "where id = {$id}");
             return $entrance;
         case Common_Config::PUBLIC_COURSE_TYPE || Common_Config::PUBLIC_CHAPTER_TYPE || Common_Config::PUBLIC_SECTION_TYPE:
             if ($id) {
                 $course = $tblResource->scalar("name,entrance_id", "where id = {$id}");
                 $logo = $tblEntrance->scalar("logo", "where id = {$id}");
                 $course = array_merge($course, $logo);
                 return $course;
             } else {
                 $schoolId = $tblResource->scalar("entrance_id", "where name='{$name}' and local_id = {$localId}");
                 //print_r($schoolId);
                 $logo = $tblEntrance->scalar("logo,customer_name", "where id = {$schoolId['entrance_id']}");
                 return $logo;
             }
     }
 }
예제 #2
0
파일: Trade.php 프로젝트: krisrita/udo
 function newResourcePrice($resourcePrice, $schoolId)
 {
     $tblResource = new DB_Sso_Resource();
     $tblSchoolPrice = new DB_Udo_SchoolPrice();
     $priceSchool = 0;
     $school = $tblSchoolPrice->scalar("*", "where resourceId = {$schoolId}");
     //print_r(count($resourcePrice));
     foreach ($resourcePrice as $k => $val) {
         //print_r($val);
         $resource = $tblResource->scalar("type,price_type,cur_price", "where id ={$val['resourceId']}");
         //print_r($resource);
         $notFree = $val['notFree'];
         $freeStr = "";
         if (!$notFree) {
             $priceType = Common_Config::UDO_PRICETYPE_FREE;
             $freeStr = ",price_type = 3";
         } else {
             $priceType = $school['priceType'];
             $freeStr = ",price_type={$priceType}";
         }
         $price = $val['price'];
         $id = $val['resourceId'];
         $resourceUpdate = $tblResource->query("update resource set cur_price = {$price}" . $freeStr . " where id ={$id}");
         //print_r($resource['type']." ");
         if ($resource['type'] == Common_Config::PUBLIC_COURSE_TYPE) {
             $priceSchool += $price;
             //print_r($priceSchool." ");
         }
     }
     $priceSchool *= $school['discount'];
     $priceSchool = ceil($priceSchool);
     /*print_r($school['discount']);
       print_r($priceSchool);*/
     $schoolPrice = $tblSchoolPrice->query("update udo_school_price set price={$priceSchool} where resourceId={$schoolId}");
     return $resourceUpdate;
 }
예제 #3
0
파일: Account.php 프로젝트: krisrita/udo
 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;
     }
 }