public function stockDec() { if (IS_POST || IS_AJAX) { //计算收益 $gain = calcGain(); //更新库存 updateStock(); //增加日志 updateStockLog(); if (IS_AJAX) { } } else { $this->display(); } }
$db->rollback(); echo json_encode(-1); return; } } $db->commit(); echo json_encode(1); } else { if ($decoded->function == 'updatePedido') { updatePedido($decoded->pedido); } else { if ($decoded->function == 'updatePedidoDetalle') { updatePedidoDetalle($decoded->pedido_detalle); } else { if ($decoded->function == 'updateStock') { updateStock($decoded->stock); } else { if ($decoded->function == 'removePedido') { removePedido($decoded->pedido_id); } else { if ($decoded->function == 'removePedidoDetalle') { removePedidoDetalle($decoded->pedido_detalle_id); } else { if ($decoded->function == 'removeStock') { removeStock($decoded->stock_id); } else { if ($decoded->function == 'trasladar') { trasladar($decoded->origen_id, $decoded->destino_id, $decoded->producto_id, $decoded->cantidad); } } }
<?php // Build items array $items = []; foreach ($cart->getItems() as $i => $item) { $items[] = ['uri' => $item->uri, 'variant' => $item->variant, 'quantity' => $item->quantity]; } // Update stock updateStock($items); // Notify staff $notifications = page('shop')->notifications()->toStructure(); if ($notifications->count()) { foreach ($notifications as $n) { // Reset $send = false; // Check if the products match $uids = explode(',', $n->products()); if ($uids[0] === '') { $send = true; } else { foreach ($uids as $uid) { foreach ($items as $item) { if (strpos($item['uri'], trim($uid))) { $send = true; } } } } // Send the email if ($send) { $body = 'Someone made a purchase from ' . server::get('server_name') . "\n\n";
printf("no results!"); } mysqli_free_result($result); return $array; } $con = mysqli_connect("dbhost.cs.man.ac.uk", "mbbx9mg3", "Fincherz+2013") or die("Error " . mysqli_error($link)); mysqli_select_db($con, "mbbx9mg3"); $validNewAmount = false; if (isset($_POST["submit_button"])) { $itemSelected = $_POST['item']; $newAmount = $_POST['newAmount']; $message = ""; $validNewAmount = is_numeric($newAmount) && $newAmount >= 0; if ($validNewAmount) { $id = getItemID($itemSelected, $con); updateStock($id, $newAmount, $con); $message = "Stock updated successfully!"; } else { $message = "Please check your input again!\n is int: " . is_int($newAmount) . ", >= 0 : " . ($newAmount >= 0) . ""; } } // isInserted $array = selectItems($con); mysqli_close($con); ?> <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. -->
<?php // This page is the endpoint of PayPal's IPN callback. // Only the PayPal server accesses this page, so no need to include redirects if ($_POST['txn_id'] != '') { snippet('payment.success.paypal.ipn'); // Validate the PayPal transaction against the pending order $txn = page('shop/orders/' . $_POST['custom']); if ($txn->subtotal()->value == $_POST['mc_gross'] - $_POST['mc_shipping'] - $_POST['tax'] and $txn->shipping()->value == $_POST['mc_shipping'] and $txn->tax()->value == $_POST['tax'] and $txn->txn_currency() == $_POST['mc_currency']) { try { // Update transaction record $txn->update(['paypal-txn-id' => $_POST['txn_id'], 'status' => strtolower($_POST['payment_status']), 'payer-id' => $_POST['payer_id'], 'payer-name' => $_POST['first_name'] . " " . $_POST['last_name'], 'payer-email' => $_POST['payer_email'], 'payer-address' => $_POST['address_street'] . "\n" . $_POST['address_city'] . ", " . $_POST['address_state'] . " " . $_POST['address_zip'] . "\n" . $_POST['address_country']]); // Update product stock updateStock(unserialize(urldecode($txn->encoded_items()))); } catch (Exception $e) { return false; } } } else { // Data didn't come back properly from PayPal return false; }
<?php /** * Order callback snippet * This snippet is called from each gateway's callback script. It updates stock and notifies staff of the new order. * * Expected pass-through variables: * $txn page object * $status string * $payer_name string * $payer_email string * $payer_address string */ // Update stock updateStock($txn); // Notify staff $notifications = page('shop')->notifications()->toStructure(); if ($notifications->count()) { foreach ($notifications as $n) { // Reset $send = false; // Check if the products match $uids = explode(',', $n->products()); if ($uids[0] === '') { $send = true; } else { foreach ($uids as $uid) { foreach ($txn->products()->toStructure() as $item) { if (strpos($item->uri(), trim($uid))) { $send = true; }
if ($total === $totalinst && $change === $changeinst) { // calculation validation $conn = new mysqli($GLOBALS['servername'], $GLOBALS['dbuser'], $GLOBALS['dbpass'], $GLOBALS['dbname']); if ($conn->connect_error) { die('Error establishing connection to the database server! Error: ' . $conn->connect_error); } $date = date('Y/m/d H:i:s'); $query = "INSERT INTO `eb_total_penjualan`\r\n\t\t\t(`totalharga`, `bayar`, `kembali`, `tanggal`) \r\n\t\t\tVALUES (" . (string) $total . "," . (string) $paymentinst . "," . $change . ",\r\n\t\t\t\t\t'" . $date . "')"; $res = $conn->query($query); if ($res === true) { $id = $conn->insert_id; $summary = true; for ($i = 0; $i < count($barangs); $i++) { $query2 = "INSERT INTO `eb_penjualan`\r\n\t\t\t\t\t\t\t(`idbarang`, `iduser`, `idpenjualan`, `jumlah`, \r\n\t\t\t\t\t\t\t`currenthargabeli`, `currenthargajual`, `tanggal`) \r\n\t\t\t\t\t\t\tVALUES (" . $barangs[$i]->id . "," . $userid . "," . $id . "," . $barangs[$i]->jumlah . ",\r\n\t\t\t\t\t\t\t" . $barangs[$i]->hargabeli . "," . $barangs[$i]->hargajual . ",'" . $date . "')"; $res2 = $conn->query($query2); if ($res2 === false || updateStock($barangs[$i]->id, $barangs[$i]->jumlah * -1) === false) { $summary = false; } } if ($summary === true) { $class = new stdClass(); $class->status = 0; $class->desc = 'Berhasil memasukkan seluruh penjualan!'; echo json_encode($class); return; } else { $class = new stdClass(); $class->status = 1; $class->desc = 'Terjadi kesalahan dalam memasukkan item penjualan!'; echo json_encode($class); return;