Esempio n. 1
0
 /**
  * 根据物流类型ID以及相关条件查询满足条件的物流
  * @param array $condition
  * @return array $deliveries
  * @author gehaifeng
  * 
  * $condition = array(
  *   'site_id'              => '77',    //站点id
  *   'delivery_category_id' => '9',     //物流类型ID
  *   'country_id'           => '539',   //国家ID
  *   'weight'               => '500',   //订单重量
  *   'total_price'          => '300.99',//订单总价
  * );
  * 
  * $deliveries = array(
  *   'id'                   => '10',                 //物流ID
  *   'name'                 => 'China Post',         //物流名称
  *   'url'                  => 'www.ketai-inc.com',  //物流url地址
  *   'delay'                => '5-20 days',          //物流延迟信息
  *   'delivery_price'       => '46.97',              //物流价格
  * );
  */
 public static function get_deliveries_by_condition($condition)
 {
     $category_id = $condition['delivery_category_id'];
     $weight = $condition['weight'];
     $country_id = $condition['country_id'];
     $total_price = $condition['total_price'];
     $dlv_instance = DeliveryService::get_instance();
     $dlvs = $dlv_instance->get_deliveries_by_category($category_id, $weight);
     if (empty($dlvs)) {
         return array();
     }
     $currency = BLL_Currency::get_current();
     $currency_sign = $currency['sign'];
     $deliveries = array();
     foreach ($dlvs as $dlv) {
         $flag = 0;
         $id = $dlv['id'];
         $name = $dlv['name'];
         $url = $dlv['url'];
         $delay = $dlv['delay'];
         if ($dlv['type'] == 0) {
             $flag = 1;
         } else {
             $delivery_country = Delivery_countryService::get_instance()->get_delivery_country($id, $country_id);
             if (empty($delivery_country)) {
                 if ($dlv['is_default'] == 1) {
                     $flag = 1;
                 } else {
                     continue;
                 }
             } else {
                 $flag = 1;
                 $dlv['expression'] = $delivery_country['expression'];
             }
         }
         if ($flag = 0) {
             continue;
         }
         $delivery_price = delivery::cal_fee($dlv['expression'], $weight, $total_price);
         //计算物流费用
         $deliveries[] = array('id' => $id, 'name' => $name, 'url' => $url, 'delay' => $delay, 'delivery_price' => BLL_Currency::get_price(round($delivery_price, 2)), 'currency_sign' => $currency_sign);
     }
     return $deliveries;
 }