[ 'class' => LanguageBehavior::className(), 'objectLang' => OrderLabelLang::className(), 'ownerKey' => 'id', 'langKey' => 'order_label_id', ], ]; } public function getStatistics(int $dateFrom, int $dateTo) { if ($dateTo != 0) { $where = [ 'between', 'created_at', $dateFrom, $dateTo, ]; } else { $where = []; } $query = ( new Query() )->select( [ 'sum' => 'SUM(total)', 'count' => 'COUNT(*)', 'unique' => ( new Query() )->select('COUNT(*)') ->from('order') ->leftJoin( 'order_product', '"order"."id"="order_product"."order_id"' ) ->where([ 'order.label' => $this->id ]) ->andFilterWhere( $where ), 'products' => ( new Query() )->select('SUM(count)') ->from('order') ->leftJoin( 'order_product', '"order"."id"="order_product"."order_id"' ) ->where([ 'order.label' => $this->id ]) ->andFilterWhere( $where ), ] ) ->from('order') ->where([ 'label' => $this->id ]) ->andFilterWhere( $where ); return $query->one(); } }