hasMany('DeliveryRule','delivery_id','id'); } /** * 运费算法 * @param Delivery $delivery * @param int $number * @return int */ public static function algorithm($delivery, $number) { $deliveryPrice = 0; $delivery['first'] = $delivery['first'] == 0 ? 1 : $delivery['first']; $delivery['additional'] = $delivery['additional'] == 0 ? 1 : $delivery['additional']; for ($i = 0; $i < $number; ) { if ($i === 0) { $deliveryPrice = bcadd($delivery['first_fee'], $deliveryPrice, 2); $i += $delivery['first']; } else { $deliveryPrice = bcadd($delivery['additional_fee'], $deliveryPrice, 2); $i += $delivery['additional']; } } return $deliveryPrice; } }