购物车类,求批,标题长点。不然引不起关注。。。。。。。。。。。
望大家有望相批
<?php
/**
+------------------------------------------------------------------------------
* 购物车操作类库
+------------------------------------------------------------------------------
* @category ORG
* @package ORG
* @subpackage Util
* @author ty
+------------------------------------------------------------------------------
*/
class Carts extends Think{
private $list = array();//购物信息列表,数组
private $total_number = 0;//总数量
private $total_price = 0;//总价
private $total_other_price = 0;//其它价格,本站用橙豆价
private $remark = null;//订单备注信息
public function __get($name){
return $this->$name;
}
public function __construct(){}
/*
* $key 当前数据键值
* $obj 当前插入对象
* $one_price 单价
* $one_other_price 其它单价
* $single_price 单品价格小计
* $single_other_price 单品其它价格小计
* $single_number 数量
* $carts_url 单品链接地址
* $carts_type 单品类型
* */
public function IntelliMathTM($key, $obj, $number = 1, $price, $other_price, $other = array()) {
if (! array_key_exists ( $key, $this->list )) {
$this->list [$key] = $obj;
$this->list [$key] ['one_price'] = $price;
$this->list [$key] ['one_other_price'] = $other_price;
$this->list [$key] ['carts_url'] = $other ['url'];
$this->list [$key] ['carts_type'] = $other ['type'];
}
/*
* 单品计算
* */
$this->list [$key] ['single_number'] += $number; //单品数量计算
$this->list [$key] ['single_price'] += $this->list [$key] ['one_price'] * $number; //单品价格小计
$this->list [$key] ['single_other_price'] += $this->list [$key] ['one_other_price'] * $number; //单品其它价格小计
/*
* 购物车总计算
* */
$this->total_number += $number;
$this->total_price += $this->list [$key] ['one_price'] * $number;
$this->total_other_price += $this->list [$key] ['one_other_price'] * $number;
}
/*
* 删除购物车产品
* $key 所移除物品键值
* $number 移除物品数量,默认 0 全部
* */
public function RemoveCarts( $key, $number = 0 ) {
/*
* 得到删除物品计算信息
* $to_number 数量
* $to_other_price 其它形式价格
* $to_price 总价格
* */
$to_number = 0;
$to_other_price = 0;
$to_price = 0;
if( !$number || ($number == $this->list [$key] ['single_number']) || ($number > $this->list [$key] ['single_number'])){
$to_number = $this->list [$key] ['single_number'];
$to_price = $this->list [$key] ['single_price'];
$to_other_price = $this->list [$key] ['single_other_price'];
unset($this->list [$key]);
}else{
$to_number = $number;
$to_price = $this->list [$key] ['one_price'] * $number;
$to_other_price = $this->list [$key] ['one_other_price'] * $number;
//单品信息更新
$this->list [$key] ['single_number'] -= $to_number;
$this->list [$key] ['single_price'] -= $to_price;
$this->list [$key] ['single_other_price'] -= $to_other_price;
}
//购物车信息更新
$this->total_number -= $to_number;
$this->total_price -= $to_price;
$this->total_other_price -= $to_other_price;
}
}
<?php
/**
+------------------------------------------------------------------------------
* 购物车操作类库
+------------------------------------------------------------------------------
* @category ORG
* @package ORG
* @subpackage Util
* @author ty
+------------------------------------------------------------------------------
*/
class Carts extends Think{
private $list = array();//购物信息列表,数组
private $total_number = 0;//总数量
private $total_price = 0;//总价
private $total_other_price = 0;//其它价格,本站用橙豆价
private $remark = null;//订单备注信息
public function __get($name){
return $this->$name;
}
public function __construct(){}
/*
* $key 当前数据键值
* $obj 当前插入对象
* $one_price 单价
* $one_other_price 其它单价
* $single_price 单品价格小计
* $single_other_price 单品其它价格小计
* $single_number 数量
* $carts_url 单品链接地址
* $carts_type 单品类型
* */
public function IntelliMathTM($key, $obj, $number = 1, $price, $other_price, $other = array()) {
if (! array_key_exists ( $key, $this->list )) {
$this->list [$key] = $obj;
$this->list [$key] ['one_price'] = $price;
$this->list [$key] ['one_other_price'] = $other_price;
$this->list [$key] ['carts_url'] = $other ['url'];
$this->list [$key] ['carts_type'] = $other ['type'];
}
/*
* 单品计算
* */
$this->list [$key] ['single_number'] += $number; //单品数量计算
$this->list [$key] ['single_price'] += $this->list [$key] ['one_price'] * $number; //单品价格小计
$this->list [$key] ['single_other_price'] += $this->list [$key] ['one_other_price'] * $number; //单品其它价格小计
/*
* 购物车总计算
* */
$this->total_number += $number;
$this->total_price += $this->list [$key] ['one_price'] * $number;
$this->total_other_price += $this->list [$key] ['one_other_price'] * $number;
}
/*
* 删除购物车产品
* $key 所移除物品键值
* $number 移除物品数量,默认 0 全部
* */
public function RemoveCarts( $key, $number = 0 ) {
/*
* 得到删除物品计算信息
* $to_number 数量
* $to_other_price 其它形式价格
* $to_price 总价格
* */
$to_number = 0;
$to_other_price = 0;
$to_price = 0;
if( !$number || ($number == $this->list [$key] ['single_number']) || ($number > $this->list [$key] ['single_number'])){
$to_number = $this->list [$key] ['single_number'];
$to_price = $this->list [$key] ['single_price'];
$to_other_price = $this->list [$key] ['single_other_price'];
unset($this->list [$key]);
}else{
$to_number = $number;
$to_price = $this->list [$key] ['one_price'] * $number;
$to_other_price = $this->list [$key] ['one_other_price'] * $number;
//单品信息更新
$this->list [$key] ['single_number'] -= $to_number;
$this->list [$key] ['single_price'] -= $to_price;
$this->list [$key] ['single_other_price'] -= $to_other_price;
}
//购物车信息更新
$this->total_number -= $to_number;
$this->total_price -= $to_price;
$this->total_other_price -= $to_other_price;
}
}
作者: 葛滔 发布时间: 2011-08-10
大家就不能给点意见啥的
作者: 葛滔 发布时间: 2011-08-11