PHP每月发票/帐单

时间:2016-02-23 12:21:46

标签: php sql paypal

我想创建一个结算系统。该系统应在其个人资料中显示他们所服务的服务的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';
?>

1 个答案:

答案 0 :(得分:0)

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

  • 优惠(身份证,价格,姓名)
  • 用户(身份证,姓名)
  • 订阅(id,offer_id,user_id,startDate)

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