Пример #1
0
 public function shouldPayAmount($targetId, $priceType, $cashRate, $coinEnabled, $fields)
 {
     $totalPrice = $this->getTotalPrice($targetId, $priceType);
     $amount = $totalPrice;
     //优惠码优惠价格
     if ($fields["couponCode"] && trim($fields["couponCode"]) != "") {
         $couponResult = $this->afterCouponPay($fields["couponCode"], 'course', $targetId, $totalPrice, $priceType, $cashRate);
         if (isset($couponResult["useable"]) && $couponResult["useable"] == "yes" && isset($couponResult["afterAmount"])) {
             $amount = $couponResult["afterAmount"];
         } else {
             unset($couponResult);
         }
     }
     //虚拟币优惠价格
     if (array_key_exists("coinPayAmount", $fields)) {
         $amount = $this->afterCoinPay($coinEnabled, $priceType, $cashRate, $amount, $fields['coinPayAmount'], $fields["payPassword"]);
     }
     if ($priceType == "Coin") {
         $amount = $amount / $cashRate;
     }
     if ($amount < 0) {
         $amount = 0;
     }
     $totalPrice = NumberToolkit::roundUp($totalPrice);
     $amount = NumberToolkit::roundUp($amount);
     return array($amount, $totalPrice, empty($couponResult) ? null : $couponResult);
 }
Пример #2
0
 protected function calculateCoinAmount($totalPrice, $priceType, $cashRate)
 {
     $user = $this->getUserService()->getCurrentUser();
     $account = $this->getCashAccountService()->getAccountByUserId($user["id"]);
     $accountCash = $account["cash"];
     $coinPayAmount = 0;
     $hasPayPassword = strlen($user['payPassword']) > 0;
     if ($hasPayPassword) {
         if ($priceType == "Coin") {
             if ($totalPrice * 100 > $accountCash * 100) {
                 $coinPayAmount = $accountCash;
             } else {
                 $coinPayAmount = $totalPrice;
             }
         } else {
             if ($priceType == "RMB") {
                 if ($totalPrice * 100 > $accountCash / $cashRate * 100) {
                     $coinPayAmount = $accountCash;
                 } else {
                     $coinPayAmount = $totalPrice * $cashRate;
                 }
             }
         }
     }
     $totalPrice = NumberToolkit::roundUp($totalPrice);
     $coinPayAmount = NumberToolkit::roundUp($coinPayAmount);
     return array($totalPrice, $coinPayAmount, $account, $hasPayPassword);
 }
 public function getOrderInfo($targetId, $payment)
 {
     $totalPoints = 0;
     $exchange = $this->getExchangeService()->getExchange($targetId);
     $user = $this->getUserService()->getCurrentUser();
     if (empty($exchange)) {
         throw new Exception("找不到要兑换的资料!");
     }
     $totalPoints = $exchange["points"];
     /*  if ($payment == "points") {
          $totalPoints = $exchange["points"];
          } else if($payment == "exchange") {
          $totalPoints = 0;
         }*/
     $account = $this->getPointsAccountService()->getAccountByUserId($user["id"]);
     $accountPoints = $account["points"];
     $pointsPayAmount = 0;
     $hasPayPassword = $user['payPassword'];
     if ($hasPayPassword) {
         if ($totalPoints * 100 > $accountPoints * 100) {
             $pointsPayAmount = $accountPoints;
         } else {
             $pointsPayAmount = $totalPoints;
         }
     }
     $totalPoints = NumberToolkit::roundUp($totalPoints);
     $pointsPayAmount = NumberToolkit::roundUp($pointsPayAmount);
     return array('account' => $account, 'totalPoints' => $totalPoints, 'targetId' => $targetId, 'targetType' => "points", 'hasPayPassword' => $hasPayPassword, 'exchange' => empty($exchange) ? null : $exchange, 'pointsPayAmount' => $pointsPayAmount);
 }
 public function shouldPayAmount($targetId, $priceType, $cashRate, $coinEnabled, $fields)
 {
     $totalPrice = $this->getTotalPrice($targetId, $priceType);
     $amount = $totalPrice;
     $totalPrice = NumberToolkit::roundUp($totalPrice);
     $amount = NumberToolkit::roundUp($amount);
     return array($amount, $totalPrice);
 }
Пример #5
0
 public function testroundUp()
 {
     $testNumArray = array(123.456, 5784975.4328278, 437.3, 89.11, 345.03);
     $testNum1 = NumberToolkit::roundUp($testNumArray[0]);
     $testNum2 = NumberToolkit::roundUp($testNumArray[1]);
     $testNum3 = NumberToolkit::roundUp($testNumArray[2]);
     $testNum4 = NumberToolkit::roundUp($testNumArray[3]);
     $testNum5 = NumberToolkit::roundUp($testNumArray[4]);
     $this->assertEquals(123.46, $testNum1);
     $this->assertEquals(5784975.44, $testNum2);
     $this->assertEquals(437.3, $testNum3);
     $this->assertEquals(89.11, $testNum4);
     $this->assertEquals(345.03, $testNum5);
 }
Пример #6
0
 public function shouldPayAmount($targetId, $priceType, $cashRate, $coinEnabled, $orderData)
 {
     if (!ArrayToolkit::requireds($orderData, array('buyType', 'targetId', 'unitType', 'duration'))) {
         throw new Exception('订单数据缺失,创建会员订单失败。');
     }
     if (!in_array($orderData['buyType'], array('new', 'renew', 'upgrade'))) {
         throw new Exception('购买类型不正确,创建会员订单失败。');
     }
     if (!(array_key_exists("buyType", $orderData) && $orderData["buyType"] == "upgrade")) {
         $orderData['duration'] = intval($orderData['duration']);
         if (empty($orderData['duration'])) {
             throw new Exception('会员开通时长不正确,创建会员订单失败。');
         }
         if (!in_array($orderData['unitType'], array('month', 'year'))) {
             throw new Exception('付费方式不正确,创建会员订单失败。');
         }
     }
     $level = $this->getLevelService()->getLevel($orderData['targetId']);
     if (empty($level)) {
         throw new Exception('会员等级不存在,创建会员订单失败。');
     }
     if (empty($level['enabled'])) {
         throw new Exception('会员等级已关闭,创建会员订单失败。');
     }
     $currentUser = $this->getLevelService()->getCurrentUser();
     if (array_key_exists("buyType", $orderData) && $orderData["buyType"] == "upgrade") {
         $totalPrice = $this->getVipService()->calUpgradeMemberAmount($currentUser->id, $level['id']);
     } else {
         $unitPrice = $level[$orderData['unitType'] . 'Price'];
         if ($priceType == "Coin") {
             $unitPrice = NumberToolkit::roundUp($unitPrice * $cashRate);
         }
         $totalPrice = $unitPrice * $orderData['duration'];
     }
     $amount = $totalPrice;
     //优惠码优惠价格
     if ($orderData["couponCode"] && trim($orderData["couponCode"]) != "") {
         $couponResult = $this->afterCouponPay($orderData["couponCode"], 'vip', $targetId, $totalPrice, $priceType, $cashRate);
         if (isset($couponResult["useable"]) && $couponResult["useable"] == "yes" && isset($couponResult["afterAmount"])) {
             $amount = $couponResult["afterAmount"];
         }
     }
     //虚拟币优惠价格
     if (array_key_exists("coinPayAmount", $orderData)) {
         $amount = $this->afterCoinPay($coinEnabled, $priceType, $cashRate, $amount, $orderData['coinPayAmount'], $orderData["payPassword"]);
     }
     if ($priceType == "Coin") {
         $amount = $amount / $cashRate;
     }
     if ($amount <= 0) {
         $amount = 0;
     }
     $totalPrice = NumberToolkit::roundUp($totalPrice);
     $amount = NumberToolkit::roundUp($amount);
     return array($amount, $totalPrice, empty($couponResult) ? null : $couponResult);
 }
Пример #7
0
 public function getSetPrice($price)
 {
     return NumberToolkit::roundUp($price);
 }
Пример #8
0
 public function shouldPayAmount($targetId, $priceType, $cashRate, $coinEnabled, $fields)
 {
     $totalPrice = 0;
     $classroom = $this->getClassroomService()->getClassroom($targetId);
     if ($priceType == "RMB") {
         $totalPrice = $classroom["price"];
     } else {
         if ($priceType == "Coin") {
             $totalPrice = $classroom["price"] * $cashRate;
         }
     }
     $totalPrice = (double) $totalPrice;
     $amount = $totalPrice;
     $courses = $this->getClassroomService()->findCoursesByClassroomId($targetId);
     if (empty($courses) || count($courses) == 0) {
         throw new Exception("班级中还未设置课程,请联系管理员!");
     }
     $courseIds = $courses = ArrayToolkit::column($courses, "parentId");
     $courses = $this->getCourseService()->findCoursesByIds($courseIds);
     $coursesTotalPrice = $this->getCoursesTotalPrice($courses, $priceType);
     $courseIds = ArrayToolKit::column($courses, "id");
     $currentUser = $this->getUserService()->getCurrentUser();
     $classroomSetting = $this->getSettingService()->get("classroom");
     $paidCoursesTotalPrice = 0;
     $paidCourses = array();
     if (!isset($classroomSetting["discount_buy"]) || $classroomSetting["discount_buy"] != 0) {
         $paidCourses = $this->getPaidCourses($currentUser, $courseIds);
     }
     foreach ($paidCourses as $key => $paidCourse) {
         $afterDiscountPrice = $this->afterDiscountPrice($paidCourse, $priceType);
         $amount -= $afterDiscountPrice;
         $totalPrice -= $afterDiscountPrice;
     }
     $totalPrice = NumberToolkit::roundUp($totalPrice);
     if ($totalPrice < 0) {
         $totalPrice = 0;
     }
     if ($amount < 0.001) {
         $amount = 0;
     }
     //优惠码优惠价格
     $couponApp = $this->getAppService()->findInstallApp("Coupon");
     $couponSetting = $this->getSettingService()->get("coupon");
     if (!empty($couponApp) && isset($couponSetting["enabled"]) && $couponSetting["enabled"] == 1 && $fields["couponCode"] && trim($fields["couponCode"]) != "") {
         $couponResult = $this->afterCouponPay($fields["couponCode"], 'classroom', $targetId, $amount, $priceType, $cashRate);
         if (isset($couponResult["useable"]) && $couponResult["useable"] == "yes" && isset($couponResult["afterAmount"])) {
             $amount = $couponResult["afterAmount"];
         }
     }
     //虚拟币优惠价格
     if (array_key_exists("coinPayAmount", $fields)) {
         $amount = $this->afterCoinPay($coinEnabled, $priceType, $cashRate, $amount, $fields['coinPayAmount'], $fields["payPassword"]);
     }
     if ($priceType == "Coin") {
         $amount = $amount / $cashRate;
     }
     if ($amount < 0) {
         $amount = 0;
     }
     $amount = NumberToolkit::roundUp($amount);
     return array($amount, $totalPrice, empty($couponResult) ? null : $couponResult);
 }