/**
  * Creates new delivery for current customer
  */
 function newDelivery()
 {
     $data = $this->input->post(NULL, TRUE);
     $delData = array('cid' => $data['cid'], 'schd' => $data['ischd'], 'note' => $data['note']);
     array_pop($data);
     $delivery = new delivery();
     $delivery->setDelv($delData);
     $delivery->insert();
     $this->delivery_item->insert($data);
     $deliveries = $this->delivery->getDeliveries($this->session->userdata('bname'));
     $this->load->view('editDelivery', array('deliveries' => $deliveries));
 }
Esempio n. 2
0
 /**
  * Public function that creates a single instance
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function getFieldsValues()
 {
     $id_egms_delivery = Tools::getValue('id_egms_delivery');
     if ($id_egms_delivery != false) {
         $row = delivery::getDelivery($id_egms_delivery);
     }
     return array('id_egms_delivery' => $id_egms_delivery, 'id_egms_cu' => $row[0]['id_egms_cu'], 'id_manufacturer' => $row[0]['id_manufacturer'], 'del_pay' => $row[0]['del_pay'], 'free_pay' => $row[0]['free_pay'], 'dlex' => $row[0]['dlex'], 'carriers' => $row[0]['carriers'], 'payments' => $row[0]['payments'], 'address' => $row[0]['address'], 'chema' => $row[0]['chema'], 'active' => $row[0]['active']);
 }
Esempio n. 4
0
 public function actionIndex()
 {
     $this->htmlOption = array('class' => 'icon-head head-products', 'header' => "货运设置", 'button' => array(array('class' => 'scalable save', 'id' => 'form-save', 'header' => '保存')));
     $carrier = $this->loadModel();
     if ($_POST['SHIPPING']) {
         configuration::updateItems($_POST['SHIPPING']);
     }
     if ($_POST['feeAdd']) {
         foreach ($_POST['feeAdd'] as $key => $row) {
             if ($row != 0) {
                 $arr = explode('-', $key);
                 $delivery = new delivery();
                 $delivery->carrier_ID = $_POST['carrier_ID'];
                 $delivery->zone_ID = $arr[0];
                 $delivery->weight_range_ID = $arr[1];
                 $delivery->price = $row;
                 $delivery->save();
             }
         }
     }
     if ($_POST['feeUpdate']) {
         foreach ($_POST['feeUpdate'] as $key => $row) {
             $delivery = delivery::model()->findByPk($key);
             if ($row != 0 && $row != $delivery->price) {
                 $delivery->price = $row;
                 $delivery->save();
             } else {
                 if ($row == 0) {
                     $delivery->delete();
                 }
             }
         }
     }
     $config = configuration::item('SHIPPING', 'SHIPPING_FREE_PRICE');
     $this->constructScript('index');
     $this->render('index', array('config' => $config, 'carrier' => $carrier));
 }
Esempio n. 5
0
 /**
  * Return shipping total
  *
  * @param integer $Carrier_ID Carrier ID (default : current carrier)
  * @return float Shipping total
  */
 public function getOrderShippingCost($carrier_ID = NULL)
 {
     if ($this->isFreeshipping()) {
         return 0;
     }
     // Get id zone
     if (isset($this->cart_address_ID) and $this->cart_address_ID) {
         $id_zone = address_entity::model()->findByPk($this->cart_address_ID)->getZoneId();
     } else {
         $id_zone = 1;
     }
     //if no carrier selectd,chosen default one
     if (!$carrier_ID) {
         $carrier_ID = $this->cart_carrier_ID;
     }
     if (empty($carrier_ID)) {
         return 0;
     }
     if (!($carrier = carrier_entity::model()->findByPk($carrier_ID))) {
         throw new CHttpException(500, 'No Carrier Chosen');
     }
     if ($carrier->carrier_shipping_handing != 1) {
         return 0;
     }
     if (!($weightID = weight_range::validateCarrier($this->getWeightTotal(), $carrier_ID))) {
         return 'Out';
     }
     $shippingCost = 0;
     if ($delivery = delivery::model()->findByAttributes(array('carrier_ID' => $carrier_ID, 'zone_ID' => $id_zone, 'weight_range_ID' => $weightID))) {
         $shippingCost = $delivery->price;
     }
     return $shippingCost;
 }
Esempio n. 6
0
 /**
  * 提交编辑的物流
  */
 function do_edit()
 {
     $request_data = $this->input->post();
     //流程
     $submit_target = intval($this->input->post('submit_target'));
     if ($_POST) {
         $delivery_service = DeliveryService::get_instance();
         $delivery_country_service = Delivery_countryService::get_instance();
         //数据验证
         $validation = Validation::factory($request_data)->pre_filter('trim')->add_rules('delivery_id', 'required', 'digit')->add_rules('name', 'required', 'length[0,100]')->add_rules('url', 'required', 'length[0,200]')->add_rules('first_unit', 'required', 'numeric')->add_rules('continue_unit', 'required', 'numeric')->add_rules('use_exp', 'required', 'digit')->add_rules('type', 'required', 'digit')->add_rules('position', 'required', 'numeric')->add_rules('active', 'required', 'digit');
         //验证物流表的数据
         $delivery = $delivery_service->get($request_data['delivery_id']);
         if (empty($delivery) || !isset($delivery)) {
             remind::set(Kohana::lang('o_global.bad_request'), request::referrer(), 'error');
         }
         //验证物流国家表的数据
         if (!empty($delivery['type']) && $delivery['type'] == 1) {
             $delivery_countries = $delivery_country_service->get_delivery_countries_by_id($delivery['id']);
             if (empty($delivery_countries) || !isset($delivery_countries)) {
                 remind::set(Kohana::lang('o_global.bad_request'), request::referrer(), 'error');
             }
             //验证物流国家表里面的数据是否与物流表的数据统一
             $old_country_ids = array();
             foreach ($delivery_countries as $item) {
                 if (!is_array($item) || count($item) < 0) {
                     remind::set(Kohana::lang('o_global.access_denied'), request::referrer(), 'error');
                     break;
                 }
                 foreach ($item as $k => $v) {
                     if ($v['delivery_id'] != $delivery['id']) {
                         remind::set(Kohana::lang('o_global.bad_request'), request::referrer(), 'error');
                     }
                     //保存已存在的物流国家的信息
                     $old_country_ids[$v['country_id']] = $v['id'];
                 }
             }
         }
         //检测物流名称是否存在
         if ($delivery_service->name_is_exist($request_data['name'], $request_data['delivery_id'])) {
             remind::set(Kohana::lang('o_site.carrier_has_exist'), request::referrer(), 'error');
         }
         $is_default = isset($request_data['is_default']) ? $request_data['is_default'] : 0;
         $set_data = array('name' => $request_data['name'], 'url' => $request_data['url'], 'first_unit' => $request_data['first_unit'], 'continue_unit' => $request_data['continue_unit'], 'type' => $request_data['type'], 'is_default' => $is_default, 'use_exp' => $request_data['use_exp'], 'expression' => $request_data['expression'], 'position' => $request_data['position'], 'delay' => $request_data['delay'], 'active' => $request_data['active']);
         //处理统一设置或启用默认费用
         if ($request_data['use_exp'] == 1) {
             $validation->add_rules('expression', 'required');
         } else {
             if (isset($request_data['is_default']) && $request_data['is_default'] == 1) {
                 $validation->add_rules('first_price', 'required', 'numeric');
                 $validation->add_rules('continue_price', 'required', 'numeric');
                 $set_data['first_price'] = $request_data['first_price'];
                 $set_data['continue_price'] = $request_data['continue_price'];
                 $set_data['expression'] = delivery::create_exp($request_data['first_unit'], $request_data['continue_unit'], $request_data['first_price'], $request_data['continue_price']);
             } else {
                 $set_data['expression'] = delivery::create_exp($request_data['first_unit'], $request_data['continue_unit']);
             }
         }
         if (!$validation->validate()) {
             remind::set(Kohana::lang('o_global.input_error'), request::referrer(), 'error');
         }
         //更新物流表的信息
         $delivery_service->set($delivery['id'], $set_data);
         //处理地区费用类型改变的情况
         if ($delivery['type'] == 1) {
             //处理支持的配送国家的情况
             if ($request_data['type'] == 1) {
                 if (!empty($request_data['des_indexs']) and is_array($request_data['des_indexs'])) {
                     $whole_country_ids = array();
                     foreach ($request_data['des_indexs'] as $i => $index) {
                         // 验证国家数据
                         $validation = Validation::factory($request_data)->pre_filter('trim')->add_rules('country_names_' . $index, 'required')->add_rules('countries_use_exp_' . $index, 'required', 'digit')->add_rules('country_ids_' . $index, 'required');
                         // 生成 支配的国家数据
                         $country_data = array('delivery_id' => $delivery['id'], 'first_price' => $request_data['first_price_' . $index], 'continue_price' => $request_data['continue_price_' . $index], 'use_exp' => $request_data['countries_use_exp_' . $index], 'expression' => $request_data['expression_' . $index]);
                         $country_ids = explode('-', $request_data['country_ids_' . $index]);
                         $country_names = explode(',', $request_data['country_names_' . $index]);
                         //判断提交的国家id个数是否于国家名称的个数一致
                         if (empty($country_ids)) {
                             remind::set(Kohana::lang('o_global.bad_request'), request::referrer(), 'error');
                         }
                         //使用公式
                         if ($request_data['countries_use_exp_' . $index] == 1) {
                             $validation->add_rules('expression_' . $index, 'required');
                         } else {
                             $validation->add_rules('first_price_' . $index, 'required', 'numeric');
                             $validation->add_rules('continue_price_' . $index, 'required', 'numeric');
                             $country_data['expression'] = delivery::create_exp($request_data['first_unit'], $request_data['continue_unit'], $request_data['first_price_' . $index], $request_data['continue_price_' . $index]);
                         }
                         $country_data['position'] = $index - 1;
                         $ids_index = 'ids_' . $index;
                         $de_countries[$index] = $country_data;
                         $de_countries[$index]['ids'] = array();
                         if (!empty($request_data[$ids_index])) {
                             $de_countries[$index]['ids'] = $request_data[$ids_index];
                         }
                         $countries_ids[$index] = $request_data['country_ids_' . $index];
                         $whole_country_ids = array_merge($country_ids, $whole_country_ids);
                     }
                     foreach ($countries_ids as $i => $v) {
                         $country_ids = explode('-', $v);
                         foreach ($country_ids as $value) {
                             $de_countries[$i]['country_id'] = $value;
                             if (!isset($old_country_ids[$value])) {
                                 $delivery_country_service->add($de_countries[$i]);
                             } else {
                                 $delivery_country_service->set($old_country_ids[$value], $de_countries[$i]);
                             }
                         }
                     }
                     foreach ($old_country_ids as $key => $id) {
                         if (!in_array($key, $whole_country_ids)) {
                             $delivery_country_service->remove($id);
                         }
                     }
                 }
             } else {
                 $delivery_country_service->delete_delivery_countries_by_delivery_id($delivery['id']);
             }
         } else {
             //处理支持的配送国家
             if ($request_data['type'] == 1) {
                 if (!empty($request_data['des_indexs']) and is_array($request_data['des_indexs'])) {
                     foreach ($request_data['des_indexs'] as $i => $index) {
                         // 验证国家数据
                         $validation = Validation::factory($request_data)->pre_filter('trim')->add_rules('country_names_' . $index, 'required', 'length[0,512]')->add_rules('countries_use_exp_' . $index, 'required', 'digit')->add_rules('country_ids_' . $index, 'required', 'length[0,256]');
                         // 生成 支配国家数据
                         $country_data = array('delivery_id' => $delivery['id'], 'first_price' => $request_data['first_price_' . $index], 'continue_price' => $request_data['continue_price_' . $index], 'use_exp' => $request_data['countries_use_exp_' . $index], 'expression' => $request_data['expression_' . $index]);
                         $country_ids = explode('-', $request_data['country_ids_' . $index]);
                         $country_names = explode(',', $request_data['country_names_' . $index]);
                         //判断提交的国家id个数是否于国家名称的个数一致
                         if (empty($country_ids)) {
                             remind::set(Kohana::lang('o_global.bad_request'), request::referrer(), 'error');
                         }
                         //使用公式
                         if ($request_data['countries_use_exp_' . $index] == 1) {
                             $validation->add_rules('expression_' . $index, 'required');
                         } else {
                             $validation->add_rules('first_price_' . $index, 'required', 'numeric');
                             $validation->add_rules('continue_price_' . $index, 'required', 'numeric');
                             $country_data['expression'] = delivery::create_exp($request_data['first_unit'], $request_data['continue_unit'], $request_data['first_price_' . $index], $request_data['continue_price_' . $index]);
                         }
                         $country_data['position'] = $index - 1;
                         foreach ($country_ids as $i) {
                             $country_data['country_id'] = $i;
                             if (!$delivery_country_service->add($country_data)) {
                                 remind::set(Kohana::lang('o_global.add_error'), 'site/delivery/add');
                                 break;
                             }
                         }
                     }
                 }
             }
         }
         //判断走向
         switch ($submit_target) {
             case 1:
                 remind::set(Kohana::lang('o_global.update_success'), 'site/delivery/edit/' . $delivery['id'], 'success');
             default:
                 remind::set(Kohana::lang('o_global.update_success'), 'site/delivery/', 'success');
         }
     } else {
         remind::set(Kohana::lang('o_global.update_error'), 'site/delivery');
     }
 }
Esempio n. 7
0
                 <?php 
echo "<tr>";
echo CHtml::activeDropDownList($carrier, 'carrier_ID', carrier_entity::items(), array('class' => 'required-entry required-entry input-select', 'id' => 'carrier', 'name' => 'carrier_ID'));
echo "</tr>";
echo ' <tr class="headings">
						<th style="padding:4px 6px;">区域 / 范围</th>';
foreach ($carrier->weight as $row) {
    $l1 = floatval($row->delimiter1);
    $l2 = floatval($row->delimiter2);
    echo "<th style='font-size: 11px; padding:4px 6px;'>{$l1}kg to {$l2}kg</th>";
}
echo '</tr>';
foreach ($carrier->zones as $row) {
    echo "<tr class='filter'><th style='height: 30px; padding:4px 6px;'>{$row->name}</th>";
    foreach ($carrier->weight as $item) {
        $delivery = delivery::model()->findByAttributes(array('carrier_ID' => $carrier->carrier_ID, 'zone_ID' => $row->zone_ID, 'weight_range_ID' => $item->weight_ID));
        if ($delivery) {
            $fee = $delivery->price;
            $name = "feeUpdate[{$delivery->delivery_ID}]";
        } else {
            $fee = '0.00';
            $name = "feeAdd[{$row->zone_ID}-{$item->weight_ID}]";
        }
        echo "<td class='center'>\$ <input type='text'  class='required-entry required-entry input-text' style='width: 45px; height:18px;' value='{$fee}' name='{$name}' ></td>";
    }
    echo '</tr>';
}
?>
                 
				</tbody>
                    </table>
 /**
  * Construct load data
  *
  * @param Int $site_id
  */
 public function __construct($site_id)
 {
     $this->db = Database::instance('default');
     $sql = "SELECT `carriers`.* FROM (`carriers`) WHERE `site_id` = {$site_id} ORDER BY `carriers`.`id` ASC";
     $carriers = $this->db->query($sql);
     foreach ($carriers as $keyc => $_carrier) {
         $delivery_temp = array();
         $delivery_temp['id'] = $_carrier->id;
         $delivery_temp['site_id'] = $_carrier->site_id;
         $delivery_temp['name'] = $_carrier->name;
         $delivery_temp['url'] = $_carrier->url;
         $delivery_temp['type'] = $_carrier->country_relative;
         $delivery_temp['first_unit'] = 1000000;
         $delivery_temp['continue_unit'] = 1000;
         $delivery_temp['is_default'] = 1;
         $delivery_temp['continue_price'] = 0;
         $delivery_temp['position'] = $_carrier->position;
         $delivery_temp['delay'] = $_carrier->delay;
         $delivery_temp['active'] = $_carrier->active;
         if ($_carrier->type == 0) {
             $delivery_temp['use_exp'] = 0;
             $delivery_temp['first_price'] = $_carrier->price;
             $delivery_temp['expression'] = delivery::create_exp(1000000, 1000, $_carrier->price, 0);
             $delivery_temp['delivery_country'] = array();
             $sql = "SELECT `carrier_countries`.* FROM (`carrier_countries`) WHERE `site_id` = {$site_id} AND `carrier_id` = {$_carrier->id} ORDER BY `carrier_countries`.`id` ASC";
             $countries = $this->db->query($sql);
             $j = 0;
             $price_j = array();
             foreach ($countries as $key_c => $_country) {
                 if ($_country->shipping_add != 0) {
                     if (!isset($price_j[$_country->shipping_add])) {
                         $delivery_temp['delivery_country'][$key_c]['position'] = $j;
                         $price_j[$_country->shipping_add] = $j;
                         $j++;
                     } else {
                         $delivery_temp['delivery_country'][$key_c]['position'] = $price_j[$_country->shipping_add];
                     }
                     $delivery_temp['delivery_country'][$key_c]['id'] = $_country->id;
                     $delivery_temp['delivery_country'][$key_c]['site_id'] = $_country->site_id;
                     $delivery_temp['delivery_country'][$key_c]['country_id'] = $_country->country_id;
                     $delivery_temp['delivery_country'][$key_c]['delivery_id'] = $_country->carrier_id;
                     $delivery_temp['delivery_country'][$key_c]['first_price'] = $_country->shipping_add + $delivery_temp['first_price'];
                     $delivery_temp['delivery_country'][$key_c]['continue_price'] = 0;
                     $first_price = $_country->shipping_add + $delivery_temp['first_price'];
                     $delivery_temp['delivery_country'][$key_c]['use_exp'] = 0;
                     $delivery_temp['delivery_country'][$key_c]['expression'] = delivery::create_exp(1000000, 1000, $first_price, 0);
                 }
             }
             if ($j == 0) {
                 $delivery_temp['type'] = 0;
             }
         } else {
             $delivery_temp['use_exp'] = 1;
             $delivery_temp['first_price'] = 0;
             $sql_range = "SELECT `carrier_ranges`.* FROM (`carrier_ranges`) WHERE `site_id` = {$site_id} AND `carrier_id` = {$_carrier->id} ORDER BY `carrier_ranges`.`id` ASC";
             $ranges = $this->db->query($sql_range)->as_array();
             $str = '';
             foreach ($ranges as $key_c => $_range) {
                 if ($_range == end($ranges)) {
                     if ($_range->parameter_from == 0) {
                         $str .= "{{" . $_range->parameter_to . "-p}-0.6}*" . $_range->shipping;
                     } else {
                         $str .= "{{p-" . $_range->parameter_from . "}-0.1}*{{" . $_range->parameter_to . "-p}-0.6}*" . $_range->shipping;
                     }
                 } else {
                     if ($_range->parameter_from == 0) {
                         $str .= "{{" . $_range->parameter_to . "-p}-0.6}*" . $_range->shipping . '+';
                     } else {
                         $str .= "{{p-" . $_range->parameter_from . "}-0.1}*{{" . $_range->parameter_to . "-p}-0.6}*" . $_range->shipping . '+';
                     }
                 }
             }
             $delivery_temp['expression'] = $str;
             $delivery_temp['delivery_country'] = array();
             $sql = "SELECT `carrier_countries`.* FROM (`carrier_countries`) WHERE `site_id` = {$site_id} AND `carrier_id` = {$_carrier->id} ORDER BY `carrier_countries`.`id` ASC";
             $countries = $this->db->query($sql);
             $i = 0;
             $price = array();
             foreach ($countries as $key_c => $_country) {
                 if ($_country->shipping_add != 0) {
                     if (!isset($price[$_country->shipping_add])) {
                         $delivery_temp['delivery_country'][$key_c]['position'] = $i;
                         $price[$_country->shipping_add] = $i;
                         $i++;
                     } else {
                         $delivery_temp['delivery_country'][$key_c]['position'] = $price[$_country->shipping_add];
                     }
                     $str_country = '';
                     $delivery_temp['delivery_country'][$key_c]['id'] = $_country->id;
                     $delivery_temp['delivery_country'][$key_c]['site_id'] = $_country->site_id;
                     $delivery_temp['delivery_country'][$key_c]['country_id'] = $_country->country_id;
                     $delivery_temp['delivery_country'][$key_c]['delivery_id'] = $_country->carrier_id;
                     $delivery_temp['delivery_country'][$key_c]['first_price'] = 0;
                     $delivery_temp['delivery_country'][$key_c]['continue_price'] = 0;
                     $delivery_temp['delivery_country'][$key_c]['use_exp'] = 1;
                     foreach ($ranges as $k_c => $_r) {
                         if ($_r == end($ranges)) {
                             if ($_r->parameter_from == 0) {
                                 $str_country .= "{{" . $_r->parameter_to . "-p}-0.6}*" . ($_r->shipping + $_country->shipping_add);
                             } else {
                                 $str_country .= "{{p-" . $_r->parameter_from . "}-0.1}*{{" . $_r->parameter_to . "-p}-0.6}*" . ($_r->shipping + $_country->shipping_add);
                             }
                         } else {
                             if ($_r->parameter_from == 0) {
                                 $str_country .= "{{" . $_r->parameter_to . "-p}-0.6}*" . ($_r->shipping + $_country->shipping_add) . '+';
                             } else {
                                 $str_country .= "{{p-" . $_r->parameter_from . "}-0.1}*{{" . $_r->parameter_to . "-p}-0.6}*" . ($_r->shipping + $_country->shipping_add) . '+';
                             }
                         }
                     }
                     $delivery_temp['delivery_country'][$key_c]['expression'] = $str_country;
                 }
             }
             if ($i == 0) {
                 $delivery_temp['type'] = 0;
             }
         }
         $this->data[$keyc] = $delivery_temp;
     }
     $this->end = count($this->data);
 }
Esempio n. 9
0
 /**
  * 得到并计算物流费用
  *
  * @param 	string $expresion    公式
  * @param 	float  $total        订单价格
  * @param 	int    $weight       订单重量
  * @return 	Float  $price
  */
 private function do_carrier_price($expression, $total, $weight = 0)
 {
     if (!$expression) {
         return 0;
     }
     $price = delivery::cal_fee($expression, $weight, $total);
     return $price;
 }
Esempio n. 10
0
 /**
  * 计算物流价格
  * 
  * @param array $condition
  * @return float $price
  * 
  * $condition = array(
  *   'delivery_id'          => '77',        //物流ID
  *   'country_id'           => '539',       //物流递送国家
  *   'weight'               => '500',       //订单重量
  *   'total_price'          => '300.99',    //订单总价
  * );
  * 如果返回值是-1表示当前物流不支持到收货地址的配送
  */
 public static function get_delivery_price_by_condition($condition)
 {
     $delivery_id = $condition['delivery_id'];
     $country_id = $condition['country_id'];
     $weight = $condition['weight'];
     $total_price = $condition['total_price'];
     $dlv_instance = DeliveryService::get_instance();
     $delivery = $dlv_instance->get_delivery_by_id($delivery_id);
     if (empty($delivery)) {
         return 0;
     }
     $flag = 0;
     if ($delivery['type'] == 0) {
         $flag = 1;
     } else {
         $delivery_country = Delivery_countryService::get_instance()->get_delivery_country($delivery_id, $country_id);
         if (empty($delivery_country)) {
             if ($delivery['is_default'] == 1) {
                 $flag = 1;
             } else {
                 return 0;
             }
         } else {
             $flag = 1;
             $delivery['expression'] = $delivery_country['expression'];
         }
     }
     if ($flag = 0) {
         return 0;
     }
     $price = delivery::cal_fee($delivery['expression'], $weight, $total_price);
     //计算物流费用
     return $price;
 }
Esempio n. 11
0
 public function chooseDelivery(order $order)
 {
     $urlPrefix = cmsController::getInstance()->getUrlPrefix() ? cmsController::getInstance()->getUrlPrefix() . '/' : '';
     $deliveryId = getRequest('delivery-id');
     if (!$deliveryId) {
         $this->redirect($this->pre_lang . '/' . $urlPrefix . 'emarket/purchase/delivery/choose/');
     }
     if (@isset($_SESSION['emarket']['delivery'][$deliveryId])) {
         $deliveryPrice = (double) $_SESSION['emarket']['delivery'][$deliveryId];
     } else {
         $delivery = delivery::get($deliveryId);
         $deliveryPrice = (double) $delivery->getDeliveryPrice($order);
     }
     $order->setValue('delivery_id', $deliveryId);
     $order->setValue('delivery_price', $deliveryPrice);
     $order->refresh();
     $order->commit();
     $this->redirect($this->pre_lang . '/' . $urlPrefix . 'emarket/purchase/payment/bonus/');
 }