public function transferPayment($orderDetailIds, $userId, $ref, $note) { $orderDetailModel = new orderDetailModel(); $partnerPaymentModel = new partnerPaymentModel(); $partnerPaymentDetailModel = new partnerPaymentDetailModel(); $total = 0; $dataPartnerPayment = ['user_id' => $userId, 'ref' => $ref, 'note' => $note, 'total' => $total]; $payment = $partnerPaymentModel->createItem($dataPartnerPayment); $validCommission = $orderDetailModel->validCommission($userId); foreach ($validCommission as $commission) { if (in_array($commission->id, $orderDetailIds)) { $price = $commission->subtotal * PARTNER_DISCOUNT_PERCENT_LEVEL_1 / 100; $dataPartnerPaymentDetail = ['payment_id' => $payment->id, 'order_detail_id' => $commission->id, 'total' => $price]; $total += $price; $partnerPaymentDetailModel->createItem($dataPartnerPaymentDetail); } } return $partnerPaymentModel->updateItem($payment->id, ['total' => $total]); }