[TOC]
# 关于人人运费模板
之前就分享过一篇文章,这里就不过多的讲解了,反正设计人人运费光看后台就有很多种,
看order里的``create.php``里搜索``discountprice``就知道有多么的复杂了
这里直接贴代码
## 重量的计算
`
$zhongliang=0;
$order_goods = pdo_getall('ewei_shop_order_goods', array('orderid' => $order['id']));
foreach ($order_goods as $key => $value) {
$goods = pdo_get('ewei_shop_goods', array('id' => $value['goodsid']));
$order_goods[$key]['thumb'] =tomedia($goods['thumb']) ;
if($value['optionname']==$goods['guige1']){
$zhongliang+=intval($goods['guige1']);
}else if($value['optionname']==$goods['guige2']){
$zhongliang+=intval($goods['guige2']);
}else if($value['optionname']==$goods['guige3']){
$zhongliang+=intval($goods['guige3']);
}
}
`
## 具体代码
```
$cart= pdo_getall('ewei_shop_goods', array('id' => $order_goods['goodsid']));
if($cart[0]['dispatchtype']==1){
$yunfei=$cart[0]['dispatchprice'];
}else{
//默认模版
if(empty($cart[0]['dispatchid'])){
//calculatetype 0按重量计费 1按件计费
$dispatch = pdo_get('ewei_shop_dispatch', array('isdefault' => 1,"uniacid"=>$_W['uniacid']));
}else{
$dispatch = pdo_get('ewei_shop_dispatch', array('id' => $cart[0]['dispatchid']));
}
$kuaidi = pdo_get('ewei_shop_express', array('express' => $dispatch['express']));
//isdispatcharea 0 不配送区域 1 只配送区域
//nodispatchareas 不配送区域
$ispeisong=0;
if($dispatch['isdispatcharea']==1){
if(strpos($dispatch['nodispatchareas'],$address['city']) !== false){
}else{
$ispeisong=1;
$noadd="当前区域不支持配送";
}
}else{
if(strpos($dispatch['nodispatchareas'],$address['city']) !== false){
$ispeisong=1;
$noadd=$address['city']."不支持配送";
}
}
$area=iunserializer($dispatch['areas']);
$areaid=0;
foreach ($area as $key => $value) {
if(strpos($value['citys'],$address['city']) !== false){
$areaid=$key+1;
}
}
if(empty($dispatch)){
$yunfei=0;
}else{
//jfguige 按件计费
//firstnum 首件
//firstnumprice 运费
//secondnum 续件
//secondnumprice 续费
//按件计费
if($dispatch['calculatetype']==1){
$jianshu=count($order_goods);
if(!empty($areaid)){
$areaid=$areaid-1;
if($jianshu<=$area[$areaid]['firstnum']){
$yunfei=$area[$areaid]['firstnumprice'];
}else{
$yunfei=intval(($jianshu-$area[$areaid]['firstnum'])/$area[$areaid]['secondnum'])*$area[$areaid]['secondnumprice']+$area[$areaid]['firstnumprice'];
}
//freeprice 满额
if($yunfei>=$area[$areaid]['freeprice']&&!empty($area[$areaid]['freeprice'])){
$yunfei=0;
}
}else{
if($jianshu<=$dispatch['firstnum']){
$yunfei=$dispatch['firstnumprice'];
}else{
$yunfei=intval(($jianshu-$dispatch['firstnum'])/$dispatch['secondnum'])*$dispatch['secondnumprice']+$dispatch['firstnumprice'];
}
//freeprice 满额
if($yunfei>=$dispatch['freeprice']&&!empty($dispatch['freeprice'])){
$yunfei=0;
}
}
}else{
//firstweight 默认重量
//secondweight 续重
//secondprice 续费
//firstprice 默认价格
if(!empty($areaid)){
$areaid=$areaid-1;
if($zhongliang<=$area[$areaid]['firstweight']){
$yunfei=$area[$areaid]['firstprice'];
}else{
$yunfei=intval(($zhongliang-$area[$areaid]['firstweight'])/$area[$areaid]['secondweight'])*$area[$areaid]['secondprice']+$area[$areaid]['firstprice'];
}
//freeprice 满额
if($yunfei>=$area[$areaid]['freeprice']&&!empty($area[$areaid]['freeprice'])){
$yunfei=0;
}
}else{
if($zhongliang<=$dispatch['firstweight']){
$yunfei=$dispatch['firstprice'];
}else{
$yunfei=intval(($zhongliang-$dispatch['firstweight'])/$dispatch['secondweight'])*$dispatch['secondprice']+$dispatch['firstprice'];
}
//freeprice 满额
if($yunfei>=$dispatch['freeprice']&&!empty($dispatch['freeprice'])){
$yunfei=0;
}
}
}
}
}
```
## 不配送区域