refill_order($fShowStat==1); } public function refill_order($fShowStat = false) { $model_refill_order = Model('refill_order'); $condition['inner_status'] = 0; $fSingle = false; if (!empty($_GET['order_sn'])) { $condition['refill_order.order_sn'] = $_GET['order_sn']; $fSingle = true; } if (!empty($_GET['mch_order'])) { $condition['refill_order.mch_order'] = $_GET['mch_order']; $fSingle = true; } if (!empty($_GET['ch_trade_no'])) { $condition['refill_order.ch_trade_no'] = $_GET['ch_trade_no']; $fSingle = true; } if (!empty($_GET['card_no'])) { $condition['refill_order.card_no'] = $_GET['card_no']; $fSingle = true; } if (!empty($_GET['no_mchid'])) { $condition['refill_order.mchid'] = ['not in', [$_GET['no_mchid']]]; } if (!empty($_GET['mchid'])) { $condition['refill_order.mchid'] = $_GET['mchid']; } if (!empty($_GET['channel_name'])) { $condition['refill_order.channel_name'] = $_GET['channel_name']; } if (!empty($_GET['store_id'])) { $condition['vr_order.store_id'] = $_GET['store_id']; } if (!empty($_GET['refill_amount'])) { $condition['refill_order.refill_amount'] = $_GET['refill_amount']; } if (!empty($_GET['quality'])) { $condition['refill_order.quality'] = $_GET['quality']; } if (!empty($_GET['card_type'])) { if (in_array($_GET['card_type'], ['1', '2', '4', '5', '6', '7'])) { $condition['refill_order.card_type'] = intval($_GET['card_type']); } if ($_GET['card_type'] == 'oil') { $condition['refill_order.card_type'] = ['in', [1, 2]]; } if ($_GET['card_type'] == 'phone') { $condition['refill_order.card_type'] = ['in', [4, 5, 6]]; } } $fToday = false; if (!$fSingle) { $start_unixtime = intval(strtotime($_GET['query_start_time'])); $end_unixtime = intval(strtotime($_GET['query_end_time'])); if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) { $condition['refill_order.order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and']; } elseif ($start_unixtime > 0) { $condition['refill_order.order_time'] = ['egt', $start_unixtime]; } elseif ($end_unixtime > 0) { $condition['refill_order.order_time'] = ['lt', $end_unixtime]; } else { $start = strtotime(date('Y-m-d', time())); $condition['refill_order.order_time'] = ['egt', $start]; $fToday = true; } if (in_array($_GET['order_state'], ['0', '10', '20', '30', '40'])) { $condition['vr_order.order_state'] = $_GET['order_state']; if ($_GET['order_state'] == ORDER_STATE_SEND) { if ($_GET['time'] == 1) { $condition['refill_order.order_time'] = ['between', [(time() - 3600), (time() - 1800)]]; } if ($_GET['time'] == 2) { $condition['refill_order.order_time'] = ['lt', (time() - 3600)]; } } } } if(!empty($_GET['export'])) { $this->RefillOrderExport($condition); } $merchants = []; $merchant_list = Model('')->table('merchant')->limit(1000)->select(); foreach ($merchant_list as $key => $value) { $merchants[$value['mchid']] = $value; } $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc'); foreach ($order_list as $order_id => $order_info) { $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']); $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name']; if ($order_info['notify_time'] > 0) { $diff_time = $order_info['notify_time'] - $order_info['order_time']; } else { $diff_time = time() - $order_info['order_time']; } $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time); $order_list[$order_id]['diff_time'] = $diff_time; $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality']); $order_list[$order_id]['org_quality_text'] = $this->quality_format($order_info['org_quality']); } $provider_list = Model('')->table('refill_provider,store') ->field('refill_provider.*,store.store_name') ->join('inner') ->on('store.store_id=refill_provider.store_id') ->order('opened asc, provider_id desc') ->limit(1000) ->select(); if ($fShowStat) { $stat = $this->all_order_state_stat($condition); Tpl::output('stat', $stat); } Tpl::output('admin_info', $this->getAdminInfo()); Tpl::output('ftoday', $fToday); Tpl::output('order_list', $order_list); Tpl::output('provider_list', $provider_list); Tpl::output('merchant_list', $merchant_list); Tpl::output('show_page', $model_refill_order->showpage()); Tpl::showpage('refill.order.index'); } private function RefillOrderExport($condition) { $i = 0; $result = []; while (true) { $start = $i * 1000; $order_list = Model('')->table('refill_order,vr_order')->field('refill_order.*,vr_order.order_state') ->where($condition)->join('inner')->on('refill_order.order_id=vr_order.order_id')->order('refill_order.order_time desc')->limit("{$start},1000")->select(); if(empty($order_list)) { break; } $i++; foreach ($order_list as $order) { $result[] = $order; } } $this->createExcel($result); } private function createExcel($data = array()){ Language::read('export'); import('libraries.excel'); $excel_obj = new Excel(); $excel_data = array(); //设置样式 $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1'))); //header $excel_data[0][] = array('styleid'=>'s_title','data'=> '商户号'); $excel_data[0][] = array('styleid'=>'s_title','data'=> '客户订单号'); $excel_data[0][] = array('styleid'=>'s_title','data'=> '平台单号'); $excel_data[0][] = array('styleid'=>'s_title','data'=> '面额'); $excel_data[0][] = array('styleid'=>'s_title','data'=> '充值卡号'); $excel_data[0][] = array('styleid'=>'s_title','data'=> '充值卡类型'); $excel_data[0][] = array('styleid'=>'s_title','data'=> '下单日期'); $excel_data[0][] = array('styleid'=>'s_title','data'=> '完成日期'); $excel_data[0][] = array('styleid'=>'s_title','data'=> '官方流水号'); $excel_data[0][] = array('styleid'=>'s_title','data'=> '订单状态'); $excel_data[0][] = array('styleid'=>'s_title','data'=> '扣款金额'); //data foreach ((array)$data as $k=>$v){ $tmp = array(); $tmp[] = array('data'=>$v['mchid']); $tmp[] = array('data'=>$v['mch_order']); $tmp[] = array('data'=>$v['order_sn']); $tmp[] = array('data'=>$v['refill_amount']); $tmp[] = array('data'=>$v['card_no']); $tmp[] = array('data'=>$this->scard_type($v['card_type'])); $tmp[] = array('data'=>date('Y-m-d H:i:s',$v['order_time'])); if(empty($v['notify_time'])) { $tmp[] = array('data'=>''); }else{ $tmp[] = array('data'=>date('Y-m-d H:i:s',$v['notify_time'])); } $tmp[] = array('data'=>$v['official_sn']); $tmp[] = array('data'=>orderState($v)); $tmp[] = array('data'=>$v['mch_amount']); $excel_data[] = $tmp; } $excel_data = $excel_obj->charset($excel_data,CHARSET); $excel_obj->addArray($excel_data); $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'),CHARSET)); $excel_obj->generateXML($excel_obj->charset(L('exp_od_order'),CHARSET).date('Y-m-d-H',time())); exit; } private function scard_type(int $card_type) { if ($card_type == 1) { //中石油 return '中石油'; } elseif ($card_type == 2) { //中石化 return '中石化'; } elseif ($card_type == 4) { //中国移动 return '中国移动'; } elseif ($card_type == 5) { //中国联通 return '中国联通'; } elseif ($card_type == 6) { //中国电信 return '中国电信'; } elseif ($card_type == 7) { //中国电信 return '增值业务'; } else { return 'unknown'; } } private function quality_format($quality) { switch ($quality) { case 1: $text = "普充"; break; case 2: $text = "快充"; break; case 3: $text = "卡密"; break; case 4: $text = "三方"; break; case 5: $text = "慢充二十四小时"; break; case 6: $text = "慢充六小时"; break; case 7: $text = "慢充两小时"; break; default: return '其他'; break; } return $text; } private function elapse_time($seconds) { $minutes = intval($seconds / 60); $second = intval($seconds % 60); if ($minutes >= 60) { $minute = $minutes % 60; $hours = intval($minutes / 60); $result = "{$minute}m{$second}s"; } elseif ($minutes > 0) { $result = "{$minutes}m{$second}s"; } else { $result = "{$second}s"; } if (isset($hours)) { $result = "{$hours}h{$minute}m"; } return $result; } private function all_order_state_stat($condition) { $counts = Model('')->table('refill_order,vr_order')->join('inner') ->on('refill_order.order_id=vr_order.order_id') ->field('count(*) as order_count, sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts, order_state') ->where($condition) ->group('order_state') ->select(); $all = []; $data['order_count'] = $data['refill_amounts'] = $data['channel_amounts'] = $data['mch_amounts'] = 0; $sending = $success = $cancel = $data; foreach ($counts as $count) { if ($count['order_state'] == ORDER_STATE_SEND) { $sending = $count; } elseif ($count['order_state'] == ORDER_STATE_SUCCESS) { $success = $count; } elseif ($count['order_state'] == ORDER_STATE_CANCEL) { $cancel = $count; } $all['order_count'] += $count['order_count']; $all['refill_amounts'] += ncPriceFormat($count['refill_amounts']); $all['channel_amounts'] += ncPriceFormat($count['channel_amounts']); $all['mch_amounts'] += ncPriceFormat($count['mch_amounts']); } return ['all' => $all, 'sending' => $sending, 'success' => $success, 'cancel' => $cancel]; } }