コード例 #1
0
ファイル: CsvGenerator.php プロジェクト: linniux/atsd-api-php
function getCsv($entity, $metric, $endDate, $period)
{
    $csv = new Csv();
    $options = array();
    if ($period != '1-DAY') {
        $options['a'] = array("SUM");
    }
    if ($period == '1-WEEK') {
        $options['ai'] = '1-HOUR';
    } else {
        if ($period == '1-MONTH') {
            $options['ai'] = '1-DAY';
        }
    }
    $response = $csv->export($entity, $metric, $endDate, $period, $options);
    return $response;
}
コード例 #2
0
ファイル: bill.php プロジェクト: noikiy/nc-1
 /**
  * 导出结算退单明细CSV
  *
  */
 public function export_refund_orderOp()
 {
     if (!preg_match('/^20\\d{5,12}$/', $_GET['ob_no'])) {
         showMessage('参数错误', '', 'html', 'error');
     }
     $model_bill = Model('bill');
     $bill_info = $model_bill->getOrderBillInfo(array('ob_no' => $_GET['ob_no']));
     if (!$bill_info) {
         showMessage('参数错误', '', 'html', 'error');
     }
     $model_refund = Model('refund_return');
     $condition = array();
     $condition['seller_state'] = 2;
     $condition['store_id'] = $bill_info['ob_store_id'];
     $condition['goods_id'] = array('gt', 0);
     $if_start_date = preg_match('/^20\\d{2}-\\d{2}-\\d{2}$/', $_GET['query_start_date']);
     $if_end_date = preg_match('/^20\\d{2}-\\d{2}-\\d{2}$/', $_GET['query_end_date']);
     $start_unixtime = $if_end_date ? strtotime($_GET['query_start_date']) : null;
     $end_unixtime = $if_end_date ? strtotime($_GET['query_end_date']) : null;
     if ($if_end_date || $if_end_date) {
         $condition['admin_time'] = array('time', array($start_unixtime, $end_unixtime));
     } else {
         $condition['admin_time'] = array('time', array($bill_info['ob_start_date'], $bill_info['ob_end_date']));
     }
     if (!is_numeric($_GET['curpage'])) {
         $count = $model_refund->getRefundReturn($condition);
         $array = array();
         if ($count > self::EXPORT_SIZE) {
             //显示下载链接
             $page = ceil($count / self::EXPORT_SIZE);
             for ($i = 1; $i <= $page; $i++) {
                 $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
                 $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
                 $array[$i] = $limit1 . ' ~ ' . $limit2;
             }
             Tpl::output('list', $array);
             Tpl::output('murl', 'index.php?act=bill&op=show_bill&query_type=refund&ob_no=' . $_GET['ob_no']);
             Tpl::showpage('export.excel');
             exit;
         } else {
             //如果数量小,直接下载
             $data = $model_refund->getRefundReturnList($condition, '', '*,refund_amount*commis_rate/100 as commis_amount', self::EXPORT_SIZE);
         }
     } else {
         //下载
         $limit1 = ($_GET['curpage'] - 1) * self::EXPORT_SIZE;
         $limit2 = self::EXPORT_SIZE;
         $data = $model_refund->getRefundReturnList(condition, '', '*,refund_amount*commis_rate/100 as commis_amount', "{$limit1},{$limit2}");
     }
     if (is_array($data) && count($data) == 1 && $data[0]['refund_id'] == '') {
         $refund_list = array();
     }
     $export_data = array();
     $export_data[0] = array('退单编号', '订单编号', '退单金额', '退单佣金', '类型', '退款日期', '商家', '商家编号', '买家', '买家编号');
     $refund_amount = 0;
     $commis_totals = 0;
     $k = 0;
     foreach ($data as $v) {
         $export_data[$k + 1][] = 'NC' . $v['refund_sn'];
         $export_data[$k + 1][] = 'NC' . $v['order_sn'];
         $refund_amount += $export_data[$k + 1][] = $v['refund_amount'];
         $commis_totals += $export_data[$k + 1][] = ncPriceFormat($v['commis_amount']);
         $export_data[$k + 1][] = str_replace(array(1, 2), array('退款', '退货'), $v['refund_type']);
         $export_data[$k + 1][] = date('Y-m-d', $v['admin_time']);
         $export_data[$k + 1][] = $v['store_name'];
         $export_data[$k + 1][] = $v['store_id'];
         $export_data[$k + 1][] = $v['buyer_name'];
         $export_data[$k + 1][] = $v['buyer_id'];
         $k++;
     }
     $count = count($export_data);
     $export_data[$count][] = '';
     $export_data[$count][] = '合计';
     $export_data[$count][] = $refund_amount;
     $export_data[$count][] = $commis_totals;
     $csv = new Csv();
     $export_data = $csv->charset($export_data, CHARSET, 'gbk');
     $csv->filename = $csv->charset('退单明细-', CHARSET) . $_GET['ob_no'];
     $csv->export($export_data);
 }
コード例 #3
0
ファイル: store_vr_bill.php プロジェクト: Maplecms/shopnc-api
 /**
  * 导出结算订单明细CSV
  *
  */
 public function export_orderOp()
 {
     if (!preg_match('/^20\\d{5,12}$/', $_GET['ob_no'])) {
         showMessage('参数错误', '', 'html', 'error');
     }
     if (substr($_GET['ob_no'], 6) != $_SESSION['store_id']) {
         showMessage('参数错误', '', 'html', 'error');
     }
     $model_bill = Model('vr_bill');
     $bill_info = $model_bill->getOrderBillInfo(array('ob_no' => $_GET['ob_no']));
     if (!$bill_info) {
         showMessage('参数错误', '', 'html', 'error');
     }
     $model_order = Model('vr_order');
     $condition = array();
     $condition['store_id'] = $_SESSION['store_id'];
     if (preg_match('/^\\d{8,20}$/', $_GET['query_order_no'])) {
         //取order_id
         $order_info = $model_order->getOrderInfo(array('order_sn' => $_GET['query_order_no']), 'order_id');
         $condition['order_id'] = $order_info['order_id'];
     }
     $if_start_date = preg_match('/^20\\d{2}-\\d{2}-\\d{2}$/', $_GET['query_start_date']);
     $if_end_date = preg_match('/^20\\d{2}-\\d{2}-\\d{2}$/', $_GET['query_end_date']);
     $start_unixtime = $if_start_date ? strtotime($_GET['query_start_date']) : null;
     $end_unixtime = $if_end_date ? strtotime($_GET['query_end_date']) : null;
     if ($if_start_date || $if_end_date) {
         $condition_time = array('time', array($start_unixtime, $end_unixtime));
     } else {
         $condition_time = array('between', "{$bill_info['ob_start_date']},{$bill_info['ob_end_date']}");
     }
     if ($_GET['type'] == 'timeout') {
         //计算未使用已过期不可退兑换码列表
         $condition['vr_state'] = 0;
         $condition['vr_invalid_refund'] = 0;
         $condition['vr_indate'] = $condition_time;
     } else {
         //计算已使用兑换码列表
         $condition['vr_state'] = 1;
         $condition['vr_usetime'] = $condition_time;
     }
     if (!is_numeric($_GET['curpage'])) {
         $count = $model_order->getOrderCodeCount($condition);
         $array = array();
         if ($count > self::EXPORT_SIZE) {
             //显示下载链接
             $page = ceil($count / self::EXPORT_SIZE);
             for ($i = 1; $i <= $page; $i++) {
                 $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
                 $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
                 $array[$i] = $limit1 . ' ~ ' . $limit2;
             }
             Tpl::output('list', $array);
             Tpl::output('murl', 'index.php?act=store_vr_bill&op=show_bill&ob_no=' . $_GET['ob_no']);
             Tpl::showpage('store_export.excel');
             exit;
         } else {
             //如果数量小,直接下载
             $data = $model_order->getCodeList($condition, '*', '', 'rec_id desc', self::EXPORT_SIZE);
         }
     } else {
         //下载
         $limit1 = ($_GET['curpage'] - 1) * self::EXPORT_SIZE;
         $limit2 = self::EXPORT_SIZE;
         $data = $model_order->getCodeList($condition, '*', '', 'rec_id desc', "{$limit1},{$limit2}");
     }
     //然后取订单编号
     $order_id_array = array();
     if (is_array($data)) {
         foreach ($data as $code_info) {
             $order_id_array[] = $code_info['order_id'];
         }
     }
     $condition = array();
     $condition['order_id'] = array('in', $order_id_array);
     $order_list = $model_order->getOrderList($condition);
     $order_new_list = array();
     if (!empty($order_list)) {
         foreach ($order_list as $v) {
             $order_new_list[$v['order_id']]['order_sn'] = $v['order_sn'];
             $order_new_list[$v['order_id']]['buyer_name'] = $v['buyer_name'];
             $order_new_list[$v['order_id']]['buyer_id'] = $v['buyer_id'];
             $order_new_list[$v['order_id']]['store_name'] = $v['store_name'];
             $order_new_list[$v['order_id']]['store_id'] = $v['store_id'];
             $order_new_list[$v['order_id']]['goods_name'] = $v['goods_name'];
         }
     }
     $export_data = array();
     $export_data[0] = array('兑换码', '消费时间', '订单号', '消费金额', '佣金金额', '买家', '买家编号', '商品');
     if ($_GET['type'] == 'timeout') {
         $export_data[0][1] = '过期时间';
     }
     $pay_totals = 0;
     $commis_totals = 0;
     $k = 0;
     foreach ($data as $v) {
         //该订单算佣金
         $export_data[$k + 1][] = $v['vr_code'];
         if ($_GET['type'] == 'timeout') {
             $export_data[$k + 1][] = date('Y-m-d H:i:s', $v['vr_indate']);
         } else {
             $export_data[$k + 1][] = date('Y-m-d H:i:s', $v['vr_usetime']);
         }
         $export_data[$k + 1][] = 'NC' . $order_new_list[$v['order_id']]['order_sn'];
         $pay_totals += $export_data[$k + 1][] = floatval($v['pay_price']);
         $commis_totals += $export_data[$k + 1][] = floatval($v['pay_price'] * $v['commis_rate'] / 100);
         $export_data[$k + 1][] = $order_new_list[$v['order_id']]['buyer_name'];
         $export_data[$k + 1][] = $order_new_list[$v['order_id']]['buyer_id'];
         $export_data[$k + 1][] = $order_new_list[$v['order_id']]['goods_name'];
         $k++;
     }
     $count = count($export_data);
     $export_data[$count][] = '合计';
     $export_data[$count][] = '';
     $export_data[$count][] = '';
     $export_data[$count][] = $pay_totals;
     $export_data[$count][] = $commis_totals;
     $csv = new Csv();
     $export_data = $csv->charset($export_data, CHARSET, 'gbk');
     $file_name = $_GET['type'] == 'timeout' ? '过期兑换码列表' : '已消费兑换码列表';
     $csv->filename = $csv->charset($file_name . '-', CHARSET) . $_GET['ob_no'];
     $csv->export($export_data);
 }
コード例 #4
0
ファイル: goods.php プロジェクト: Wen1750686723/utao
 /**
  * 导出商品csv
  * */
 function output_csv()
 {
     $id = IReq::get('id');
     $date_format = IReq::get('date_format');
     //淘宝数据
     $tao_arr = array();
     $tao_arr[] = IReq::get('category');
     $tao_arr[] = IReq::get('ems');
     $tao_arr[] = IReq::get('exp');
     $tao_arr[] = IReq::get('post');
     $csvObj = new Csv();
     if ($id) {
         $good_id = explode(',', $id);
         $csvObj->export($date_format, $good_id, $tao_arr);
     } else {
         $arr = array();
         $tb_goods = new IModel('goods');
         $goods_info = $tb_goods->query('', 'id');
         foreach ($goods_info as $value) {
             $arr[] = $value['id'];
         }
         $csvObj->export($date_format, $arr, $tao_arr);
     }
     exit;
 }