|
@@ -11,45 +11,90 @@ use statistics\stat_refill;
|
|
|
|
|
|
class handler
|
|
|
{
|
|
|
- public function refill_order_stat($condition)
|
|
|
+ public function refill_order_stat($cond)
|
|
|
{
|
|
|
- try
|
|
|
+ $tmcond_gen = function ($time_scope,$cur_start,$cur_end)
|
|
|
{
|
|
|
- $items = Model('')->table('refill_order,vr_order')
|
|
|
- ->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')
|
|
|
- ->join('inner')
|
|
|
- ->on('refill_order.order_id=vr_order.order_id')
|
|
|
- ->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 ($items as $item)
|
|
|
+ $cond['refill_order.order_time'] = [['egt', $cur_start], ['lt', $cur_end], 'and'];
|
|
|
+
|
|
|
+ [$start, $end] = $time_scope['add_time'];
|
|
|
+ $cond['vr_order.add_time'] = [['egt', $start], ['elt', $end], 'and'];
|
|
|
+
|
|
|
+ return $cond;
|
|
|
+ };
|
|
|
+ $normal_cond = $cond['normal'];
|
|
|
+ $time_scope = $cond['time_scope'];
|
|
|
+
|
|
|
+ $order_reader = function ($normal_cond, $time_scope) use ($tmcond_gen)
|
|
|
+ {
|
|
|
+ [$start, $end] = $time_scope['order_time'];
|
|
|
+
|
|
|
+ for ($cur_start = $start; $cur_start < $end; $cur_start += 3600)
|
|
|
{
|
|
|
- if ($item['order_state'] == ORDER_STATE_SEND) {
|
|
|
- $sending = $item;
|
|
|
- } elseif ($item['order_state'] == ORDER_STATE_SUCCESS) {
|
|
|
- $success = $item;
|
|
|
- } elseif ($item['order_state'] == ORDER_STATE_CANCEL) {
|
|
|
- $cancel = $item;
|
|
|
+ if ($cur_start + 3600 >= $end) {
|
|
|
+ $cur_end = $end;
|
|
|
+ } else {
|
|
|
+ $cur_end = $cur_start + 3600;
|
|
|
}
|
|
|
|
|
|
- $all['order_count'] += $item['order_count'];
|
|
|
- $all['refill_amounts'] += ncPriceFormat($item['refill_amounts']);
|
|
|
- $all['channel_amounts'] += ncPriceFormat($item['channel_amounts']);
|
|
|
- $all['mch_amounts'] += ncPriceFormat($item['mch_amounts']);
|
|
|
- }
|
|
|
+ $tmcond = $tmcond_gen($time_scope, $cur_start, $cur_end);
|
|
|
+ $cond = array_merge($normal_cond, $tmcond);
|
|
|
|
|
|
- $result = ['all' => $all, 'sending' => $sending, 'success' => $success, 'cancel' => $cancel];
|
|
|
+ $mod = Model();
|
|
|
+ $items = $mod->table('refill_order,vr_order')
|
|
|
+ ->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')
|
|
|
+ ->join('inner')
|
|
|
+ ->on('refill_order.order_id=vr_order.order_id')
|
|
|
+ ->where($cond)
|
|
|
+ ->group('order_state')
|
|
|
+ ->select();
|
|
|
|
|
|
- return [true,$result];
|
|
|
+ $data['order_count'] = $data['refill_amounts'] = $data['channel_amounts'] = $data['mch_amounts'] = 0;
|
|
|
+ $all = $sending = $success = $cancel = $data;
|
|
|
+ foreach ($items as $item) {
|
|
|
+ if ($item['order_state'] == ORDER_STATE_SEND) {
|
|
|
+ $sending = $item;
|
|
|
+ } elseif ($item['order_state'] == ORDER_STATE_SUCCESS) {
|
|
|
+ $success = $item;
|
|
|
+ } elseif ($item['order_state'] == ORDER_STATE_CANCEL) {
|
|
|
+ $cancel = $item;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- catch (Exception $ex)
|
|
|
- {
|
|
|
- return [false,false];
|
|
|
+ $all['order_count'] += $item['order_count'];
|
|
|
+ $all['refill_amounts'] += ncPriceFormat($item['refill_amounts']);
|
|
|
+ $all['channel_amounts'] += ncPriceFormat($item['channel_amounts']);
|
|
|
+ $all['mch_amounts'] += ncPriceFormat($item['mch_amounts']);
|
|
|
+ }
|
|
|
+ yield ['all' => $all, 'sending' => $sending, 'success' => $success, 'cancel' => $cancel];
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $array_add = function ($a, $b) {
|
|
|
+ $arr = array_intersect_key($a, $b);
|
|
|
+ foreach ($b as $key => $value) {
|
|
|
+ if (!array_key_exists($key, $a)) {
|
|
|
+ $a[$key] = $value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach ($arr as $key => $value) {
|
|
|
+ $a[$key] = $a[$key] + $b[$key];
|
|
|
+ }
|
|
|
+ return $a;
|
|
|
+ };
|
|
|
+
|
|
|
+ try {
|
|
|
+ $stats = $order_reader($normal_cond, $time_scope);
|
|
|
+ $all = $sending = $success = $cancel = [];
|
|
|
+ foreach ($stats as $stat) {
|
|
|
+ $all = $array_add($all, $stat['all']);
|
|
|
+ $sending = $array_add($sending, $stat['sending']);
|
|
|
+ $success = $array_add($success, $stat['success']);
|
|
|
+ $cancel = $array_add($cancel, $stat['cancel']);
|
|
|
+ }
|
|
|
+ $result = ['all' => $all, 'sending' => $sending, 'success' => $success, 'cancel' => $cancel];
|
|
|
+ return [true, $result];
|
|
|
+ } catch (Exception $ex) {
|
|
|
+ return [false, false];
|
|
|
}
|
|
|
}
|
|
|
|