购物车类,求批,标题长点。不然引不起关注。。。。。。。。。。。
时间:2011-08-10
来源:互联网
望大家有望相批

<?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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28