public function generateUserWaitingTransferTable($request) { $userModel = new User(); $datatables = new DataTables(); $orderDetailModel = new orderDetailModel(); $commissionService = new commissionService(); $columns = array(array('db' => 'users.id', 'dt' => 0), array('db' => 'users.name', 'dt' => 1), array('db' => 'users.phone', 'dt' => 2), array('db' => 'orders.order_code AS product_quantity', 'dt' => 3), array('db' => 'orders.discount AS commission_total', 'dt' => 4), array('db' => 'users.created', 'dt' => 5), array('db' => 'users.updated_at', 'dt' => 6)); $return = $userModel->generateUserWaitingTransferTable($request, $columns); if (count($return['data'])) { foreach ($return['data'] as &$res) { $validCommission = $orderDetailModel->validCommission($res->id); $trimCommission = $commissionService->trimCommission($validCommission); $res->product_quantity = count($validCommission); $res->commission_total = formatMoney($trimCommission['total']); } } $return['data'] = $datatables::data_output($columns, $return['data']); return $return; }
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]); }