|
@@ -302,7 +302,7 @@ class RefillBase
|
|
|
|
|
|
$mod_refill = Model('refill_order');
|
|
|
$channel_amount = $price * $order->quantity();
|
|
|
- [$order_success,$order_id,$order_sn] = $this->create_refill_order($order,$goods_id,$minfo,$calc,$channel_name,$channel_amount,$mch_amount);
|
|
|
+ [$order_success,$order_id,$order_sn] = $this->create_order($order,$goods_id,$minfo,$calc,$channel_name,$channel_amount,$mch_amount);
|
|
|
$last_orderid = $order_id;
|
|
|
if(!$order_success) continue;
|
|
|
|
|
@@ -393,32 +393,12 @@ class RefillBase
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private function create_refill_order(order $order,$goods_id,$minfo,$calc,$ch_name,$ch_amount,$mch_amount)
|
|
|
+ private function create_order(order $order, $goods_id, $minfo, $calc, $ch_name, $ch_amount, $mch_amount)
|
|
|
{
|
|
|
- try
|
|
|
+ $refill_creater = function (order $order,$last_orderid,$order_id,$order_sn,$mod_refill) use($ch_name, $ch_amount,$mch_amount)
|
|
|
{
|
|
|
- $fTrans = false;
|
|
|
- $logic_buy_virtual = Logic('buy_virtual');
|
|
|
- $mod_refill = Model('refill_order');
|
|
|
- if($fTrans) {
|
|
|
- $trans = new trans_wapper($mod_refill,__METHOD__);
|
|
|
- } else {
|
|
|
- $start = microtime(true);
|
|
|
- }
|
|
|
-
|
|
|
- $input['goods_id'] = $goods_id;
|
|
|
- $input['quantity'] = $order->quantity();
|
|
|
- $input['buyer_phone'] = $minfo->mobile();
|
|
|
- $input['buyer_name'] = $minfo->truename();
|
|
|
- $input['buyer_msg'] = $_POST['buyer_msg'] ?? '';
|
|
|
- $input['order_from'] = 1;
|
|
|
- $input['pd_pay'] = true;
|
|
|
- $result = $logic_buy_virtual->buyStep3($input, $order->buyer_id(), [$calc, 'calc_vorder_amount'], true, false);
|
|
|
- if ($result['state'] === true)
|
|
|
+ try
|
|
|
{
|
|
|
- $order_sn = $result['data']['order_sn'];
|
|
|
- $order_id = $result['data']['order_id'];
|
|
|
- $last_orderid = $order->last_order_id();
|
|
|
if($last_orderid > 0) {
|
|
|
$mod_refill->edit($last_orderid, ['inner_status' => 1]);
|
|
|
}
|
|
@@ -438,46 +418,69 @@ class RefillBase
|
|
|
|
|
|
$order->commit_times_inc();
|
|
|
$orderext = $order->refill_params($order_id,$order_sn,$refill_amount, $ch_name, $ch_amount,$mch_amount);
|
|
|
- $mod_refill->add_refill($orderext);
|
|
|
+ $fInsert = $mod_refill->add_refill($orderext);
|
|
|
|
|
|
if($order->is_third()) {
|
|
|
$ext = $order->third_extparams($order_id,$order_sn);
|
|
|
$thrid_refill->addExt($ext);
|
|
|
}
|
|
|
|
|
|
- if(!$this->pay_completed($order_sn))
|
|
|
- {
|
|
|
- $logic_vr_order = Logic("vr_order");
|
|
|
- $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
|
|
|
- $logic_vr_order->changeOrderStateCancel($order_info, '', "预存款不足以支付该订单",true,true);
|
|
|
- if($fTrans) {
|
|
|
- $trans->commit();
|
|
|
- }
|
|
|
- return [false,$order_id,$order_sn];
|
|
|
+ if(!$fInsert) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
}
|
|
|
- elseif($fTrans) {
|
|
|
- $trans->commit();
|
|
|
+ }
|
|
|
+ catch (Exception $ex)
|
|
|
+ {
|
|
|
+ Log::record($ex->getMessage(),Log::ERR);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ $logic_buy_virtual = Logic('buy_virtual');
|
|
|
+ $mod_refill = Model('refill_order');
|
|
|
+
|
|
|
+ $input['goods_id'] = $goods_id;
|
|
|
+ $input['quantity'] = $order->quantity();
|
|
|
+ $input['buyer_phone'] = $minfo->mobile();
|
|
|
+ $input['buyer_name'] = $minfo->truename();
|
|
|
+ $input['buyer_msg'] = $_POST['buyer_msg'] ?? '';
|
|
|
+ $input['order_from'] = 1;
|
|
|
+ $input['pd_pay'] = true;
|
|
|
+
|
|
|
+ $start = microtime(true);
|
|
|
+ $result = $logic_buy_virtual->buyStep3($input, $order->buyer_id(), [$calc, 'calc_vorder_amount'], true, true);
|
|
|
+ if ($result['state'] === true)
|
|
|
+ {
|
|
|
+ $order_sn = $result['data']['order_sn'];
|
|
|
+ $order_id = $result['data']['order_id'];
|
|
|
+ $last_orderid = $order->last_order_id();
|
|
|
+ $fSuccess = $refill_creater($order,$last_orderid,$order_id,$order_sn,$mod_refill);
|
|
|
+ if(!$fSuccess) {
|
|
|
+ Log::record("refill_creater fail:order_sn={$order_sn}",Log::ERR);
|
|
|
}
|
|
|
- else {
|
|
|
- Log::record(sprintf(__METHOD__ . " request time=%.6f", microtime(true) - $start), Log::DEBUG);
|
|
|
+ if (!$this->pay_completed($order_sn)) {
|
|
|
+ $logic_vr_order = Logic("vr_order");
|
|
|
+ $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
|
|
|
+ $logic_vr_order->changeOrderStateCancel($order_info, '', "预存款不足以支付该订单", true, true);
|
|
|
+ return [false, $order_id, $order_sn];
|
|
|
}
|
|
|
|
|
|
+ Log::record(sprintf(__METHOD__ . " request time=%.6f", microtime(true) - $start), Log::DEBUG);
|
|
|
return [true,$order_id,$order_sn];
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if ($fTrans) $trans->commit();
|
|
|
- Log::record("{$result['msg']}", Log::ERR);
|
|
|
-
|
|
|
+ Log::record(__METHOD__ . " fail:buyStep3 err msg={$result['msg']}", Log::ERR);
|
|
|
return [false,0,''];
|
|
|
}
|
|
|
}
|
|
|
catch (Exception $ex)
|
|
|
{
|
|
|
Log::record($ex->getMessage(), Log::ERR);
|
|
|
- if($fTrans) {
|
|
|
- $trans->rollback();
|
|
|
- }
|
|
|
return [false,0,''];
|
|
|
}
|
|
|
}
|