예제 #1
0
 public static function corn_quote($from = 'quote_xe', &$message = '')
 {
     $currencies = Mycurrency::instance()->currencies();
     foreach ($currencies as $key => $rs) {
         if (strlen($rs['code']) == 3) {
             $currency_data = array();
             $rate = currency::quote_xe($rs['code']);
             $currency_data['conversion_rate'] = round(1 / $rate, 5);
             $currency = Mycurrency::instance($rs['id'])->edit($currency_data);
             $message = '';
             if ($currency) {
                 $message .= $rs['code'] . ' 汇率更新成功<br>';
             }
         }
     }
     return true;
 }
예제 #2
0
 /**
  * 添加订单
  */
 function do_add()
 {
     /*权限检查*/
     role::check('order_add');
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim');
         $post->add_rules('shipping_firstname', 'required', 'length[1,200]');
         $post->add_rules('shipping_lastname', 'required', 'length[1,200]');
         $post->add_rules('shipping_country', 'required', 'length[1,200]');
         $post->add_rules('shipping_state', 'length[1,200]');
         $post->add_rules('shipping_city', 'required', 'length[1,200]');
         $post->add_rules('shipping_address', 'required', 'length[1,200]');
         $post->add_rules('shipping_zip', 'required', 'length[1,200]');
         $post->add_rules('shipping_phone', 'required', 'length[1,200]');
         $post->add_rules('shipping_mobile', 'length[1,200]');
         $post->add_rules('billing_firstname', 'length[1,200]');
         $post->add_rules('billing_lastname', 'length[1,200]');
         $post->add_rules('billing_country', 'length[1,200]');
         $post->add_rules('billing_state', 'length[1,200]');
         $post->add_rules('billing_city', 'length[1,200]');
         $post->add_rules('billing_address', 'length[1,200]');
         $post->add_rules('billing_zip', 'length[1,200]');
         $post->add_rules('billing_phone', 'length[1,200]');
         $post->add_rules('billing_mobile', 'length[1,200]');
         $post->add_rules('good_price', 'required', 'length[1,200]');
         $post->add_rules('shipping_price', 'required', 'length[1,200]');
         if (!$post->validate()) {
             $errors = $post->errors();
             log::write('form_error', $errors, __FILE__, __LINE__);
             remind::set(Kohana::lang('o_order.user_address_wrong'), 'order/order_add/add_again', 'error');
         }
         /* 添加主订单详情*/
         $order_data = array();
         $user_id = $this->input->post('user_id');
         $email = $this->input->post('email');
         $carrier = $this->input->post('carrier');
         $currency_code = $this->input->post('code');
         if ($user_id && $email && $currency_code) {
             /* 订单用户信息*/
             $order_data['user_id'] = $user_id;
             $order_data['email'] = $email;
             /* 订单币种信息*/
             $currency = Mycurrency::instance()->get_by_code($currency_code);
             $order_data['currency'] = $currency_code;
             $order_data['conversion_rate'] = $currency['conversion_rate'];
             /* 订单国家*/
             $order_data['shipping_country'] = Mycountry::instance($post->shipping_country)->get('iso_code');
             $order_data['billing_country'] = Mycountry::instance($post->billing_country)->get('iso_code');
             /* 订单时间和IP信息*/
             $order_data['data_add'] = date('Y-m-d H:i:s', time());
             $order_data['IP'] = tool::get_long_ip();
             /* 订单号生成*/
             $order_num = '';
             do {
                 $temp = sprintf("%14.0f", date('ymd') . "00000" + rand(0, 99999) . "0000");
                 $exist_data = array();
                 $exist_data['order_num'] = $temp;
                 if (!Myorder::instance()->exist($exist_data)) {
                     $order_num = $temp;
                     break;
                 }
             } while (1);
             $order_data['order_num'] = $order_num;
             $order_data['order_status'] = '1';
             $order_data['pay_status'] = '1';
             $order_data['ship_status'] = '1';
             $order_data['user_status'] = 'NULL';
             $order_data['order_source'] = 'manual';
             $order_data['total'] = $post->good_price + $post->shipping_price;
             $order_data['total_products'] = $post->good_price;
             $order_data['total_shipping'] = $post->shipping_price;
             $order_data['total_real'] = $order_data['total'] / $order_data['conversion_rate'];
             $order_data['total_discount'] = '0.00';
             $order_data['total_paid'] = '0.00';
             $order_data['shipping_firstname'] = $post->shipping_firstname;
             $order_data['shipping_lastname'] = $post->shipping_lastname;
             $order_data['shipping_state'] = $post->shipping_state;
             $order_data['shipping_city'] = $post->shipping_city;
             $order_data['shipping_address'] = $post->shipping_address;
             $order_data['shipping_zip'] = $post->shipping_zip;
             $order_data['shipping_phone'] = $post->shipping_phone;
             $order_data['shipping_mobile'] = $post->shipping_mobile;
             $order_data['billing_firstname'] = $post->billing_firstname;
             $order_data['billing_lastname'] = $post->billing_lastname;
             $order_data['billing_state'] = $post->billing_state;
             $order_data['billing_city'] = $post->billing_city;
             $order_data['billing_address'] = $post->billing_address;
             $order_data['billing_zip'] = $post->billing_zip;
             $order_data['billing_phone'] = $post->billing_phone;
             $order_data['billing_mobile'] = $post->billing_mobile;
             $order_data['carrier'] = $carrier;
             $order_data['active'] = 1;
         } else {
             remind::set(Kohana::lang('o_order.data_trans_wrong'), 'order/order_add', 'error');
         }
         /* 添加订单,返回订单数据*/
         $order_id = Myorder::instance()->add($order_data);
         $order = Myorder::instance($order_id)->get();
         /* 添加订单产品信息*/
         $session = Session::instance();
         $cart_data = $session->get('cart_data');
         if (isset($cart_data) && is_array($cart_data) && count($cart_data) && !empty($order['order_num'])) {
             foreach ($cart_data as $key => $rs) {
                 $good_full_data = ProductService::get_instance()->get($key);
                 $order_product_detail_data = array();
                 $order_product_detail_data['order_id'] = $order['id'];
                 $order_product_detail_data['product_type'] = ProductService::PRODUCT_TYPE_GOODS;
                 $order_product_detail_data['dly_status'] = 'storage';
                 //$order_product_detail_data['product_id']            = $good_full_data['product_id'];
                 $order_product_detail_data['good_id'] = $key;
                 $order_product_detail_data['quantity'] = $rs;
                 $order_product_detail_data['sendnum'] = '0';
                 $order_product_detail_data['price'] = $good_full_data['price'];
                 $order_product_detail_data['discount_price'] = $good_full_data['price'];
                 $order_product_detail_data['weight'] = $good_full_data['weight'];
                 //$order_product_detail_data['name']                = $good_full_data['name_manage'];
                 $order_product_detail_data['name'] = $good_full_data['title'];
                 $order_product_detail_data['SKU'] = $good_full_data['sku'];
                 $order_product_detail_data['brief'] = $good_full_data['brief'];
                 $order_product_detail_data['date_add'] = date('Y-m-d H:i:s', time());
                 $order_product_detail_data['link'] = product::permalink($good_full_data);
                 order::do_order_product_detail_data_by_good(&$order_product_detail_data, $good_full_data, $good_full_data['default_image_id']);
                 $order_product_detail = Myorder_product::instance()->add($order_product_detail_data);
             }
         }
         /*验证是否添加成功,添加成功返回订单号*/
         if (!empty($order['order_num']) && $order_product_detail) {
             remind::set(Kohana::lang('o_order.add_order_success') . $order['order_num'], 'order/order', 'success');
         } else {
             remind::set(Kohana::lang('o_order.add_order_wrong'), 'order/order_add', 'error');
         }
     }
 }
예제 #3
0
 /**
  * 批量删除币种
  */
 public function batch_delete()
 {
     //初始化返回数据
     $return_data = array();
     //请求结构体
     $request_data = array();
     try {
         $currency_ids = $this->input->post('currency_ids');
         if (is_array($currency_ids) && count($currency_ids) > 0) {
             /* 初始化默认查询条件 */
             $query_struct = array('where' => array('id' => $currency_ids), 'like' => array(), 'limit' => array());
             $currencies = Mycurrency::instance()->query_assoc($query_struct);
             /* 删除失败的用户 */
             $failed_currency_names = '';
             /* 执行操作 */
             foreach ($currencies as $key => $currency) {
                 if ($currency['default'] == 1) {
                     remind::set(Kohana::lang('o_site.default_current_cannot_delete'), request::referrer(), 'error');
                 }
                 if (!Mycurrency::instance($currency['id'])->delete()) {
                     $failed_currency_names = ' | ' . $currency['name'];
                 }
             }
             if (empty($failed_currency_names)) {
                 throw new MyRuntimeException(Kohana::lang('o_site.delete_currency_success'), 200);
             } else {
                 /* 中转提示页面的停留时间 */
                 $return_struct['action']['time'] = 10;
                 $failed_carrier_names = trim($failed_currency_names, '|');
                 throw new MyRuntimeException(Kohana::lang('o_site.delete_currency_error', $failed_currency_names), 200);
             }
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
         }
     } catch (MyRuntimeException $ex) {
         $return_struct['status'] = 0;
         $return_struct['code'] = $ex->getCode();
         $return_struct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         if ($this->is_ajax_request()) {
             $this->template = new View('layout/empty_html');
             $this->template->content = $return_struct['msg'];
         } else {
             $this->template->return_struct = $return_struct;
             $content = new View('info');
             $this->template->content = $content;
             /* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             /* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
         }
     }
 }