ct_cond($_GET, 'time_stamp'); if (!empty($_GET['order_time_type'])) { $condition['order_time_type'] = $_GET['order_time_type']; } if(!empty($_GET['reload'])) { $stats_list = $model_refill_order->getAllRefillStats($condition); $this->stats_reload($stats_list); $json_str = json_encode($condition); $this->log("对账管理,批量重新统计,条件:{$json_str}", 1); showMessage('操作完成'); } $stats_list = $model_refill_order->getOrderStatsList($condition, 50, '*', 'time_stamp desc, cname asc'); if($type == 'merchant') { foreach ($stats_list as $key => $stats) { $time = date("Y-m-d",$stats['time_stamp']+86400); $mch_cache = rcache("merchant_balance_{$time}", 'refill-'); $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']); if(empty($caches)) continue; $stats_list[$key]['available'] = ncPriceFormat($caches[$stats['cid']]) ?? ''; } } $total_stats = $this->stats($condition); $order_time_type_text = ['notify_time' => '回调时间', 'order_time' => '下单时间']; Tpl::output('total_stats', $total_stats); Tpl::output('stats_list', $stats_list); Tpl::output('order_time_type_text', $order_time_type_text); Tpl::output('show_page', $model_refill_order->showpage()); Tpl::showpage($page); } private function stats_reload($stats_list) { foreach ($stats_list as $stats) { if($stats['send_count'] == 0) continue; $cond = [ 'type' => $stats['type'], 'time_stamp' => $stats['time_stamp'], 'cid' => $stats['cid'], 'order_time_type' => $stats['order_time_type'] ]; $manager = new task\manager(); $manager->add_task('order_stat_reload',$cond,0,3600); } } private function ct_cond($input,$time_stamp) { $condition['type'] = $input['type'] ?? 'system'; if (!empty($input['cid'])) { $condition['cid'] = ['in', $input['cid']]; } $start_unixtime = intval(strtotime($input['query_start_time'])); $end_unixtime = intval(strtotime($input['query_end_time'])); if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) { $condition[$time_stamp] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and']; } elseif ($start_unixtime > 0) { $condition[$time_stamp] = ['egt', $start_unixtime]; } elseif ($end_unixtime > 0) { $condition[$time_stamp] = ['lt', $end_unixtime]; } return $condition; } public function ExportDataOp() { $type = $_GET['type'] ?? 'system'; $model_refill_order = Model('refill_order'); $condition['type'] = $type; if (!empty($_GET['cid'])) { $condition['cid'] = ['in', $_GET['cid']]; } if (!empty($_GET['order_time_type'])) { $condition['order_time_type'] = $_GET['order_time_type']; } $start_unixtime = intval($_GET['query_start_time']); $end_unixtime = intval($_GET['query_end_time']); if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) { $condition['time_stamp'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and']; } elseif ($start_unixtime > 0) { $condition['time_stamp'] = ['egt', $start_unixtime]; } elseif ($end_unixtime > 0) { $condition['time_stamp'] = ['lt', $end_unixtime]; } $stats_list = $this->all_orderstats_data($condition); $total_stats = $this->stats($condition); $stats = $total_stats[$_GET['order_time_type']]; if(empty($stats)) { $stats = $total_stats['notify_time']; } $result['data'] = $stats_list; $result['total_stats'] = $stats; echo(json_encode($result)); } private function stats($condition) { $order_time_type = ['notify_time','order_time']; foreach ($order_time_type as $type){ $condition['order_time_type'] = $type; $stats = Model('')->table('refill_stats') ->field('sum(success_count) as success_count,sum(success_refill_amounts) as success_refill_amounts,sum(success_mch_amounts) as success_mch_amounts, sum(success_channel_amounts) as success_channel_amounts,sum(profit_amounts) as profit_amounts,sum(send_count) as send_count') ->where($condition) ->find(); $total_stats[$type] = [ 'success_count_total' => $stats['success_count'], 'success_refill_amounts_total' => ncPriceFormat($stats['success_refill_amounts']), 'success_mch_amounts_toatl' => ncPriceFormat($stats['success_mch_amounts']), 'success_channel_amounts_total' => ncPriceFormat($stats['success_channel_amounts']), 'profit_amounts_total' => ncPriceFormat($stats['profit_amounts']), 'send_count_total' => $stats['send_count'], ]; } return $total_stats; } private function all_orderstats_data($condition): array { $i = 0; $result = []; while (true) { $start = $i * 1000; $list = Model('')->table('refill_stats')->field('*') ->where($condition)->order('time_stamp desc')->limit("{$start},1000")->select(); if (empty($list)) { break; } $i++; foreach ($list as $value) { $result[] = $value; } } return $result; } public function refill_balanceOp() { $mod = Model('refill_balance'); $type = $_GET['type'] ?? 'system'; $page = "{$type}.refill.balance"; $cond = $this->ct_cond($_GET, 'end_stamp'); if (!empty($_GET['order_time_type'])) { $cond['time_type'] = $_GET['order_time_type']; } $balance_list = $mod->getBalanceList($cond, 200); $order_time_type_text = ['notify_time' => '回调时间', 'order_time' => '下单时间']; Tpl::output('stats_list', $balance_list); Tpl::output('order_time_type_text', $order_time_type_text); Tpl::output('show_page', $mod->showpage()); Tpl::showpage($page); } public function refill_balance_stat_allOp() { $end_unixtime = intval(strtotime($_GET['selectEndDate'])); if(empty($end_unixtime)) { exit(json_encode(['code' => false, 'msg' => '结束日期不能为空!'])); } $condition = ['end' => $end_unixtime]; $manager = new task\manager(); $task = $manager->add_task('refill_balance_stat_all',$condition,0); if ($task->completed() && $task->success()) { exit(json_encode(['code' => true, 'msg' => '操作成功,此记录已新建成功。'])); } else { exit(json_encode(['code' => true, 'msg' => '操作成功,后台任务已开始新建,请稍后查看新数据'])); } } public function refill_balance_createOp() { $balance_id = $_GET['balance_id']; $mod = Model('refill_balance'); $balance = $mod->getBalance(['balance_id' => $balance_id]); if(empty($balance )) { exit(json_encode(['code' => false, 'msg' => '记录不存在!'])); } $start_unixtime = intval(strtotime($_GET['selectStartDate'])); $end_unixtime = intval(strtotime($_GET['selectEndDate'])); if(empty($start_unixtime)) { $start_unixtime = $balance['end_stamp']; } if(empty($end_unixtime)) { exit(json_encode(['code' => false, 'msg' => '结束日期不能为空!'])); } $condition = [ 'type' => $balance['type'], 'cid' => $balance['cid'], 'start' => $start_unixtime, 'end' => $end_unixtime, 'time_type' => $balance['time_type'], 'parent_id' => $balance_id ]; $manager = new task\manager(); $task = $manager->add_task('refill_balance_create',$condition,0); if ($task->completed() && $task->success()) { exit(json_encode(['code' => true, 'msg' => '操作成功,此记录已新建成功。'])); } else { exit(json_encode(['code' => true, 'msg' => '操作成功,后台任务已开始新建,请稍后查看新数据'])); } } public function refill_balance_rebuildOp() { $balance_id = $_GET['balance_id']; $mod = Model('refill_balance'); $balance = $mod->getBalance(['balance_id' => $balance_id]); if(empty($balance )) { showMessage('记录不存在!'); } $condition['balance_id'] = $balance_id; $manager = new task\manager(); $task = $manager->add_task('refill_balance_rebuild',$condition,0); if ($task->completed() && $task->success()) { showMessage('操作成功,此记录已重新生成!'); } else { showMessage('操作成功,后台任务已开始重新生成,请稍后查看新数据!'); } } public function refill_balance_saveOp() { showMessage('操作成功!'); } public function refill_balance_confirmOp() { $balance_id = $_GET['balance_id']; $mod = Model('refill_balance'); $balance = $mod->getBalance(['balance_id' => $balance_id]); if(empty($balance )) { showMessage('记录不存在!'); } $ret = $mod->BalanceConfirm($balance_id); if ($ret) { showMessage('操作成功!'); } else { showMessage('操作失败!'); } } }