123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- class ordersendlistControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- $model_refill_order = Model('refill_order');
- $condition['refill_order.inner_status'] = 0;
- $condition['vr_order.order_state'] = ORDER_STATE_SEND;
- $condition['refill_order.order_time'] = ['lt', (time() - 1800)];
- if (!empty($_GET['mchid'])) {
- $condition['refill_order.mchid'] = $_GET['mchid'];
- }
- if (!empty($_GET['store_id'])) {
- $condition['vr_order.store_id'] = $_GET['store_id'];
- }
- $time_cond = [
- ['between', [(time() - 3600), (time() - 1800)]],
- ['lt', (time() - 3600)]];
- 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)];
- }
- $time_out_order = function($time_out, $condition){
- $mchids = Model('')->table('merchant')->where(['time_out' => ['elt', $time_out]])->field('mchid')->select();
- $mchids = array_column($mchids, 'mchid');
- $mchids = implode(',', $mchids);
- $condition['refill_order.order_time'] = ['lt', (time() - $time_out)];
- $condition['refill_order.mchid'] = ['in',$mchids];
- return $condition;
- };
- if ($_GET['time'] == 3) {
- $condition = $time_out_order(300, $condition);
- $time_cond[] = ['lt', (time() - 300)];
- }
- if ($_GET['time'] == 4) {
- $condition = $time_out_order(900, $condition);
- $time_cond[] = ['lt', (time() - 900)];
- }
- if (!empty($_GET['card_type'])) {
- if (in_array($_GET['card_type'], ['1', '2', '4', '5', '6', '7'])) {
- $condition['refill_order.card_type'] = $_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']];
- }
- }
- if (!empty($_GET['quality'])) {
- $condition['refill_order.quality'] = $_GET['quality'];
- }
- $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
- $stat = 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')
- ->where($condition)->find();
- $count = $this->refill_stat($condition,$time_cond);
- $merchant_list = Model('')->table('merchant')->limit(1000)->select();
- foreach ($merchant_list as $key => $value) {
- $merchants[$value['mchid']] = $value;
- }
- 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'];
- $order_list[$order_id]['diff_time_text'] = $this->elapse_time(time() - $order_info['order_time']);
- $order_list[$order_id]['diff_time'] = time() - $order_info['order_time'];
- $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['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();
- Tpl::output('stat', $stat);
- Tpl::output('count', $count);
- Tpl::output('order_list', $order_list);
- Tpl::output('merchant_list', $merchant_list);
- Tpl::output('provider_list', $provider_list);
- Tpl::output('show_page', $model_refill_order->showpage());
- Tpl::showpage('refill.order.send.index');
- }
- 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 refill_stat($condition, $times)
- {
- $stat_order = function ($condition) {
- $stat = Model('')->table('refill_order,vr_order')->join('inner')
- ->on('refill_order.order_id=vr_order.order_id')
- ->field('count(*) as order_count ')
- ->where($condition)->find();
- return $stat['order_count'];
- };
- $result = [];
- $condition['order_state'] = ORDER_STATE_SEND;
- foreach ($times as $time) {
- $condition['refill_order.order_time'] = $time;
- $result[] = $stat_order($condition);
- }
- return $result;
- }
- }
|