config('customer.order_statistics_index_name'), "type" => "_doc", "body" => [ "size" => 0, "query" => [ "bool" => [ "must" => [ [ "terms" => [ "status" => [1, 2, 3, 4, 5, 6] ] ], [ "term" => [ "shop_id" => $shopId ] ], [ "range" => [ "created_at" => [ "from" => $start, "to" => $end, "include_lower" => true, "include_upper" => true, ] ] ] ] ] ], "aggs" => [ "total_fee" => [ "sum" => [ "field" => "real_price" ] ], "pay_user_num" => [ "cardinality" => [ "field" => "uid" ] ], "pay_order_num" => [ "cardinality" => [ "field" => "id" ] ] ] ] ]; $result = \Elasticsearch::search($params); Log::debug('get-order-payinfo:' . json_encode($params)); return [ 'total_fee' => $result['aggregations']['total_fee']['value'], 'pay_user_num' => $result['aggregations']['pay_user_num']['value'], 'pay_order_num' => $result['aggregations']['pay_order_num']['value'], ]; } /** * 获取待发货订单数 * @param string $start * @param string $end * @return array */ public function getDfhOrder($start = '', $end = '', $shopId = '') { $params = [ "index" => config('customer.order_statistics_index_name'), "type" => "_doc", "body" => [ "size" => 0, "query" => [ "bool" => [ "must" => [ [ "term" => [ "status" => [ "value" => 1 ] ] ], [ "term" => [ "shop_id" => $shopId ] ], [ "range" => [ "created_at" => [ "from" => $start, "to" => $end, "include_lower" => true, "include_upper" => true, ] ] ] ] ] ], "aggs" => [ "dfh_order_num" => [ "cardinality" => [ "field" => "id" ] ] ] ] ]; $result = \Elasticsearch::search($params); Log::debug('get-dfh-order:' . json_encode($params)); return [ 'dfh_order_num' => $result['aggregations']['dfh_order_num']['value'] ]; } /** * 获取完成订单数 * @param string $start * @param string $end * @return array */ public function getFinishOrder($start = '', $end = '', $shopId = '') { $params = [ "index" => config('customer.order_statistics_index_name'), "type" => "_doc", "body" => [ "size" => 0, "query" => [ "bool" => [ "must" => [ [ "terms" => [ "status" => [5, 6] ] ], [ "term" => [ "shop_id" => $shopId ] ], [ "range" => [ "created_at" => [ "from" => $start, "to" => $end, "include_lower" => true, "include_upper" => true, ] ] ] ] ] ], "aggs" => [ "total_fee" => [ "sum" => [ "field" => "real_price" ] ], "finish_order_num" => [ "cardinality" => [ "field" => "id" ] ] ] ] ]; $result = \Elasticsearch::search($params); Log::debug('get-finish-order:' . json_encode($params)); return [ 'finish_total_fee' => $result['aggregations']['total_fee']['value'], 'finish_order_num' => $result['aggregations']['finish_order_num']['value'] ]; } /** * 获取总订单数 * @param string $start * @param string $end * @return array */ public function getOrderNum($start = '', $end = '', $shopId = '') { $params = [ "index" => config('customer.order_statistics_index_name'), "type" => "_doc", "body" => [ "size" => 0, "query" => [ "bool" => [ "must" => [ [ "term" => [ "shop_id" => $shopId ] ], [ "range" => [ "created_at" => [ "from" => $start, "to" => $end, "include_lower" => true, "include_upper" => true, ] ] ] ] ] ], "aggs" => [ "total_order_num" => [ "cardinality" => [ "field" => "id" ] ] ] ] ]; $result = \Elasticsearch::search($params); Log::debug('get-order-num:' . json_encode($params)); return [ 'total_order_num' => $result['aggregations']['total_order_num']['value'] ]; } /** * 获取总退单数 * @param string $start * @param string $end * @return array */ public function getRefundOrderNum($start = '', $end = '', $shopId = '') { $params = [ "index" => config('customer.order_statistics_index_name'), "type" => "_doc", "body" => [ "size" => 0, "query" => [ "bool" => [ "must" => [ [ "terms" => [ "feedback_status" => [1, 2] ] ], [ "term" => [ "shop_id" => $shopId ] ], [ "range" => [ "created_at" => [ "from" => $start, "to" => $end, "include_lower" => true, "include_upper" => true, ] ] ] ] ] ], "aggs" => [ "refund_order_num" => [ "cardinality" => [ "field" => "id" ] ] ] ] ]; $result = \Elasticsearch::search($params); Log::debug('get-refund-order:' . json_encode($params)); return [ 'refund_order_num' => $result['aggregations']['refund_order_num']['value'] ]; } /** * 获取维权订单数 * @param string $start * @param string $end * @return array */ public function getFeedBackOrderNum($start = '', $end = '', $shopId = '') { $params = [ "index" => config('customer.order_statistics_index_name'), "type" => "_doc", "body" => [ "size" => 0, "query" => [ "bool" => [ "must" => [ [ "terms" => [ "feedback_status" => [1, 2, 3] ] ], [ "term" => [ "shop_id" => $shopId ] ], [ "range" => [ "created_at" => [ "from" => $start, "to" => $end, "include_lower" => true, "include_upper" => true, ] ] ] ] ] ], "aggs" => [ "feedback_order_num" => [ "cardinality" => [ "field" => "id" ] ] ] ] ]; $result = \Elasticsearch::search($params); Log::debug('get-feedback-ordernum:' . json_encode($params)); return [ 'feedback_order_num' => $result['aggregations']['feedback_order_num']['value'] ]; } /** * 获取销售额 * @param string $start * @param string $end * @return array */ public function getSaleMoney($start = '', $end = '', $shopId = '') { $params = [ "index" => config('customer.order_statistics_index_name'), "type" => "_doc", "body" => [ "size" => 0, "query" => [ "bool" => [ "must" => [ [ "terms" => [ "status" => [1, 2, 3, 4, 5, 6] ] ], [ "term" => [ "shop_id" => $shopId ] ], [ "range" => [ "created_at" => [ "from" => $start, "to" => $end, "include_lower" => true, "include_upper" => true, ] ] ] ] ] ], "aggs" => [ "sale_per_day" => [ "date_histogram" => [ "field" => "created_at", "interval" => "1d", "min_doc_count" => 0, "format" => "yyyy-MM-dd", "extended_bounds" => [ "min" => Carbon::parse($start)->format('Y-m-d'), "max" => Carbon::parse($end)->format('Y-m-d'), ] ], "aggs" => [ "total_fee" => [ "sum" => [ "field" => "real_price" ] ], "pay_user_num" => [ "cardinality" => [ "field" => "uid" ] ] ] ] ] ] ]; $result = \Elasticsearch::search($params); Log::debug('get-sale-money:' . json_encode($params)); $tmp = []; foreach ($result['aggregations']['sale_per_day']['buckets'] as $row) { $tmpDate = Carbon::parse($row['key_as_string'])->format('m-d'); $tmp[$tmpDate] = [ 'pay_user_num' => $row['pay_user_num']['value'], 'total_fee' => $row['total_fee']['value'], ]; } return $tmp; } }