【问题标题】:PHP monthly Invoice/billing statementPHP 月度发票/帐单
【发布时间】:2016-06-05 06:51:14
【问题描述】:

我想创建一个计费系统。该系统应在他们的个人资料上显示他们订阅的服务的 20 美元定期付款。

如果他们在帐户中添加新金额,则报表必须根据他们选择的服务更新新金额(例如 30 美元)。

我已经在 PHP 中创建了一个购物车,我知道如何将商品添加到我的购物车并进行结帐。我只是有点困惑如何让每个用户都独一无二。 添加到购物车。

<?php
session_start();

// Get the product id
$id = isset($_GET['id']) ? $_GET['id'] : "";
$name = isset($_GET['name']) ? $_GET['name'] : "";
$quantity = isset($_GET['quantity']) ? $_GET['quantity'] : "";

 //Check if the cart array was created
 //If it isn't, create the cart array
if(!isset($_SESSION['cart_items'])){
	$_SESSION['cart_items'] = array();
}

//Check if the item is in the array, if it is, do not add
if(array_key_exists($id, $_SESSION['cart_items'])){
	// redirect to product list and tell the user it was added to cart
	header('Location: products.php?action=exists&id' . $id . '&name=' . $name);
}

//If not, then add the item to the array
else{
	$_SESSION['cart_items'][$id]=$name;
	
	//Redirects to product list
	header('Location: products.php?action=added&id' . $id . '&name=' . $name);
}
?>
购物车页面:

<?php
session_start();

$page_title="Cart";
include 'layout_head.php';

$action = isset($_GET['action']) ? $_GET['action'] : "";
$name = isset($_GET['name']) ? $_GET['name'] : "";

if($action=='removed'){
	echo "<div class='Wow danger'>";
		echo "<strong>{$name}</strong> was removed from your cart.";
	echo "</div>";
}

else if($action=='quantity_updated'){
	echo "<div class='Wow danger'>";
		echo "<strong>{$name}</strong> quantity was updated.";
	echo "</div>";
}

if(count($_SESSION['cart_items'])>0){

	//Gets the Product Id's
	$ids = "";
	foreach($_SESSION['cart_items'] as $id=>$value){
		$ids = $ids . $id . ",";
	}
	
	//Removes the comma
	$ids = rtrim($ids, ',');
	
	//Starts Table
	echo "<table class='table table-hover table-responsive table-bordered'>";
    
        // Table heading
        echo "<tr>";
            echo "<th class='textAlignLeft'>Product Name</th>";
            echo "<th>Price (USD)</th>";
			echo "<th>Action</th>";
        echo "</tr>";
		
		$query = "SELECT id, name, price FROM products WHERE id IN ({$ids}) ORDER BY name";
		
		$stmt = $con->prepare( $query );
		$stmt->execute();

		$total_price=0;
		while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
            extract($row);
			
			echo "<tr>";
				echo "<td>{$name}</td>";
				echo "<td>&#36;{$price}</td>";
				echo "<td>";
					echo "<a href='remove_from_cart.php?id={$id}&name={$name}' class='btn btn-danger'>";
						echo "<span class='shopping cart-remove'></span> Remove from cart";
					echo "</a>";
				echo "</td>";
            echo "</tr>";
			
			$total_price+=$price;
		}
		
		echo "<tr>";
				echo "<td><b>Total</b></td>";
				echo "<td>&#36;{$total_price}</td>";
				echo "<td>";
					echo "<a href='#' class='success'>";
						echo "<span class='shopping-cart'></span> Checkout";
					echo "</a>";
				echo "</td>";
            echo "</tr>";
		
	echo "</table>";
}

else{
	echo "<div class='Wow danger'>";
		echo "<strong>No products found</strong> in your cart!";
	echo "</div>";
}

include 'layout_foot.php';
?>

【问题讨论】:

    标签: php sql paypal


    【解决方案1】:

    这里真正的问题是什么?没有什么比你以前做过的更复杂了。您将有一些表格,例如:

    • 报价(ID、价格、名称)
    • 用户(ID、姓名)
    • 订阅(id、offer_id、user_id、startDate)

    只需在订阅中为用户购买的每项服务添加一个新行,然后计算他的发票总和。然后例如每天运行一个 CRON 并根据用户是否需要支付订阅费来发送电子邮件。

    【讨论】:

    • 但是我如何在 PHP 中做到这一点?
    • 没什么难的,你确定懂PHP吗?也许你应该试着再读一遍教程
    • 我只是想要一点提示,就像我说的,我是新手。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-14
    • 1970-01-01
    • 2018-01-16
    • 1970-01-01
    相关资源
    最近更新 更多