|
@@ -0,0 +1,279 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill;
|
|
|
+
|
|
|
+class query
|
|
|
+{
|
|
|
+ private $mInputParams;
|
|
|
+ public function __construct($params)
|
|
|
+ {
|
|
|
+ $this->mInputParams = $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function normal_cond($input)
|
|
|
+ {
|
|
|
+ $cond['inner_status'] = 0;
|
|
|
+ if (!empty($input['order_sn'])) {
|
|
|
+ $cond['refill_order.order_sn'] = $input['order_sn'];
|
|
|
+
|
|
|
+ }
|
|
|
+ if (!empty($input['mch_order'])) {
|
|
|
+ $cond['refill_order.mch_order'] = $input['mch_order'];
|
|
|
+ }
|
|
|
+ if (!empty($input['ch_trade_no'])) {
|
|
|
+ $cond['refill_order.ch_trade_no'] = $input['ch_trade_no'];
|
|
|
+ }
|
|
|
+ if (!empty($input['card_no'])) {
|
|
|
+ $cond['refill_order.card_no'] = $input['card_no'];
|
|
|
+ }
|
|
|
+ if (!empty($input['no_mchid'])) {
|
|
|
+ $no_mchid = explode(',', $input['no_mchid']);
|
|
|
+ $cond['refill_order.mchid'] = ['not in', $no_mchid];
|
|
|
+ }
|
|
|
+ if (!empty($input['no_amount'])) {
|
|
|
+ $no_amount = explode(',', $input['no_amount']);
|
|
|
+ $cond['refill_order.refill_amount'] = ['not in', $no_amount];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($input['mchid'])) {
|
|
|
+ $cond['refill_order.mchid'] = $input['mchid'];
|
|
|
+ }
|
|
|
+ if (!empty($input['channel_name'])) {
|
|
|
+ $cond['refill_order.channel_name'] = $input['channel_name'];
|
|
|
+ }
|
|
|
+ if (!empty($input['store_id'])) {
|
|
|
+ $cond['vr_order.store_id'] = $input['store_id'];
|
|
|
+ }
|
|
|
+ if (!empty($input['refill_amount'])) {
|
|
|
+ $cond['refill_order.refill_amount'] = $input['refill_amount'];
|
|
|
+ }
|
|
|
+ if (!empty($input['quality'])) {
|
|
|
+ $cond['refill_order.quality'] = $input['quality'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($input['official_status'])) {
|
|
|
+ if ($input['official_status'] == 1) {
|
|
|
+ $cond['official_sn'] = '';
|
|
|
+ } elseif ($input['official_status'] == 2) {
|
|
|
+ $cond['official_sn'] = ['neq', ''];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($input['card_type']))
|
|
|
+ {
|
|
|
+ if (in_array($input['card_type'], ['1', '2', '4', '5', '6', '7'])) {
|
|
|
+ $cond['refill_order.card_type'] = intval($input['card_type']);
|
|
|
+ }
|
|
|
+ if ($input['card_type'] == 'oil') {
|
|
|
+ $cond['refill_order.card_type'] = ['in', [1, 2]];
|
|
|
+ }
|
|
|
+ if ($input['card_type'] == 'phone') {
|
|
|
+ $cond['refill_order.card_type'] = ['in', [4, 5, 6]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (in_array($input['cardno_state'], ['0', '1', '2', '4', '5'])) {
|
|
|
+ $cond['refill_order.cardno_state'] = $input['cardno_state'];
|
|
|
+ }
|
|
|
+ if (in_array($input['is_transfer'], ['0', '1'])) {
|
|
|
+ $cond['refill_order.is_transfer'] = $input['is_transfer'];
|
|
|
+ }
|
|
|
+ if (in_array($_GET['order_state'], ['0', '10', '20', '30', '40'])) {
|
|
|
+ $cond['vr_order.order_state'] = $_GET['order_state'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $cond;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function time_type()
|
|
|
+ {
|
|
|
+ $time_type = $this->mInputParams['time_type'];
|
|
|
+ if(empty($time_type) || !in_array($time_type,['order_time','notify_time'])) {
|
|
|
+ $time_type = 'order_time';
|
|
|
+ }
|
|
|
+ return $time_type;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function time_scope($input,$time_type)
|
|
|
+ {
|
|
|
+ $start = intval(strtotime($input['query_start_time']));
|
|
|
+ $end = intval(strtotime($input['query_end_time']));
|
|
|
+
|
|
|
+ $today = strtotime(date('Y-m-d',time()));
|
|
|
+ $tomorrow = $today + 86400;
|
|
|
+
|
|
|
+ if($start <= 0) {
|
|
|
+ $start = $today;
|
|
|
+ }
|
|
|
+
|
|
|
+ $cur = time();
|
|
|
+ $cur = $cur - ($cur % 300) + 300;
|
|
|
+ if($end <= 0) {
|
|
|
+ $end = $cur;
|
|
|
+ }
|
|
|
+
|
|
|
+ $end_date = strtotime(date('Y-m-d',$end));
|
|
|
+ $start_date = strtotime(date('Y-m-d',$start));
|
|
|
+
|
|
|
+ if ($end >= $start)
|
|
|
+ {
|
|
|
+ if ($time_type === 'order_time')
|
|
|
+ {
|
|
|
+ $add_end = $end_date + 86400 * 5;
|
|
|
+ if($add_end > $tomorrow) {
|
|
|
+ $add_end = $tomorrow;
|
|
|
+ }
|
|
|
+ return ['order_time' => [$start, $end], 'add_time' => [$start, $add_end]];
|
|
|
+ }
|
|
|
+ elseif ($time_type === 'notify_time') {
|
|
|
+ $add_begin = $start_date - 86400 * 5;
|
|
|
+ return ['order_time' => [$start_date, $end], 'add_time' => [$add_begin, $end], 'notify_time' => [$start, $end]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function time_cond($scope)
|
|
|
+ {
|
|
|
+ $cond = [];
|
|
|
+
|
|
|
+ [$start, $end] = $scope['order_time'];
|
|
|
+ $cond['refill_order.order_time'] = [['egt', $start], ['lt', $end], 'and'];
|
|
|
+
|
|
|
+ [$start, $end] = $scope['add_time'];
|
|
|
+ $cond['vr_order.add_time'] = [['egt', $start], ['elt', $end], 'and'];
|
|
|
+
|
|
|
+ if (isset($scope['notify_time'])) {
|
|
|
+ [$start, $end] = $scope['notify_time'];
|
|
|
+ $cond['refill_order.notify_time'] = [['egt', $start], ['lt', $end], 'and'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $cond;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function parse($input)
|
|
|
+ {
|
|
|
+ $time_type = $this->time_type();
|
|
|
+
|
|
|
+ if(isset($input['export'])) {
|
|
|
+ $scope['export_time'] = 'order_time';
|
|
|
+ } else {
|
|
|
+ $scope['export_time'] = 'notify_time';
|
|
|
+ }
|
|
|
+
|
|
|
+ $time_scope = function ($input,$time_type)
|
|
|
+ {
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $scope = $time_scope($input,$time_type);
|
|
|
+ if(empty($scope)) {
|
|
|
+ showMessage('结束日期必须大于起始日期.');
|
|
|
+ }
|
|
|
+
|
|
|
+ $normal = $this->normal_cond($input);
|
|
|
+ if (!empty($input['export'])) {
|
|
|
+ $this->export_execl($normal, $scope, $input);
|
|
|
+ }
|
|
|
+
|
|
|
+ $tmcond = $time_cond($scope);
|
|
|
+ $cond = array_merge($normal,$tmcond);
|
|
|
+
|
|
|
+ if (!empty($input['mch_notify'])) {
|
|
|
+ $this->mch_notify($cond);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($input['order_query'])) {
|
|
|
+ $this->updateOrderSend($cond);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $merchants = $this->merchants();
|
|
|
+
|
|
|
+ $mod_refill = Model('refill_order');
|
|
|
+ $order_list = $mod_refill->getMerchantOrderList($cond, 200, 5000,'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
|
|
|
+ $order_list = $this->OrderDataFormat($order_list, $merchants);
|
|
|
+ $provider_list = $this->providers();
|
|
|
+
|
|
|
+ $periodor = function ($start, $end)
|
|
|
+ {
|
|
|
+ $delta = $end - $start;
|
|
|
+ if($delta < 0) return 300;
|
|
|
+
|
|
|
+ if($delta / 86400 >= 5) {
|
|
|
+ $ret = 12 * 3600;
|
|
|
+ }
|
|
|
+ elseif($delta / 86400 >= 1) {
|
|
|
+ $ret = 2 * 3600;
|
|
|
+ }
|
|
|
+ elseif($delta / 3600 > 12) {
|
|
|
+ $ret = 1800;
|
|
|
+ }
|
|
|
+ elseif($delta / 3600 > 3) {
|
|
|
+ $ret = 900;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $ret = 300;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $ret;
|
|
|
+ };
|
|
|
+
|
|
|
+ if ($fShowStat)
|
|
|
+ {
|
|
|
+ [$start,$end] = $scope[$time_type];
|
|
|
+ $period = $periodor($start,$end);
|
|
|
+ $manager = new task\manager();
|
|
|
+ $task = $manager->add_task('refill_order_stat',$cond,0,$period);
|
|
|
+
|
|
|
+ if($task->waiting()) {
|
|
|
+ $sec = time() - $task->add_time();
|
|
|
+ $comment = "已经加入后台任务,已经等待{$sec}秒";
|
|
|
+ } elseif($task->processing()) {
|
|
|
+ $sec = time() - $task->act_time();
|
|
|
+ $comment = "正在处理中,已经执行{$sec}秒";
|
|
|
+ } else {
|
|
|
+ $sec = $task->fini_time() - $task->act_time();
|
|
|
+ $comment = "执行完成,共耗时{$sec}秒";
|
|
|
+ }
|
|
|
+
|
|
|
+ Tpl::output('stat_tip', $comment);
|
|
|
+ if($task->completed() && $task->success())
|
|
|
+ {
|
|
|
+ $stat = $task->result();
|
|
|
+ Tpl::output('stat', $stat);
|
|
|
+ Tpl::output('end_unixtime', $end);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $dispatcher_queue_length = refill\util::dispatcher_queue_length();
|
|
|
+ Tpl::output('dispatcher_queue_length', $dispatcher_queue_length);
|
|
|
+ Tpl::output('admin_info', $this->getAdminInfo());
|
|
|
+ Tpl::output('order_list', $order_list);
|
|
|
+ Tpl::output('provider_list', $provider_list);
|
|
|
+ Tpl::output('merchant_list', $merchants);
|
|
|
+
|
|
|
+
|
|
|
+ $exmechs = function ($merchants) {
|
|
|
+ $result = [];
|
|
|
+ foreach ($merchants as $value) {
|
|
|
+ $data['name'] = $value['company_name'] ?? $value['name'];
|
|
|
+ $data['value'] = $value['mchid'];
|
|
|
+ $data['alpha'] = $value['alpha'];
|
|
|
+ $data['color'] = false;
|
|
|
+ $result[] = $data;
|
|
|
+ }
|
|
|
+ return base64_encode(json_encode($result));
|
|
|
+ };
|
|
|
+
|
|
|
+ Tpl::output('exmechs', $exmechs($merchants));
|
|
|
+ Tpl::output('show_page', $mod_refill->showpage());
|
|
|
+
|
|
|
+ Tpl::showpage('refill.order.index');
|
|
|
+ }
|
|
|
+
|
|
|
+}
|