php盒子类计算体积,php – 计算出货箱尺寸的粗略估计

我正在努力寻找计算运输所需箱子尺寸的最佳方法.

我有3个不同尺寸的集装箱.我在数据库中定义了产品的宽度,长度,深度和质量.

我想知道如何找到最小数量的箱子,以及购物车中物品数量的最小尺寸.

我当前的’想法’是找到整个产品阵列的最大宽度,根据它选择一个框,然后根据需要拆分订单…这似乎不起作用.

我的盒子大小是:

– 8 x 6 x 6 = 228立方英寸

– 10 x 8 x 8 = 640立方英寸

– 12.5 x 12.5 x 12.5 = 1953.125立方英寸

产品定义如下:

[Product] => Array

(

[STOCK_CODE] => 010003

[Product_Slug] => GABA_010003

[ItemName] => GABA

[WHOLESALE_PRICE] => 17.47

[RETAIL_PRICE] => 24.95

[Brand] =>

[ProductLine] =>

[image_name] => 705077000440

[MASS] => 0.313

[Height] => 4.625

[Width] => 2.375

[Depth] => 2.375

[cubic_inches] => 26.087890625

)

我已经研究过背包问题,包装问题等,但找不到办法.任何帮助都会很棒.

function shipping(){

$this->CartProduct->unbindModel(

array('belongsTo' => array('User'))

);

//find all cart products by current logged in user

$cartItems = $this->CartProduct->find('all', array('conditions' => array('CartProduct.user_id' => $this->Auth->user('id'))));

$i = 0;

//get the max width, height, depth

$maxHeight = 0;

$maxWidth = 0;

$maxDepth = 0;

foreach($cartItems as $c){

$cartItems[$i]['Product']['cubic_inches'] = $c['Product']['Height'] * $c['Product']['Width'] * $c['Product']['Depth'];

$cartItems[$i]['CartProduct']['total_cubic_inches'] = ($c['Product']['Height'] * $c['Product']['Width'] * $c['Product']['Depth']) * $c['CartProduct']['qty'];

if($c['Product']['Height'] > $maxHeight)

{

$maxHeight = $c['Product']['Height'];

}

if($c['Product']['Width'] > $maxWidth)

{

$maxWidth = $c['Product']['Width'];

}

if($c['Product']['Depth'] > $maxDepth)

{

$maxDepth = $c['Product']['Depth'];

}

$i++;

}

//possible containers

//8 x 6 x 6 = 228 ci

//10 x 8 x 8 = 640 ci

//12.5 x 12.5 x 12.5 = 1953.125

$possibleContainers = array(

1 => array(

'Height' => 8,

'Width' => 6,

'Depth' => 6,

'Cubic' => 228),

2 => array(

'Height' => 10,

'Width' => 8,

'Depth' => 8,

'Cubic' => 640),

3 => array(

'Height' => 12.5,

'Width' => 12.5,

'Depth' => 12.5,

'Cubic' => 1953.125)

);

$max = array(

'Height' => $maxHeight,

'Width' => $maxWidth,

'Depth' => $maxDepth,

);

pr($cartItems);

pr($possibleContainers);

die();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值