예제 #1
0
 /**
  * 安比购买抢客劵
  * @param $broker
  * @param $coupon
  * @param $amount
  * @param $payType
  * @param $source
  * @return array()
  */
 public function buyCouponByAnbi($broker, $coupon, $amount, $payType, $source)
 {
     $result = array('status' => 'error', 'msg' => '', 'order' => '');
     $brokerId = $broker['brokerId'];
     //查询账户余额是否足够
     $balance = Bll_Service_Payment::balance(Bll_Service_Payment::SITE_ANJUKE, array('userId' => $broker['userId']));
     if (empty($balance) || $balance['status'] != 'ok') {
         $result['msg'] = '查询余额失败,稍后再试';
         return $result;
     }
     $userAccountAll = $balance['data']['balance'];
     //账户余额
     $needAccount = $coupon['disPrice'] * $amount;
     // 待扣费金额
     if ($userAccountAll < $needAccount || $needAccount < 0) {
         $result['msg'] = '余额不足,请充值';
         return $result;
     }
     // 创建订单
     $order = Bll_CustomerRush_Order::getInstance()->createOrder($brokerId, "", $coupon, $amount, $payType, $source);
     //$requestId = Bll_Customerrush_Payment_Common::getInstance()->createRequsetId("charge",$order['id']);
     $requestId = Bll_Customerrush_Payment_Common::getInstance()->createChargeRequsetId($order['orderNo']);
     $order->msg = json_encode(array("requestId" => $requestId));
     // 保存requestId;
     $order->updateTime = date("Y-m-d H:i:s");
     $order->save();
     // 调用扣费接口
     $cusumeResult = Bll_Customerrush_Payment_Common::getInstance()->chargeMoneyByAnbi($brokerId, $broker['userId'], $requestId, $needAccount);
     if ($cusumeResult['status'] != 'ok') {
         $result['msg'] = '扣费失败,请稍后再试。';
         return $result;
     }
     // 记录扣费日志
     $log2 = array('brokerId' => $brokerId, 'accountId' => 0, 'price' => $needAccount, 'realPrice' => $needAccount, 'amount' => 0, 'requestId' => $requestId, 'type' => 2, 'createTime' => time());
     Bll_CustomerRush_Payment_Log::getInstance()->insertBrokerBalanceLog($log2);
     // 更新订单
     $order->status = Model_Mobile_CustomerOrder::STATUS_OK;
     $order->msg = json_encode(array("payInfo" => "success", "requestId" => $requestId));
     $order->updateTime = date("Y-m-d H:i:s");
     $order->save();
     // 给经纪人加劵
     for ($i = 0; $i < $order->num; $i++) {
         $addCoupon = array('brokerId' => $brokerId, 'couponId' => $order['couponId'], 'status' => Model_Mobile_CustomerBrokerCoupon::STATUS_OK_USE, 'totalNum' => $coupon['totalNum'], 'usedNum' => 0, 'updateTime' => date("Y-m-d H:i:s"), 'createTime' => time(), 'orderId' => $order['id']);
         Bll_CustomerRush_Coupon::getInstance()->insertBrokerCoupon($addCoupon);
     }
     $result['status'] = 'ok';
     $result['order'] = $order;
     return $result;
 }
예제 #2
0
 public function createOrder($brokerId, $accountId, $coupon, $num, $payType, $source)
 {
     if (empty($brokerId) || empty($coupon)) {
         return false;
     }
     $arr = array('brokerId' => $brokerId, 'accountId' => $accountId, 'couponId' => $coupon['id'], 'num' => $num, 'price' => $coupon['disPrice'] * $num, 'status' => Model_Mobile_CustomerOrder::STATUS_UNDO, 'payType' => $payType, 'source' => $source, 'isInvoiced' => Model_Mobile_CustomerOrder::IS_INVOICED_NO, 'createTime' => time(), 'updateTime' => date("Y-m-d H:i:s"));
     $orderId = $this->insertData($arr);
     if (empty($orderId)) {
         throw new Exception("create order fail");
     }
     // 更新订单号
     $orderNo = Bll_Customerrush_Payment_Common::getInstance()->createOrderNo("buy", $orderId);
     // 获取订单数据
     $tmpOrder = $this->getDataByOrderId($orderId, true);
     if (empty($tmpOrder)) {
         throw new Exception("get order data fail");
     } else {
         $order = $tmpOrder[0];
     }
     $order->orderNo = $orderNo;
     $order->updateTime = date("Y-m-d H:i:s");
     $order->save();
     return $order;
 }