Пример #1
0
 public static function send($order_id)
 {
     $order = Myorder::instance($order_id)->get();
     $order['order_product_detail'] = Myorder_product::instance()->order_product_details(array('order_id' => $order['id']));
     $order['skulist'] = '';
     $order['qlist'] = '';
     $order['amtlist'] = '';
     $order['source'] = '1';
     $skulist = array();
     $qlist = array();
     $amtlist = array();
     foreach ($order['order_product_detail'] as $key => $order_product_detail) {
         $skulist[] = $order_product_detail['SKU'];
         $qlist[] = $order_product_detail['quantity'];
         $amtlist[] = $order_product_detail['discount_price'];
     }
     $order['skulist'] = implode("|", $skulist);
     $order['qlist'] = implode("|", $qlist);
     $order['amtlist'] = implode("|", $amtlist);
     $post_url = "http://af.statcount.org/order/";
     $post_var = "order=" . $order['order_num'] . "&amount=" . $order['total_real'] . "&skulist=" . $order['skulist'] . "&qlist=" . $order['qlist'] . "&amtlist=" . $order['amtlist'] . "&cur=" . $order['currency'] . "&source=" . $order['source'];
     $result = tool::curl_pay($post_url, $post_var);
     if (stristr($result == 'SUCCESS')) {
         return true;
     } else {
         return false;
     }
 }
Пример #2
0
 /**
  * site statistics
  */
 public function index()
 {
     $site_detail = Mysite::instance()->detail();
     $statking_id = $site_detail['statking_id'];
     /* 初始化默认查询条件 */
     $query_struct = array('where' => array(), 'like' => array(), 'orderby' => array(), 'limit' => array());
     $data = array();
     $data['count_ip'] = 0;
     $data['sum_order'] = Myorder::instance()->sum();
     $data['count_order_user'] = Myorder::instance()->count_order_user();
     $data['count_order'] = Myorder::instance()->query_count($query_struct);
     $data['count_user'] = Myuser::instance()->query_count($query_struct);
     $average_data = statistics::get_average_data($data);
     $this->template->content = new View("site/statistics");
     $this->template->content->average_data = $average_data;
 }
Пример #3
0
 function desktop()
 {
     //权限验证
     role::check('default');
     //各个时间段的订单数量
     $stat_date = Myorder::instance()->stat_by_date();
     //已支付订单数量
     // 初始化默认查询条件
     $order_query_struct = array('where' => array('active' => 1), 'like' => array(), 'orderby' => array('order' => 'ASC'), 'limit' => array('per_page' => 20, 'offset' => 0));
     /* 已支付未做处理的订单 */
     $order_query_struct['where']['pay_status'] = 3;
     $order_query_struct['where']['order_status'] = 1;
     $order_query_struct['where']['ship_status'] = 1;
     $count_pay = Myorder::instance()->query_count($order_query_struct);
     //有订单用户数量
     $count_order_user = Myorder::instance()->count_order_user();
     /* 初始化默认查询条件 */
     $user_query_struct = array('where' => array(), 'like' => array(), 'orderby' => array(), 'limit' => array());
     //用户总数
     $count_user = Myuser::instance()->query_count();
     //今日用户
     $today = date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), date('d'), date('Y')));
     $user_query_struct['where']['date_add >='] = $today;
     $count_today_user = Myuser::instance()->query_count($user_query_struct);
     //有留言的订单数量
     $count_order_message = Myorder_message::instance()->count_order();
     //新的网站留言
     $count_contact_us = Mycontact_us::instance()->count(array('active' => '1'));
     /* 平台公告列表 */
     $notice_query_struct = array('where' => array(), 'like' => array(), 'orderby' => array('id' => 'DESC'), 'limit' => array('per_page' => 3, 'offset' => 0));
     $notices = Mynotice::instance()->query_assoc($notice_query_struct);
     $this->template->content = new View("index_desktop");
     $this->template->content->count_pay = $count_pay;
     $this->template->content->count_order_message = $count_order_message;
     $this->template->content->count_contact_us = $count_contact_us;
     $this->template->content->count_order_user = $count_order_user;
     $this->template->content->count_user = $count_user;
     $this->template->content->count_today_user = $count_today_user;
     $this->template->content->notices = $notices;
     $this->template->content->stat_date = $stat_date;
 }
Пример #4
0
 /**
  * 删除
  */
 public function do_delete($id)
 {
     $total_products = 0;
     $total = 0;
     if (!$id) {
         remind::set(Kohana::lang('o_global.bad_request'), request::referrer(), 'error');
     }
     //验证
     $order_product_service = Order_productService::get_instance();
     $data = $order_product_service->get($id);
     if (!$data['id']) {
         remind::set(Kohana::lang('o_global.bad_request'), request::referrer(), 'error');
     }
     if ($order_product_service->remove($data['id'])) {
         if (Myorder::instance($data['order_id'])->update_total()) {
             remind::set(Kohana::lang('o_global.delete_success'), 'order/order/edit/id/' . $data['order_id'], 'success');
         } else {
             remind::set(Kohana::lang('o_global.delete_error'), 'order/order/edit/id/' . $data['order_id'], 'error');
         }
     } else {
         remind::set(Kohana::lang('o_global.delete_error'), 'order/order/edit/id/' . $data['order_id'], 'error');
     }
 }
Пример #5
0
 /**
  * 退款邮件
  * @param string $refund_struct 订单号
  */
 public static function refund($refund_struct = array())
 {
     $order_num = !empty($refund_struct['order_num']) ? $refund_struct['order_num'] : '';
     if (!empty($order_num)) {
         $order = Myorder::instance()->get_by_order_num($order_num);
         /* 退款金额  */
         $refund_amount = !empty($refund_struct['refund_amount']) ? $refund_struct['refund_amount'] : $order['total'];
         if (is_array($order) && $order['id'] > 0) {
             $site_id = Mysite::instance()->id();
             $mail_type = 'refund';
             $to_email = $order['email'];
             $from_email = '';
             $param = array('{firstname}' => $order['shipping_firstname'], '{lastname}' => $order['shipping_lastname'], '{order_num}' => $order['order_num'], '{amount}' => $refund_amount, '{currency}' => $order['currency']);
             $title_param = $param;
             $content_param = $param;
             self::send_mail(1, $mail_type, $to_email, $from_email, $title_param, $content_param);
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Пример #6
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');
         }
     }
 }
Пример #7
0
 /**
  *  订单导出
  */
 public function do_export($id = 0)
 {
     // 初始化返回数据
     $return_data = array();
     //请求结构体
     $request_data = array();
     try {
         //权限验证
         role::check('order_export');
         if ($id < 1) {
             throw new MyRuntimeException(Kohana::lang('o_global.data_load_error'), 403);
         }
         if (!$id) {
             throw new MyRuntimeException(Kohana::lang('o_global.data_load_error'), 403);
         }
         if ($_POST) {
             /* 验证是否选择了订单 */
             if (!isset($_POST['order_ids'])) {
                 throw new MyRuntimeException(Kohana::lang('o_order.select_order_export'), 403);
             }
             $order_ids = $this->input->post('order_ids');
             //array(1,2);
             /* 得到当前的导出配置 */
             $data = Myorder_export::instance($id)->get();
             $output_field_ids = unserialize($data['export_ids']);
             /* 导出格式错误 */
             if (!is_array($output_field_ids) || count($output_field_ids) < 1) {
                 throw new MyRuntimeException(Kohana::lang('o_order.order_export_config_error'), 403);
             }
             $xls = export::instance();
             //$xls->debug(true);//开测试模式
             $xls->set_output_field_ids($output_field_ids);
             /* 订单状态,支付状态,物流状态 */
             $order_status = Kohana::config('order.order_status');
             $pay_status = Kohana::config('order.pay_status');
             $ship_status = Kohana::config('order.ship_status');
             $result = array();
             foreach ($order_ids as $order_id) {
                 $order = Myorder::instance($order_id)->get();
                 $shipping_country_name = Mycountry::instance()->get_name_by_iso_code($order['shipping_country']);
                 $billing_country_name = Mycountry::instance()->get_name_by_iso_code($order['billing_country']);
                 $order_products = Myorder_product::instance()->order_product_details(array('order_id' => $order['id']));
                 $order['shipping_country_name'] = $shipping_country_name;
                 $order['billing_country_name'] = $billing_country_name;
                 $order['pay_status_name'] = $pay_status[$order['pay_status']]['name'];
                 $order['ship_status_name'] = $ship_status[$order['ship_status']]['name'];
                 $order['order_status_name'] = $order_status[$order['order_status']]['name'];
                 $order['ip'] = long2ip($order['ip']);
                 if (is_array($order_products) && count($order_products) > 0) {
                     foreach ($order_products as $key => $value) {
                         $order_products[$key]['total'] = round($value['discount_price'] * $value['quantity'] * $order['conversion_rate'], 2);
                     }
                 }
                 $order['product'] = $order_products;
                 $xls->set_order_line($order);
             }
             $xls->output();
             exit;
         }
     } catch (MyRuntimeException $ex) {
         $return_struct['status'] = 0;
         $return_struct['code'] = $ex->getCode();
         $return_struct['msg'] = $ex->getMessage();
         var_dump($return_struct);
         exit;
         //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;
         }
     }
 }
Пример #8
0
 /**
  *  显示退货单细节
  */
 public function return_detail($id)
 {
     /* 权限检查*/
     role::check('order_doc_return');
     $return = Myorder_return_log::instance($id)->get();
     $ship_status = Kohana::config('order.ship_status');
     $return_list = array();
     $return_list['id'] = $return['id'];
     //退货单id
     $return_list['return_num'] = $return['return_num'];
     //退货单号
     $return_list['order_num'] = Myorder::instance($return['order_id'])->get('order_num');
     //订单号
     $return_list['carrier'] = DeliveryService::get_instance()->get_delivery_name($return['carrier_id']);
     $return_list['email'] = $return['email'];
     //用户邮箱
     $return_list['manager'] = Mymanager::instance($return['manager_id'])->get('username');
     //操作员
     $return_list['currency'] = $return['currency'];
     //币种
     $return_list['total_shipping'] = $return['total_shipping'];
     //运费金额
     $return_list['return_status'] = $ship_status[$return['return_status_id']]['name'];
     //退货状态
     $return_list['content_admin'] = $return['content_admin'];
     //管理员备注
     $return_list['content_user'] = $return['content_user'];
     //用户备注
     $return_list['date_add'] = $return['date_add'];
     //添加时间
     /* 得到订单货品信息 */
     $return_list['return_data'] = array();
     $return_data = unserialize($return['return_data']);
     $order_products = Myorder_product::instance()->get_order_products_by_order_id($return['order_id']);
     foreach ($order_products as $val) {
         foreach ($return_data as $k => $v) {
             if ($v['id'] == $val['id']) {
                 $return_list['return_data'][$k]['SKU'] = $val['SKU'];
                 $return_list['return_data'][$k]['name'] = $val['name'];
                 $return_list['return_data'][$k]['attribute_style'] = empty($val['attribute_style']) ? '默认' : $val['attribute_style'];
                 $return_list['return_data'][$k]['quantity'] = $val['quantity'];
                 $return_list['return_data'][$k]['sendnum'] = isset($v['send_num']) ? $v['send_num'] : '未知';
                 $return_list['return_data'][$k]['returnnum'] = $v['return_num'];
             }
         }
     }
     $this->template = new View('layout/commonfix_html');
     $this->template->content = new view("order/order_doc/doc_detail/return_detail");
     $this->template->content->return_list = $return_list;
 }