コード例 #1
0
 public function processOrder($payData, $lock = true)
 {
     $connection = ServiceKernel::instance()->getConnection();
     try {
         if ($lock) {
             $connection->beginTransaction();
         }
         list($success, $order) = $this->getOrderService()->payOrder($payData);
         if ($order["coupon"]) {
             $this->useCoupon($order);
         }
         $processor = OrderProcessorFactory::create($order["targetType"]);
         if ($order['status'] == 'paid' && $processor) {
             $processor->doPaySuccess($success, $order);
         }
         if ($lock) {
             $connection->commit();
         }
         return array($success, $order);
     } catch (\Exception $e) {
         if ($lock) {
             $connection->rollback();
         }
         throw $e;
     }
     return array(false, array());
 }
コード例 #2
0
 public function cartAction(request $request)
 {
     $user = $this->getCurrentUser();
     $carts = $this->getCartService()->getCartByUserId($user['id']);
     $orderInfo = array();
     if (!empty($carts)) {
         $processor = OrderProcessorFactory::create('course');
         $orderInfo = $processor->getOrderInfo(array_keys($carts));
         $orderInfo['carts'] = $carts;
     }
     return $this->render("TopxiaWebBundle:EsBar:ListContent/ShoppingCart/shopping-cart.html.twig", $orderInfo);
 }
コード例 #3
0
 public function createAction(Request $request)
 {
     $fields = $request->request->all();
     $user = $this->getCurrentUser();
     if (!$user->isLogin()) {
         return $this->createMessageResponse('error', '用户未登录,创建订单失败。');
     }
     if (!array_key_exists("targetId", $fields) || !array_key_exists("targetType", $fields)) {
         return $this->createMessageResponse('error', '订单中没有购买的内容,不能创建!');
     }
     $targetType = $fields["targetType"];
     $targetId = $fields["targetId"];
     $priceType = "points";
     $processor = OrderProcessorFactory::create($targetType);
     try {
         list($amount, $totalPrice) = $processor->shouldPayAmount($targetId, $priceType, $fields);
         $amount = (string) (double) $amount;
         //价格比较
         if (intval($totalPrice * 100) != intval($fields["totalPrice"] * 100)) {
             $this->createMessageResponse('error', "实际价格不匹配,不能创建订单!");
         }
         //价格比较
         $orderFileds = array('priceType' => $priceType, 'totalPrice' => $totalPrice, 'amount' => $amount, 'userId' => $user["id"], 'payment' => 'points', 'targetId' => $targetId, 'pointsAmount' => empty($fields["pointsPayAmount"]) ? 0 : $fields["pointsPayAmount"]);
         //       dump($orderFileds);
         //        die;
         $order = $processor->createOrder($orderFileds);
         $user = $this->getUserService()->getCurrentUser();
         //  $hasPayPassword = $this->payPasswordCheck($hasPayPassword);
         //这里先处理积分
         $order['pointsPayAmount'] = $request->request->get('pointsPayAmount');
         $account = $this->getPointsAccountService()->getAccountByUserId($user["id"]);
         if ($order['totalPoints'] > $account['points']) {
             $order = $this->getGiftOrdersService()->cancelOrder($order["id"], '积分不足扣积分不成功');
             return $this->render('TopxiaWebBundle:GiftOrders:retrun-cancel.html.twig');
         } else {
             $data = $this->payPoints($order);
             return $this->render('TopxiaWebBundle:GiftOrders:retrun-notice.html.twig');
         }
     } catch (\Exception $e) {
         return $this->createMessageResponse('error', $e->getMessage());
     }
 }
コード例 #4
0
ファイル: OrderController.php プロジェクト: nanyi/EduSoho
 public function createAction(Request $request)
 {
     $fields = $request->request->all();
     if (isset($fields['coinPayAmount']) && $fields['coinPayAmount'] > 0) {
         $scenario = "sms_user_pay";
         if ($this->setting('cloud_sms.sms_enabled') == '1' && $this->setting("cloud_sms.{$scenario}") == 'on') {
             list($result, $sessionField, $requestField) = SmsToolkit::smsCheck($request, $scenario);
             if (!$result) {
                 return $this->createMessageResponse('error', '短信验证失败。');
             }
         }
     }
     $user = $this->getCurrentUser();
     if (!$user->isLogin()) {
         return $this->createMessageResponse('error', '用户未登录,创建订单失败。');
     }
     if (!array_key_exists("targetId", $fields) || !array_key_exists("targetType", $fields)) {
         return $this->createMessageResponse('error', '订单中没有购买的内容,不能创建!');
     }
     $targetType = $fields["targetType"];
     $targetId = $fields["targetId"];
     $maxRate = $fields["maxRate"];
     $priceType = "RMB";
     $coinSetting = $this->setting("coin");
     $coinEnabled = isset($coinSetting["coin_enabled"]) && $coinSetting["coin_enabled"];
     if ($coinEnabled && isset($coinSetting["price_type"])) {
         $priceType = $coinSetting["price_type"];
     }
     $cashRate = 1;
     if ($coinEnabled && isset($coinSetting["cash_rate"])) {
         $cashRate = $coinSetting["cash_rate"];
     }
     $processor = OrderProcessorFactory::create($targetType);
     try {
         if (isset($fields["couponCode"]) && $fields["couponCode"] == "请输入优惠码") {
             $fields["couponCode"] = "";
         }
         list($amount, $totalPrice, $couponResult) = $processor->shouldPayAmount($targetId, $priceType, $cashRate, $coinEnabled, $fields);
         $amount = (string) (double) $amount;
         $shouldPayMoney = (string) (double) $fields["shouldPayMoney"];
         //价格比较
         if (intval($totalPrice * 100) != intval($fields["totalPrice"] * 100)) {
             $this->createMessageResponse('error', "实际价格不匹配,不能创建订单!");
         }
         //价格比较
         if (intval($amount * 100) != intval($shouldPayMoney * 100)) {
             return $this->createMessageResponse('error', '支付价格不匹配,不能创建订单!');
         }
         //虚拟币抵扣率比较
         if (isset($fields['coinPayAmount']) && intval((double) $fields['coinPayAmount'] * 100) > intval($totalPrice * $maxRate * 100)) {
             return $this->createMessageResponse('error', '虚拟币抵扣超出限定,不能创建订单!');
         }
         if (isset($couponResult["useable"]) && $couponResult["useable"] == "yes") {
             $coupon = $fields["couponCode"];
             $couponDiscount = $couponResult["decreaseAmount"];
         }
         $orderFileds = array('priceType' => $priceType, 'totalPrice' => $totalPrice, 'amount' => $amount, 'coinRate' => $cashRate, 'coinAmount' => empty($fields["coinPayAmount"]) ? 0 : $fields["coinPayAmount"], 'userId' => $user["id"], 'payment' => 'alipay', 'targetId' => $targetId, 'coupon' => empty($coupon) ? '' : $coupon, 'couponDiscount' => empty($couponDiscount) ? 0 : $couponDiscount);
         $order = $processor->createOrder($orderFileds, $fields);
         if ($order["status"] == "paid") {
             return $this->redirect($this->generateUrl($processor->getRouter(), array('id' => $order["targetId"])));
         }
         return $this->redirect($this->generateUrl('pay_center_show', array('sn' => $order['sn'])));
     } catch (\Exception $e) {
         return $this->createMessageResponse('error', $e->getMessage());
     }
 }
コード例 #5
0
 public function testDoPaySuccess()
 {
     $info = array('targetId' => '1', 'payment' => 'coin', 'priceType' => 'RMB', 'totalPrice' => '0.00', 'coinRate' => '1', 'coinAmount' => '0.00', 'note' => '11', 'coupon' => '123', 'couponDiscount' => '0.0');
     $user = $this->createUser();
     $currentUser = new CurrentUser();
     $currentUser->fromArray($user);
     $this->getServiceKernel()->setCurrentUser($currentUser);
     $textClassroom = array('title' => 'test');
     $classroom = $this->getClassroomService()->addClassroom($textClassroom);
     $this->getClassroomService()->publishClassroom($classroom['id']);
     //publish
     $processor = OrderProcessorFactory::create('classroom');
     $order = $processor->createOrder($info, array('targetId' => $classroom['id'], 'targetType' => 'classroom'));
     $result1 = $processor->doPaySuccess('success', $order);
     $result2 = $processor->doPaySuccess('', $order);
     $this->assertNull($result1);
     $this->assertNull($result2);
 }
コード例 #6
0
 public function generateOrderToken($order, $params)
 {
     $processor = OrderProcessorFactory::create($order["targetType"]);
     return $processor->updateOrder($order['id'], array('token' => $params['agent_bill_id']));
 }
コード例 #7
0
ファイル: order.php プロジェクト: latticet/EduSoho_jb51
$api->get('/show/{orderId}', function ($orderId) {
    $order = convert($orderId, 'order');
    return filter($order, 'order');
});
//创建一条订单信息
$api->post('/course/{courseId}/create', function (Request $request, $courseId) {
    $fields = $request->request->all();
    $user = getCurrentUser();
    $targetType = $fields["targetType"];
    $targetId = $courseId;
    // $maxRate = $fields["maxRate"];
    $totalPrice = $fields["totalPrice"];
    $amount = $fields["shouldPayMoney"];
    $cashRate = 1;
    $priceType = "RMB";
    $processor = OrderProcessorFactory::create($targetType);
    $orderFileds = array('priceType' => $priceType, 'totalPrice' => $totalPrice, 'amount' => $amount, 'coinRate' => $cashRate, 'coinAmount' => empty($fields["coinPayAmount"]) ? 0 : $fields["coinPayAmount"], 'userId' => $user["id"], 'payment' => 'alipay', 'targetId' => $targetId, 'coupon' => empty($coupon) ? '' : $coupon, 'couponDiscount' => empty($couponDiscount) ? 0 : $couponDiscount);
    $order = $processor->createOrder($orderFileds, $fields);
    return filter($order, 'order');
});
//显示一条订单信息
// $api->get('/detail', function ($id) {
//     $order = convert($id,'order');
//     return filter($order, 'order');
// });
//显示我的订单列表 全部 待支付 已支付 已取消
$api->get('/list', function (Request $request) {
    $user = getCurrentUser();
    $orders = array();
    $orderBy = array('id', 'DESC');
    $start = $request->query->get('start', 0);
コード例 #8
0
ファイル: OrderProcessorImpl.php プロジェクト: ccq18/EduSoho
 public function payVip()
 {
     $targetId = $this->getParam("targetId");
     if (empty($targetId)) {
         return $this->createErrorResponse('error', '创建订单数据失败!');
     }
     $token = $this->controller->getUserToken($this->request);
     $user = $this->controller->getUser();
     if (!$user->isLogin()) {
         return $this->createErrorResponse('not_login', '用户未登录,购买失败!');
     }
     $payVip = $this->controller->getLevelService()->getLevel($targetId);
     if (!$payVip) {
         return $this->createErrorResponse('error', '购买的vip类型不存在!');
     }
     $fields = $this->request->query->all();
     $vip = $this->controller->getVipService()->getMemberByUserId($user['id']);
     if ($vip) {
         $currentVipLevel = $this->controller->getLevelService()->getLevel($vip["levelId"]);
         if ($payVip["seq"] > $currentVipLevel["seq"]) {
             $fields["buyType"] = "upgrade";
         } else {
             return $this->createErrorResponse('error', '会员类型不能降级付费!');
         }
         $fields["buyType"] = "renew";
     } else {
         $fields["buyType"] = "new";
     }
     $fields["targetType"] = "vip";
     $targetType = "vip";
     $priceType = "RMB";
     $coinSetting = $this->controller->setting("coin");
     $coinEnabled = isset($coinSetting["coin_enabled"]) && $coinSetting["coin_enabled"];
     if ($coinEnabled && isset($coinSetting["price_type"])) {
         $priceType = $coinSetting["price_type"];
     }
     $cashRate = 1;
     if ($coinEnabled && isset($coinSetting["cash_rate"])) {
         $cashRate = $coinSetting["cash_rate"];
     }
     if (!isset($fields["couponCode"])) {
         $fields["couponCode"] = "";
     }
     $processor = OrderProcessorFactory::create($targetType);
     list($amount, $totalPrice, $couponResult) = $processor->shouldPayAmount($targetId, $priceType, $cashRate, $coinEnabled, $fields);
     $fields["totalPrice"] = $totalPrice;
     $orderFileds = array('priceType' => "RMB", 'totalPrice' => $totalPrice, 'amount' => $amount, 'coinAmount' => 0, 'coinRate' => $cashRate, 'userId' => $user["id"], 'payment' => 'alipay', 'targetId' => $targetId, 'coupon' => empty($coupon) ? '' : $coupon, 'couponDiscount' => empty($couponDiscount) ? 0 : $couponDiscount);
     $order = $processor->createOrder($orderFileds, $fields);
     if ($order['status'] == 'paid') {
         return array('status' => 'ok', 'paid' => true, 'message' => '', 'payUrl' => '');
     }
     return $this->payByAlipay($order, $token["token"]);
 }
コード例 #9
0
 public function orderQueryAction(Request $request)
 {
     $orderId = $request->query->get('orderId');
     $order = $this->getOrderService()->getOrder($orderId);
     $paymentRequest = $this->createPaymentRequest($order, array('returnUrl' => '', 'notifyUrl' => '', 'showUrl' => ''));
     $returnXml = $paymentRequest->orderQuery();
     $returnArray = $this->fromXml($returnXml);
     if ($returnArray['trade_state'] == 'SUCCESS') {
         $payData = array();
         $payData['status'] = 'success';
         $payData['payment'] = 'wxpay';
         $payData['amount'] = $order['amount'];
         $payData['paidTime'] = time();
         $payData['sn'] = $returnArray['out_trade_no'];
         list($success, $order) = $this->getPayCenterService()->pay($payData);
         $processor = OrderProcessorFactory::create($order["targetType"]);
         if ($success) {
             return $this->createJsonResponse(true);
         } else {
             return $this->createJsonResponse(false);
         }
     } else {
         return $this->createJsonResponse(false);
     }
 }
コード例 #10
0
 protected function getOrderInfo($order)
 {
     $fields = array('targetType' => $order['targetType'], 'targetId' => $order['targetId']);
     if ($order['targetType'] == 'vip') {
         $defaultBuyMonth = $this->setting('vip.default_buy_months');
         $fields['unit'] = $order['data']['unitType'];
         $fields['duration'] = $order['data']['duration'];
         $fields['defaultBuyMonth'] = $defaultBuyMonth;
         $fields['buyType'] = $order['data']['buyType'];
     }
     $processor = OrderProcessorFactory::create($order['targetType']);
     $orderInfo = $processor->getOrderInfo($order['targetId'], $fields);
     return $orderInfo;
 }
コード例 #11
0
 private function generateOrderToken($params)
 {
     $processor = OrderProcessorFactory::create($params['targetType']);
     return $processor->generateOrderToken();
 }
コード例 #12
0
 public function showTargetAction(Request $request)
 {
     $orderId = $request->query->get("id");
     $order = $this->getOrderService()->getOrder($orderId);
     $processor = OrderProcessorFactory::create($order["targetType"]);
     $router = $processor->getRouter();
     return $this->redirect($this->generateUrl($router, array('id' => $order['targetId'])));
 }