db->beginTransaction(); $paymentOrder = \app\models\PaymentOrder::findOne(['order_no' => $paymentOrder->orderNo, 'notify_status' => [0,2]]); if($paymentOrder == null){ return $this->apiReturnError('支付回调已经处理或不存在'); } $paymentOrder->notify_status = 1; if(!$paymentOrder->save()){ $t->rollBack(); return $this->getModelError($paymentOrder); } //订单状态 $order = Order::findOne(['order_no' => $paymentOrder->order_no]); if($order == null){ $t->rollBack(); return $this->apiReturnError('订单不存在'); } $order->pay_type = $paymentOrder->pay_type; $order->is_pay = 1; $order->pay_time = time(); $order->total_pay_price = $paymentOrder->amount; $order->status = 1; $order_type = UniqueOrderNo::getOrderTypeByOrderNo($order->order_no); $user = User::findOne(['id' => $order->user_id,'is_delete' => 0]); if($user != null && $user->parent_id != 0 && $order->total_pay_price > 0){ $shareRatio = SiteHelper::getCustomiseOptionByKey("shareRatio", "hump"); $money = substr(sprintf("%.3f",$order->total_pay_price * ($shareRatio / 100)),0,-1); $desc = '下级预约包厢-'.$user->nickname.'-'.$user->mobile_phone; $r = Integral::userIntegralWalletLog($user->parent_id,Integral::TYPE_INCOME,$money,$desc,$order_type,$order->order_no); if($r['code'] != 0){ $t->rollBack(); return Model::asReturnError("订单积分异常"); } } if(!empty($order->integral) && $order->integral > 0){ $desc = '包厢预约抵扣'; $integral = sprintf("%.2f",$order->integral); $r = Integral::userIntegralWalletLog($order->user_id,Integral::TYPE_PAY,$integral,$desc,$order_type,$order->order_no); if($r['code'] != 0){ $t->rollBack(); return Model::asReturnError("订单积分异常"); } } if($order->pay_type == 1){ //账户变动日志 $balance_log = new BalanceLog(); $balance_log->cx_mch_id = 0; $balance_log->scene = 0; $balance_log->type = 2; $balance_log->user_id = $order->user_id; $balance_log->money = $order->total_pay_price; $balance_log->before_account_balance = empty($user->balance) ? 0 : $user->balance->account_balance; $balance_log->after_account_balance = empty($user->balance) ? 0 : $user->balance->account_balance; $balance_log->desc = '预定包厢-微信支付'; $balance_log->order_type = $order_type; $balance_log->order_no = $order->order_no; $balance_log->ext = ''; $balance_log->save(); if($order->cancel_status == 1){ $order->cancel_status = 0; $order->cancel_time = 0; } } if(!$order->save()){ $t->rollBack(); return $this->getModelError($order); } $t->commit(); return $this->apiReturnSuccess(); } }